Improve documentation of Profiling features

* doc/lispref/debugging.texi (Profiling): Improve the description
of elp.el.  Improve wording of the rest of the section.  (Bug#30491)

* lisp/emacs-lisp/elp.el (elp-instrument-list): Make the
interactive invocation work.  Doc fix.
This commit is contained in:
Eli Zaretskii 2018-02-17 11:59:36 +02:00
parent b228839af1
commit d8917eba1c
3 changed files with 41 additions and 26 deletions

View file

@ -922,48 +922,61 @@ be cleaner to combine them.
@cindex measuring resource usage @cindex measuring resource usage
@cindex memory usage @cindex memory usage
If your program is working correctly, but you want to make it run more If your program is working correctly, but not fast enough, and you
quickly or efficiently, the first thing to do is @dfn{profile} your want to make it run more quickly or efficiently, the first thing to do
code so that you know how it is using resources. If you find that one is @dfn{profile} your code so that you know where it spends most of
particular function is responsible for a significant portion of the the execution time. If you find that one particular function is
runtime, you can start looking for ways to optimize that piece. responsible for a significant portion of the execution time, you can
start looking for ways to optimize that piece.
Emacs has built-in support for this. To begin profiling, type Emacs has built-in support for this. To begin profiling, type
@kbd{M-x profiler-start}. You can choose to profile by processor @kbd{M-x profiler-start}. You can choose to profile by processor
usage, memory usage, or both. After doing some work, type usage, memory usage, or both. Then run the code you'd like to speed
@kbd{M-x profiler-report} to display a summary buffer for each up. After that, type @kbd{M-x profiler-report} to display a summary
resource that you chose to profile. The names of the report buffers buffer for each resource (cpu and memory) that you chose to profile.
include the times at which the reports were generated, so you can The names of the report buffers include the times at which the reports
generate another report later on without erasing previous results. were generated, so you can generate another report later on without
When you have finished profiling, type @kbd{M-x profiler-stop} (there erasing previous results. When you have finished profiling, type
is a small overhead associated with profiling). @kbd{M-x profiler-stop} (there is a small overhead associated with
profiling, so we don't recommend leaving it active except when you are
actually running the code you want to examine).
The profiler report buffer shows, on each line, a function that was The profiler report buffer shows, on each line, a function that was
called, followed by how much resource (processor or memory) it used in called, followed by how much resources (cpu or memory) it used in
absolute and percentage times since profiling started. If a given absolute and percentage terms since profiling started. If a given
line has a @samp{+} symbol at the left-hand side, you can expand that line has a @samp{+} symbol at the left-hand side, you can expand that
line by typing @kbd{@key{RET}}, in order to see the function(s) called line by typing @kbd{@key{RET}}, in order to see the function(s) called
by the higher-level function. Use a prefix argument (@kbd{C-u by the higher-level function. Use a prefix argument (@kbd{C-u
@key{RET}}) to see the whole call tree below a function. Pressing @key{RET}}) to see the whole call tree below a function. Pressing
@kbd{@key{RET}} again will collapse back to the original state. @kbd{@key{RET}} again will collapse back to the original state.
Press @kbd{j} or @kbd{mouse-2} to jump to the definition of a function. Press @kbd{j} or @kbd{mouse-2} to jump to the definition of a function
Press @kbd{d} to view a function's documentation. at point. Press @kbd{d} to view a function's documentation. You can
You can save a profile to a file using @kbd{C-x C-w}. save a profile to a file using @kbd{C-x C-w}. You can compare two
You can compare two profiles using @kbd{=}. profiles using @kbd{=}.
@c FIXME reversed calltree? @c FIXME reversed calltree?
@cindex @file{elp.el} @cindex @file{elp.el}
@cindex timing programs @cindex timing programs
The @file{elp} library offers an alternative approach. See the file The @file{elp} library offers an alternative approach, which is useful
@file{elp.el} for instructions. when you know in advance which Lisp function(s) you want to profile.
Using that library, you begin by setting @code{elp-function-list} to
the list of function symbols---those are the functions you want to
profile. Then type @w{@kbd{M-x elp-instrument-list @key{RET} nil
@key{RET}}} to arrange for profiling those functions. After running
the code you want to profile, invoke @w{@kbd{M-x elp-results}} to
display the current results. See the file @file{elp.el} for more
detailed instructions. This approach is limited to profiling
functions written in Lisp, it cannot profile Emacs primitives.
@cindex @file{benchmark.el} @cindex @file{benchmark.el}
@cindex benchmarking @cindex benchmarking
You can check the speed of individual Emacs Lisp forms using the You can measure the time it takes to evaluate individual Emacs Lisp
@file{benchmark} library. See the functions @code{benchmark-run} and forms using the @file{benchmark} library. See the macros
@code{benchmark-run-compiled} in @file{benchmark.el}. @code{benchmark-run} and @code{benchmark-run-compiled} in
@file{benchmark.el}. You can also use the @code{benchmark} command
for timing forms interactively.
@c Not worth putting in the printed manual. @c Not worth putting in the printed manual.
@ifnottex @ifnottex

View file

@ -98,7 +98,8 @@ result. The overhead of the `lambda's is accounted for."
;;;###autoload ;;;###autoload
(defun benchmark (repetitions form) (defun benchmark (repetitions form)
"Print the time taken for REPETITIONS executions of FORM. "Print the time taken for REPETITIONS executions of FORM.
Interactively, REPETITIONS is taken from the prefix arg. Interactively, REPETITIONS is taken from the prefix arg, and
the command prompts for the form to benchmark.
For non-interactive use see also `benchmark-run' and For non-interactive use see also `benchmark-run' and
`benchmark-run-compiled'." `benchmark-run-compiled'."
(interactive "p\nxForm: ") (interactive "p\nxForm: ")

View file

@ -278,8 +278,9 @@ Argument FUNSYM is the symbol of a defined function."
(defun elp-instrument-list (&optional list) (defun elp-instrument-list (&optional list)
"Instrument, for profiling, all functions in `elp-function-list'. "Instrument, for profiling, all functions in `elp-function-list'.
Use optional LIST if provided instead. Use optional LIST if provided instead.
If called interactively, read LIST using the minibuffer." If called interactively, prompt for LIST in the minibuffer;
(interactive "PList of functions to instrument: ") ;FIXME: Doesn't work?! type \"nil\" to use `elp-function-list'."
(interactive "xList of functions to instrument: ")
(unless (listp list) (unless (listp list)
(signal 'wrong-type-argument (list 'listp list))) (signal 'wrong-type-argument (list 'listp list)))
(mapcar #'elp-instrument-function (or list elp-function-list))) (mapcar #'elp-instrument-function (or list elp-function-list)))