summaryrefslogtreecommitdiff
path: root/devdocs/elisp/profiling.html
diff options
context:
space:
mode:
Diffstat (limited to 'devdocs/elisp/profiling.html')
-rw-r--r--devdocs/elisp/profiling.html7
1 files changed, 7 insertions, 0 deletions
diff --git a/devdocs/elisp/profiling.html b/devdocs/elisp/profiling.html
new file mode 100644
index 00000000..e859b128
--- /dev/null
+++ b/devdocs/elisp/profiling.html
@@ -0,0 +1,7 @@
+ <h3 class="section">Profiling</h3> <p>If your program is working correctly, but not fast enough, and you want to make it run more quickly or efficiently, the first thing to do is <em>profile</em> your code so that you know where it spends most of the execution time. If you find that one particular function is responsible for a significant portion of the execution time, you can start looking for ways to optimize that piece. </p> <p>Emacs has built-in support for this. To begin profiling, type <kbd><span class="nolinebreak">M-x</span> <span class="nolinebreak">profiler-start</span></kbd>. You can choose to sample CPU usage periodically (<code>cpu</code>), when memory is allocated (<code>memory</code>), or both. Then run the code you’d like to speed up. After that, type <kbd>M-x profiler-report</kbd> to display a summary buffer for CPU usage sampled by each type (cpu and memory) that you chose to profile. The names of the report buffers include the times at which the reports were generated, so you can generate another report later on without erasing previous results. When you have finished profiling, type <kbd>M-x profiler-stop</kbd> (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). </p> <p>The profiler report buffer shows, on each line, a function that was called, preceded by how much CPU resources it used in absolute and percentage terms since profiling started. If a given line has a ‘<samp>+</samp>’ symbol to the left of the function name, you can expand that line by typing <kbd><span class="key">RET</span></kbd>, in order to see the function(s) called by the higher-level function. Use a prefix argument (<kbd>C-u <span class="key">RET</span></kbd>) to see the whole call tree below a function. Pressing <kbd><span class="key">RET</span></kbd> again will collapse back to the original state. </p> <p>Press <kbd>j</kbd> or <kbd>mouse-2</kbd> to jump to the definition of a function at point. Press <kbd>d</kbd> to view a function’s documentation. You can save a profile to a file using <kbd>C-x C-w</kbd>. You can compare two profiles using <kbd>=</kbd>. </p> <p>The <samp>elp</samp> library offers an alternative approach, which is useful when you know in advance which Lisp function(s) you want to profile. Using that library, you begin by setting <code>elp-function-list</code> to the list of function symbols—those are the functions you want to profile. Then type <kbd><span class="nolinebreak">M-x</span> <span class="nolinebreak">elp-instrument-list</span> <span class="key">RET</span> nil <span class="key">RET</span></kbd> to arrange for profiling those functions. After running the code you want to profile, invoke <kbd><span class="nolinebreak">M-x</span> <span class="nolinebreak">elp-results</span></kbd> to display the current results. See the file <samp>elp.el</samp> for more detailed instructions. This approach is limited to profiling functions written in Lisp, it cannot profile Emacs primitives. </p> <p>You can measure the time it takes to evaluate individual Emacs Lisp forms using the <samp>benchmark</samp> library. See the function <code>benchmark-call</code> as well as the macros <code>benchmark-run</code>, <code>benchmark-run-compiled</code>, <code>benchmark-progn</code> and <code>benchmark-call</code> in <samp>benchmark.el</samp>. You can also use the <code>benchmark</code> command for timing forms interactively. </p> <p>To profile Emacs at the level of its C code, you can build it using the <samp>--enable-profiling</samp> option of <code>configure</code>. When Emacs exits, it generates a file <samp>gmon.out</samp> that you can examine using the <code>gprof</code> utility. This feature is mainly useful for debugging Emacs. It actually stops the Lisp-level <kbd>M-x profiler-…</kbd> commands described above from working. </p>
+<hr><div class="_attribution">
+ <p class="_attribution-p">
+ Copyright &copy; 1990-1996, 1998-2022 Free Software Foundation, Inc. <br>Licensed under the GNU GPL license.<br>
+ <a href="https://www.gnu.org/software/emacs/manual/html_node/elisp/Profiling.html" class="_attribution-link">https://www.gnu.org/software/emacs/manual/html_node/elisp/Profiling.html</a>
+ </p>
+</div>