aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/lispref/debugging.texi59
-rw-r--r--lisp/emacs-lisp/benchmark.el3
-rw-r--r--lisp/emacs-lisp/elp.el5
3 files changed, 41 insertions, 26 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi
index bb022e4516a..c08a382ef12 100644
--- a/doc/lispref/debugging.texi
+++ b/doc/lispref/debugging.texi
@@ -922,48 +922,61 @@ be cleaner to combine them.
922@cindex measuring resource usage 922@cindex measuring resource usage
923@cindex memory usage 923@cindex memory usage
924 924
925If your program is working correctly, but you want to make it run more 925If your program is working correctly, but not fast enough, and you
926quickly or efficiently, the first thing to do is @dfn{profile} your 926want to make it run more quickly or efficiently, the first thing to do
927code so that you know how it is using resources. If you find that one 927is @dfn{profile} your code so that you know where it spends most of
928particular function is responsible for a significant portion of the 928the execution time. If you find that one particular function is
929runtime, you can start looking for ways to optimize that piece. 929responsible for a significant portion of the execution time, you can
930start looking for ways to optimize that piece.
930 931
931Emacs has built-in support for this. To begin profiling, type 932Emacs has built-in support for this. To begin profiling, type
932@kbd{M-x profiler-start}. You can choose to profile by processor 933@kbd{M-x profiler-start}. You can choose to profile by processor
933usage, memory usage, or both. After doing some work, type 934usage, memory usage, or both. Then run the code you'd like to speed
934@kbd{M-x profiler-report} to display a summary buffer for each 935up. After that, type @kbd{M-x profiler-report} to display a summary
935resource that you chose to profile. The names of the report buffers 936buffer for each resource (cpu and memory) that you chose to profile.
936include the times at which the reports were generated, so you can 937The names of the report buffers include the times at which the reports
937generate another report later on without erasing previous results. 938were generated, so you can generate another report later on without
938When you have finished profiling, type @kbd{M-x profiler-stop} (there 939erasing previous results. When you have finished profiling, type
939is a small overhead associated with profiling). 940@kbd{M-x profiler-stop} (there is a small overhead associated with
941profiling, so we don't recommend leaving it active except when you are
942actually running the code you want to examine).
940 943
941The profiler report buffer shows, on each line, a function that was 944The profiler report buffer shows, on each line, a function that was
942called, followed by how much resource (processor or memory) it used in 945called, followed by how much resources (cpu or memory) it used in
943absolute and percentage times since profiling started. If a given 946absolute and percentage terms since profiling started. If a given
944line has a @samp{+} symbol at the left-hand side, you can expand that 947line has a @samp{+} symbol at the left-hand side, you can expand that
945line by typing @kbd{@key{RET}}, in order to see the function(s) called 948line by typing @kbd{@key{RET}}, in order to see the function(s) called
946by the higher-level function. Use a prefix argument (@kbd{C-u 949by the higher-level function. Use a prefix argument (@kbd{C-u
947@key{RET}}) to see the whole call tree below a function. Pressing 950@key{RET}}) to see the whole call tree below a function. Pressing
948@kbd{@key{RET}} again will collapse back to the original state. 951@kbd{@key{RET}} again will collapse back to the original state.
949 952
950Press @kbd{j} or @kbd{mouse-2} to jump to the definition of a function. 953Press @kbd{j} or @kbd{mouse-2} to jump to the definition of a function
951Press @kbd{d} to view a function's documentation. 954at point. Press @kbd{d} to view a function's documentation. You can
952You can save a profile to a file using @kbd{C-x C-w}. 955save a profile to a file using @kbd{C-x C-w}. You can compare two
953You can compare two profiles using @kbd{=}. 956profiles using @kbd{=}.
954 957
955@c FIXME reversed calltree? 958@c FIXME reversed calltree?
956 959
957@cindex @file{elp.el} 960@cindex @file{elp.el}
958@cindex timing programs 961@cindex timing programs
959The @file{elp} library offers an alternative approach. See the file 962The @file{elp} library offers an alternative approach, which is useful
960@file{elp.el} for instructions. 963when you know in advance which Lisp function(s) you want to profile.
964Using that library, you begin by setting @code{elp-function-list} to
965the list of function symbols---those are the functions you want to
966profile. Then type @w{@kbd{M-x elp-instrument-list @key{RET} nil
967@key{RET}}} to arrange for profiling those functions. After running
968the code you want to profile, invoke @w{@kbd{M-x elp-results}} to
969display the current results. See the file @file{elp.el} for more
970detailed instructions. This approach is limited to profiling
971functions written in Lisp, it cannot profile Emacs primitives.
961 972
962@cindex @file{benchmark.el} 973@cindex @file{benchmark.el}
963@cindex benchmarking 974@cindex benchmarking
964You can check the speed of individual Emacs Lisp forms using the 975You can measure the time it takes to evaluate individual Emacs Lisp
965@file{benchmark} library. See the functions @code{benchmark-run} and 976forms using the @file{benchmark} library. See the macros
966@code{benchmark-run-compiled} in @file{benchmark.el}. 977@code{benchmark-run} and @code{benchmark-run-compiled} in
978@file{benchmark.el}. You can also use the @code{benchmark} command
979for timing forms interactively.
967 980
968@c Not worth putting in the printed manual. 981@c Not worth putting in the printed manual.
969@ifnottex 982@ifnottex
diff --git a/lisp/emacs-lisp/benchmark.el b/lisp/emacs-lisp/benchmark.el
index 589e76eaec0..d74446c7479 100644
--- a/lisp/emacs-lisp/benchmark.el
+++ b/lisp/emacs-lisp/benchmark.el
@@ -98,7 +98,8 @@ result. The overhead of the `lambda's is accounted for."
98;;;###autoload 98;;;###autoload
99(defun benchmark (repetitions form) 99(defun benchmark (repetitions form)
100 "Print the time taken for REPETITIONS executions of FORM. 100 "Print the time taken for REPETITIONS executions of FORM.
101Interactively, REPETITIONS is taken from the prefix arg. 101Interactively, REPETITIONS is taken from the prefix arg, and
102the command prompts for the form to benchmark.
102For non-interactive use see also `benchmark-run' and 103For non-interactive use see also `benchmark-run' and
103`benchmark-run-compiled'." 104`benchmark-run-compiled'."
104 (interactive "p\nxForm: ") 105 (interactive "p\nxForm: ")
diff --git a/lisp/emacs-lisp/elp.el b/lisp/emacs-lisp/elp.el
index dab17fd75b6..954e7aa73ae 100644
--- a/lisp/emacs-lisp/elp.el
+++ b/lisp/emacs-lisp/elp.el
@@ -278,8 +278,9 @@ Argument FUNSYM is the symbol of a defined function."
278(defun elp-instrument-list (&optional list) 278(defun elp-instrument-list (&optional list)
279 "Instrument, for profiling, all functions in `elp-function-list'. 279 "Instrument, for profiling, all functions in `elp-function-list'.
280Use optional LIST if provided instead. 280Use optional LIST if provided instead.
281If called interactively, read LIST using the minibuffer." 281If called interactively, prompt for LIST in the minibuffer;
282 (interactive "PList of functions to instrument: ") ;FIXME: Doesn't work?! 282type \"nil\" to use `elp-function-list'."
283 (interactive "xList of functions to instrument: ")
283 (unless (listp list) 284 (unless (listp list)
284 (signal 'wrong-type-argument (list 'listp list))) 285 (signal 'wrong-type-argument (list 'listp list)))
285 (mapcar #'elp-instrument-function (or list elp-function-list))) 286 (mapcar #'elp-instrument-function (or list elp-function-list)))