aboutsummaryrefslogtreecommitdiffstats
path: root/doc/lispref/debugging.texi
diff options
context:
space:
mode:
Diffstat (limited to 'doc/lispref/debugging.texi')
-rw-r--r--doc/lispref/debugging.texi64
1 files changed, 64 insertions, 0 deletions
diff --git a/doc/lispref/debugging.texi b/doc/lispref/debugging.texi
index 11532b19781..3439a8ae152 100644
--- a/doc/lispref/debugging.texi
+++ b/doc/lispref/debugging.texi
@@ -32,6 +32,9 @@ program.
32@item 32@item
33You can use the ERT package to write regression tests for the program. 33You can use the ERT package to write regression tests for the program.
34@xref{Top,the ERT manual,, ERT, ERT: Emacs Lisp Regression Testing}. 34@xref{Top,the ERT manual,, ERT, ERT: Emacs Lisp Regression Testing}.
35
36@item
37You can profile the program to get hints about how to make it more efficient.
35@end itemize 38@end itemize
36 39
37 Other useful tools for debugging input and output problems are the 40 Other useful tools for debugging input and output problems are the
@@ -43,6 +46,7 @@ function (@pxref{Terminal Output}).
43* Edebug:: A source-level Emacs Lisp debugger. 46* Edebug:: A source-level Emacs Lisp debugger.
44* Syntax Errors:: How to find syntax errors. 47* Syntax Errors:: How to find syntax errors.
45* Test Coverage:: Ensuring you have tested all branches in your code. 48* Test Coverage:: Ensuring you have tested all branches in your code.
49* Profiling:: Measuring the resources that your code uses.
46@end menu 50@end menu
47 51
48@node Debugger 52@node Debugger
@@ -809,3 +813,63 @@ never return. If it ever does return, you get a run-time error.
809 Edebug also has a coverage testing feature (@pxref{Coverage 813 Edebug also has a coverage testing feature (@pxref{Coverage
810Testing}). These features partly duplicate each other, and it would 814Testing}). These features partly duplicate each other, and it would
811be cleaner to combine them. 815be cleaner to combine them.
816
817
818@node Profiling
819@section Profiling
820@cindex profiling
821@cindex measuring resource usage
822@cindex memory usage
823
824If your program is working correctly, but you want to make it run more
825quickly or efficiently, the first thing to do is @dfn{profile} your
826code so that you know how it is using resources. If you find that one
827particular function is responsible for a significant portion of the
828runtime, you can start looking for ways to optimize that piece.
829
830Emacs has built-in support for this. To begin profiling, type
831@kbd{M-x profiler-start}. You can choose to profile by processor
832usage, memory usage, or both. After doing some work, type
833@kbd{M-x profiler-report} to display a summary buffer for each
834resource that you chose to profile. The names of the report buffers
835include the times at which the reports were generated, so you can
836generate another report later on without erasing previous results.
837When you have finished profiling, type @kbd{M-x profiler-stop} (there
838is a small overhead associated with profiling).
839
840The profiler report buffer shows, on each line, a function that was
841called, followed by how much resource (processor or memory) it used in
842absolute and percentage times since profiling started. If a given
843line has a @samp{+} symbol at the left-hand side, you can expand that
844line by typing @key{RET}, in order to see the function(s) called by
845the higher-level function. Pressing @key{RET} again will collapse
846back to the original state.
847
848Press @kbd{j} or @kbd{mouse-2} to jump to the definition of a function.
849Press @kbd{d} to view a function's documentation.
850You can save a profile to a file using @kbd{C-x C-w}.
851You can compare two profiles using @kbd{=}.
852
853@c FIXME reversed calltree?
854
855@cindex @file{elp.el}
856@cindex timing programs
857The @file{elp} library offers an alternative approach. See the file
858@file{elp.el} for instructions.
859
860@cindex @file{benchmark.el}
861@cindex benchmarking
862You can check the speed of individual Emacs Lisp forms using the
863@file{benchmark} library. See the functions @code{benchmark-run} and
864@code{benchmark-run-compiled} in @file{benchmark.el}.
865
866@c Not worth putting in the printed manual.
867@ifnottex
868@cindex --enable-profiling option of configure
869For low-level profiling of Emacs itself, you can build it using the
870@option{--enable-profiling} option of @command{configure}. When Emacs
871exits, it generates a file @file{gmon.out} that you can examine using
872the @command{gprof} utility. This feature is mainly useful for
873debugging Emacs. It actually stops the Lisp-level @kbd{M-x
874profiler-@dots{}} commands described above from working.
875@end ifnottex