diff options
Diffstat (limited to 'doc/lispref/debugging.texi')
| -rw-r--r-- | doc/lispref/debugging.texi | 64 |
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 |
| 33 | You can use the ERT package to write regression tests for the program. | 33 | You 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 | ||
| 37 | You 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 |
| 810 | Testing}). These features partly duplicate each other, and it would | 814 | Testing}). These features partly duplicate each other, and it would |
| 811 | be cleaner to combine them. | 815 | be 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 | |||
| 824 | If your program is working correctly, but you want to make it run more | ||
| 825 | quickly or efficiently, the first thing to do is @dfn{profile} your | ||
| 826 | code so that you know how it is using resources. If you find that one | ||
| 827 | particular function is responsible for a significant portion of the | ||
| 828 | runtime, you can start looking for ways to optimize that piece. | ||
| 829 | |||
| 830 | Emacs has built-in support for this. To begin profiling, type | ||
| 831 | @kbd{M-x profiler-start}. You can choose to profile by processor | ||
| 832 | usage, memory usage, or both. After doing some work, type | ||
| 833 | @kbd{M-x profiler-report} to display a summary buffer for each | ||
| 834 | resource that you chose to profile. The names of the report buffers | ||
| 835 | include the times at which the reports were generated, so you can | ||
| 836 | generate another report later on without erasing previous results. | ||
| 837 | When you have finished profiling, type @kbd{M-x profiler-stop} (there | ||
| 838 | is a small overhead associated with profiling). | ||
| 839 | |||
| 840 | The profiler report buffer shows, on each line, a function that was | ||
| 841 | called, followed by how much resource (processor or memory) it used in | ||
| 842 | absolute and percentage times since profiling started. If a given | ||
| 843 | line has a @samp{+} symbol at the left-hand side, you can expand that | ||
| 844 | line by typing @key{RET}, in order to see the function(s) called by | ||
| 845 | the higher-level function. Pressing @key{RET} again will collapse | ||
| 846 | back to the original state. | ||
| 847 | |||
| 848 | Press @kbd{j} or @kbd{mouse-2} to jump to the definition of a function. | ||
| 849 | Press @kbd{d} to view a function's documentation. | ||
| 850 | You can save a profile to a file using @kbd{C-x C-w}. | ||
| 851 | You can compare two profiles using @kbd{=}. | ||
| 852 | |||
| 853 | @c FIXME reversed calltree? | ||
| 854 | |||
| 855 | @cindex @file{elp.el} | ||
| 856 | @cindex timing programs | ||
| 857 | The @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 | ||
| 862 | You 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 | ||
| 869 | For low-level profiling of Emacs itself, you can build it using the | ||
| 870 | @option{--enable-profiling} option of @command{configure}. When Emacs | ||
| 871 | exits, it generates a file @file{gmon.out} that you can examine using | ||
| 872 | the @command{gprof} utility. This feature is mainly useful for | ||
| 873 | debugging Emacs. It actually stops the Lisp-level @kbd{M-x | ||
| 874 | profiler-@dots{}} commands described above from working. | ||
| 875 | @end ifnottex | ||