;;; profile.el --- basic profiling commands for XEmacs
-;; Copyright (C) 1996, 2002, 2003 Ben Wing.
+;; Copyright (C) 1996, 2002, 2003 Ben Wing.
;; Copyright (C) 1997 Free Software Foundation.
;; Author: Ben Wing <email@example.com>
;; -- High-level interactive commands for profiling key sequences, commands,
;; and expressions (`profile-key-sequence', `profile-command',
+;; `profile-expression'), or for interactively profiling any sequence of
+;; commands (`toggle-profiling').
;; -- Functions for profiling forms, optionally byte-compiled (`profile',
;; `continue-profile', `compile-and-profile',
;; For instance, to see where Gnus spends time when generating
;; Summary buffer, go to the group buffer and press
-;; `M-x profile-key-sequence RET SPC'.
+;; `M-x profile-key-sequence RET SPC'; or just do
+;; `M-x toggle-profiling', hit SPC, and do `M-x toggle-profiling' again.
+;; (This is especially convenient if you bind `toggle-profiling' to a
sequences, commands, and expressions, see `profile-key-sequence',
`profile-command', and `profile-expression'.
+See also `toggle-profiling', which lets you easily profile any sequence
If you need more control over what is profiled and what isn't, use the more
basic functions `clear-profiling-info', `start-profiling',
`stop-profiling', `profile-results', `get-profiling-info',
(profile (mapc 'dispatch-event keys))))
+(defun toggle-profiling ()
+ "Start profiling, or stop it and print results.
+This lets you figure out where time is being spent when executing Lisp code."
+ (if (profiling-active-p)
+ (message "...Finished profiling")
+ (message "Profiling...")
(defmacro compile-and-profile (&rest forms)
"Byte compile FORMS, profile the execution, and pretty-print the results."