annotate lisp/emacs-lisp/elp.el @ 15053:68d9a01cfb23

(simula-tab-always-indent, simula-indent-level) (simula-substatement-offset, simula-continued-statement-offset) (simula-label-offset, simula-if-indent, simula-inspect-indent) (simula-electric-indent, simula-abbrev-keyword, simula-abbrev-stdproc): Added default constants. (simula-emacs-features): new constant to hold information on which flavor if emacs is running (from cc-mode.el). (simula-mode-menu): Menu definition for Lucid Emacs (simula-mode-map): Bound new command simula-indent-exp to C-M-q and added lots of commands to [menu-bar]. (simula-popup-menu): New function for Lucid menus. (simula-keep-region-active): New function for Lucid menus. (simula-indent-exp): New command that indents a whole expression. (simula-indent-line): New strategies for finding the right amount to indent. (simula-skip-comment-backward): Added optional parameter stop-at-end to stop at the first END statement. (simula-expand-stdproc): Added abbrev expansion to verbatim copy of abbrev table, same for function simula-expand-keyword. (simula-search-backward): Added Doc string, and lots of error checking. (simula-search-forward): Added Doc string, and lots of error checking. Added hilit19 config code. (simula-version): New variable and function to report value. (simula-submit-bug-report): New function to submit bug report.
author Richard M. Stallman <rms@gnu.org>
date Sun, 21 Apr 1996 01:39:51 +0000
parents 0a88c1cc98ec
children c9f73399244c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
1 ;;; elp.el --- Emacs Lisp Profiler
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
2
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
4
8745
ebbea7d79174 Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 8744
diff changeset
5 ;; Author: 1994 Barry A. Warsaw <bwarsaw@cnri.reston.va.us>
ebbea7d79174 Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 8744
diff changeset
6 ;; Maintainer: tools-help@anthem.nlm.nih.gov
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
7 ;; Created: 26-Feb-1994
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
8 ;; Version: 2.23
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
9 ;; Last Modified: 1994/12/28 22:39:31
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
10 ;; Keywords: Emacs Lisp Profile Timing
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
11
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
12 ;; This file is part of GNU Emacs.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
13
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
15 ;; it under the terms of the GNU General Public License as published by
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
16 ;; the Free Software Foundation; either version 2, or (at your option)
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
17 ;; any later version.
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
18
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
19 ;; GNU Emacs is distributed in the hope that it will be useful,
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
22 ;; GNU General Public License for more details.
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
23
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
24 ;; You should have received a copy of the GNU General Public License
14169
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 10280
diff changeset
25 ;; along with GNU Emacs; see the file COPYING. If not, write to the
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 10280
diff changeset
26 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
83f275dcd93a Update FSF's address.
Erik Naggum <erik@naggum.no>
parents: 10280
diff changeset
27 ;; Boston, MA 02111-1307, USA.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
28
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
29 ;;; Commentary:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
30 ;;
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
31 ;; If you want to profile a bunch of functions, set elp-function-list
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
32 ;; to the list of symbols, then do a M-x elp-instrument-list. This
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
33 ;; hacks those functions so that profiling information is recorded
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
34 ;; whenever they are called. To print out the current results, use
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
35 ;; M-x elp-results. With elp-reset-after-results set to non-nil,
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
36 ;; profiling information will be reset whenever the results are
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
37 ;; displayed. You can also reset all profiling info at any time with
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
38 ;; M-x elp-reset-all.
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
39 ;;
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
40 ;; You can also instrument all functions in a package, provided that
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
41 ;; the package follows the GNU coding standard of a common textural
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
42 ;; prefix. Use M-x elp-instrument-package for this.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
43 ;;
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
44 ;; If you want to sort the results, set elp-sort-by-function to some
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
45 ;; predicate function. The three most obvious choices are predefined:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
46 ;; elp-sort-by-call-count, elp-sort-by-average-time, and
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
47 ;; elp-sort-by-total-time. Also, you can prune from the output, all
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
48 ;; functions that have been called fewer than a given number of times
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
49 ;; by setting elp-report-limit.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
50 ;;
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
51 ;; Elp can instrument byte-compiled functions just as easily as
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
52 ;; interpreted functions, but it cannot instrument macros. However,
10234
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
53 ;; when you redefine a function (e.g. with eval-defun), you'll need to
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
54 ;; re-instrument it with M-x elp-instrument-function. This will also
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
55 ;; reset profiling information for that function. Elp can handle
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
56 ;; interactive functions (i.e. commands), but of course any time spent
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
57 ;; idling for user prompts will show up in the timing results.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
58 ;;
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
59 ;; You can also designate a `master' function. Profiling times will
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
60 ;; be gathered for instrumented functions only during execution of
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
61 ;; this master function. Thus, if you have some defuns like:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
62 ;;
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
63 ;; (defun foo () (do-something-time-intensive))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
64 ;; (defun bar () (foo))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
65 ;; (defun baz () (bar) (foo))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
66 ;;
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
67 ;; and you want to find out the amount of time spent in bar and foo,
10234
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
68 ;; but only during execution of bar, make bar the master. The call of
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
69 ;; foo from baz will not add to foo's total timing sums. Use M-x
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
70 ;; elp-set-master and M-x elp-unset-master to utilize this feature.
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
71 ;; Only one master function can be set at a time.
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
72
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
73 ;; You can restore any function's original function definition with
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
74 ;; elp-restore-function. The other instrument, restore, and reset
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
75 ;; functions are provided for symmetry.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
76
10263
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
77 ;; Note that there are plenty of factors that could make the times
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
78 ;; reported unreliable, including the accuracy and granularity of your
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
79 ;; system clock, and the overhead spent in lisp calculating and
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
80 ;; recording the intervals. The latter I figure is pretty constant
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
81 ;; so, while the times may not be entirely accurate, I think they'll
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
82 ;; give you a good feel for the relative amount of work spent in the
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
83 ;; various lisp routines you are profiling. Note further that times
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
84 ;; are calculated using wall-clock time, so other system load will
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
85 ;; affect accuracy too.
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
86
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
87 ;; Here is a list of variable you can use to customize elp:
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
88 ;; elp-function-list
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
89 ;; elp-reset-after-results
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
90 ;; elp-sort-by-function
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
91 ;; elp-report-limit
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
92 ;;
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
93 ;; Here is a list of the interactive commands you can use:
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
94 ;; elp-instrument-function
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
95 ;; elp-restore-function
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
96 ;; elp-instrument-list
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
97 ;; elp-restore-list
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
98 ;; elp-instrument-package
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
99 ;; elp-restore-all
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
100 ;; elp-reset-function
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
101 ;; elp-reset-list
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
102 ;; elp-reset-all
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
103 ;; elp-set-master
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
104 ;; elp-unset-master
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
105 ;; elp-results
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
106 ;; elp-submit-bug-report
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
107
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
108 ;; Note that there are plenty of factors that could make the times
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
109 ;; reported unreliable, including the accuracy and granularity of your
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
110 ;; system clock, and the overhead spent in lisp calculating and
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
111 ;; recording the intervals. I figure the latter is pretty constant,
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
112 ;; so while the times may not be entirely accurate, I think they'll
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
113 ;; give you a good feel for the relative amount of work spent in the
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
114 ;; various lisp routines you are profiling. Note further that times
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
115 ;; are calculated using wall-clock time, so other system load will
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
116 ;; affect accuracy too. You cannot profile anything longer than ~18
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
117 ;; hours since I throw away the most significant 16 bits of seconds
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
118 ;; returned by current-time: 2^16 == 65536 seconds == ~1092 minutes ==
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
119 ;; ~18 hours. I doubt you will ever want to profile stuff on the
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
120 ;; order of 18 hours anyway.
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
121
10263
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
122 ;;; Background:
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
123
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
124 ;; This program is based on the only two existing Emacs Lisp profilers
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
125 ;; that I'm aware of, Boaz Ben-Zvi's profile.el, and Root Boy Jim's
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
126 ;; profiler.el. Both were written for Emacs 18 and both were pretty
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
127 ;; good first shots at profiling, but I found that they didn't provide
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
128 ;; the functionality or interface that I wanted. So I wrote this.
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
129 ;; I've tested elp in GNU Emacs 19 and in GNU XEmacs. There's no
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
130 ;; point in even trying to make this work with Emacs 18.
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
131
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
132 ;; Unlike previous profilers, elp uses Emacs 19's built-in function
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
133 ;; current-time to return interval times. This obviates the need for
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
134 ;; both an external C program and Emacs processes to communicate with
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
135 ;; such a program, and thus simplifies the package as a whole.
10234
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
136
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
137 ;;; Code:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
138
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
139
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
140 ;; start user configuration variables
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
141 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
142
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
143 (defvar elp-function-list nil
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
144 "*List of function to profile.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
145
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
146 (defvar elp-reset-after-results t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
147 "*Non-nil means reset all profiling info after results are displayed.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
148 Results are displayed with the `elp-results' command.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
149
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
150 (defvar elp-sort-by-function nil
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
151 "*Non-nil specifies elp results sorting function.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
152 These functions are currently available:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
153
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
154 elp-sort-by-call-count -- sort by the highest call count
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
155 elp-sort-by-total-time -- sort by the highest total time
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
156 elp-sort-by-average-time -- sort by the highest average times
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
157
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
158 You can write you're own sort function. It should adhere to the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
159 interface specified by the PRED argument for the `sort' defun. Each
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
160 \"element of LIST\" is really a 4 element vector where element 0 is
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
161 the call count, element 1 is the total time spent in the function,
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
162 element 2 is the average time spent in the function, and element 3 is
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
163 the symbol's name string.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
164
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
165 (defvar elp-report-limit nil
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
166 "*Prevents some functions from being displayed in the results buffer.
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
167 If a number, no function that has been called fewer than that number
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
168 of times will be displayed in the output buffer. If nil, all
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
169 functions will be displayed.")
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
170
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
171
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
172 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
173 ;; end user configuration variables
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
174
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
175
10280
ba09e85fa992 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10263
diff changeset
176 (defconst elp-version "2.23"
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
177 "ELP version number.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
178
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
179 (defconst elp-help-address "tools-help@anthem.nlm.nih.gov"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
180 "Address accepting submissions of bug reports and questions.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
181
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
182 (defvar elp-results-buffer "*ELP Profiling Results*"
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
183 "Buffer name for outputting profiling results.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
184
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
185 (defconst elp-timer-info-property 'elp-info
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
186 "ELP information property name.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
187
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
188 (defvar elp-all-instrumented-list nil
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
189 "List of all functions currently being instrumented.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
190
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
191 (defvar elp-record-p t
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
192 "Controls whether functions should record times or not.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
193 This variable is set by the master function.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
194
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
195 (defvar elp-master nil
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
196 "Master function symbol.")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
197
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
198
8745
ebbea7d79174 Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 8744
diff changeset
199 ;;;###autoload
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
200 (defun elp-instrument-function (funsym)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
201 "Instrument FUNSYM for profiling.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
202 FUNSYM must be a symbol of a defined function."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
203 (interactive "aFunction to instrument: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
204 ;; TBD what should we do if the function is already instrumented???
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
205 (let* ((funguts (symbol-function funsym))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
206 (infovec (vector 0 0 funguts))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
207 (newguts '(lambda (&rest args))))
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
208 ;; we cannot profile macros
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
209 (and (eq (car-safe funguts) 'macro)
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
210 (error "ELP cannot profile macro %s" funsym))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
211 ;; put rest of newguts together
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
212 (if (commandp funsym)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
213 (setq newguts (append newguts '((interactive)))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
214 (setq newguts (append newguts (list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
215 (list 'elp-wrapper
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
216 (list 'quote funsym)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
217 (list 'and
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
218 '(interactive-p)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
219 (not (not (commandp funsym))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
220 'args))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
221 ;; to record profiling times, we set the symbol's function
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
222 ;; definition so that it runs the elp-wrapper function with the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
223 ;; function symbol as an argument. We place the old function
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
224 ;; definition on the info vector.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
225 ;;
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
226 ;; The info vector data structure is a 3 element vector. The 0th
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
227 ;; element is the call-count, i.e. the total number of times this
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
228 ;; function has been entered. This value is bumped up on entry to
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
229 ;; the function so that non-local exists are still recorded. TBD:
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
230 ;; I haven't tested non-local exits at all, so no guarantees.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
231 ;;
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
232 ;; The 1st element is the total amount of time in usecs that have
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
233 ;; been spent inside this function. This number is added to on
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
234 ;; function exit.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
235 ;;
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
236 ;; The 2nd element is the old function definition list. This gets
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
237 ;; funcall'd in between start/end time retrievals. I believe that
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
238 ;; this lets us profile even byte-compiled functions.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
239
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
240 ;; put the info vector on the property list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
241 (put funsym elp-timer-info-property infovec)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
242
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
243 ;; set the symbol's new profiling function definition to run
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
244 ;; elp-wrapper
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
245 (fset funsym newguts)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
246
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
247 ;; add this function to the instrumentation list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
248 (or (memq funsym elp-all-instrumented-list)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
249 (setq elp-all-instrumented-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
250 (cons funsym elp-all-instrumented-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
251 ))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
252
8745
ebbea7d79174 Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 8744
diff changeset
253 ;;;###autoload
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
254 (defun elp-restore-function (funsym)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
255 "Restore an instrumented function to its original definition.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
256 Argument FUNSYM is the symbol of a defined function."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
257 (interactive "aFunction to restore: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
258 (let ((info (get funsym elp-timer-info-property)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
259 ;; delete the function from the all instrumented list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
260 (setq elp-all-instrumented-list
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
261 (delq funsym elp-all-instrumented-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
262
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
263 ;; if the function was the master, reset the master
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
264 (if (eq funsym elp-master)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
265 (setq elp-master nil
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
266 elp-record-p t))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
267
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
268 ;; zap the properties
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
269 (put funsym elp-timer-info-property nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
270
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
271 ;; restore the original function definition, but if the function
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
272 ;; wasn't instrumented do nothing. we do this after the above
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
273 ;; because its possible the function got un-instrumented due to
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
274 ;; circumstances beyond our control. Also, check to make sure
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
275 ;; that the current function symbol points to elp-wrapper. If
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
276 ;; not, then the user probably did an eval-defun while the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
277 ;; function was instrumented and we don't want to destroy the new
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
278 ;; definition.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
279 (and info
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
280 (assq 'elp-wrapper (symbol-function funsym))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
281 (fset funsym (aref info 2)))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
282
8745
ebbea7d79174 Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 8744
diff changeset
283 ;;;###autoload
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
284 (defun elp-instrument-list (&optional list)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
285 "Instrument for profiling, all functions in `elp-function-list'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
286 Use optional LIST if provided instead."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
287 (interactive "PList of functions to instrument: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
288 (let ((list (or list elp-function-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
289 (mapcar 'elp-instrument-function list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
290
8745
ebbea7d79174 Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 8744
diff changeset
291 ;;;###autoload
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
292 (defun elp-instrument-package (prefix)
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
293 "Instrument for profiling, all functions which start with PREFIX.
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
294 For example, to instrument all ELP functions, do the following:
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
295
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
296 \\[elp-instrument-package] RET elp- RET"
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
297 (interactive "sPrefix of package to instrument: ")
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
298 (elp-instrument-list
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
299 (mapcar 'intern (all-completions prefix obarray
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
300 (function
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
301 (lambda (sym)
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
302 (and (fboundp sym)
14858
0a88c1cc98ec (elp-instrument-package): Don't instrument keymaps and autoloaded functions.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
303 (not (memq (car-safe
0a88c1cc98ec (elp-instrument-package): Don't instrument keymaps and autoloaded functions.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
304 (symbol-function sym))
0a88c1cc98ec (elp-instrument-package): Don't instrument keymaps and autoloaded functions.
Richard M. Stallman <rms@gnu.org>
parents: 14169
diff changeset
305 '(macro keymap autoload))))))))))
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
306
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
307 (defun elp-restore-list (&optional list)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
308 "Restore the original definitions for all functions in `elp-function-list'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
309 Use optional LIST if provided instead."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
310 (interactive "PList of functions to restore: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
311 (let ((list (or list elp-function-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
312 (mapcar 'elp-restore-function list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
313
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
314 (defun elp-restore-all ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
315 "Restores the original definitions of all functions being profiled."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
316 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
317 (elp-restore-list elp-all-instrumented-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
318
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
319
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
320 (defun elp-reset-function (funsym)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
321 "Reset the profiling information for FUNSYM."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
322 (interactive "aFunction to reset: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
323 (let ((info (get funsym elp-timer-info-property)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
324 (or info
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
325 (error "%s is not instrumented for profiling." funsym))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
326 (aset info 0 0) ;reset call counter
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
327 (aset info 1 0.0) ;reset total time
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
328 ;; don't muck with aref 2 as that is the old symbol definition
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
329 ))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
330
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
331 (defun elp-reset-list (&optional list)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
332 "Reset the profiling information for all functions in `elp-function-list'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
333 Use optional LIST if provided instead."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
334 (interactive "PList of functions to reset: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
335 (let ((list (or list elp-function-list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
336 (mapcar 'elp-reset-function list)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
337
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
338 (defun elp-reset-all ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
339 "Reset the profiling information for all functions being profiled."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
340 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
341 (elp-reset-list elp-all-instrumented-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
342
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
343 (defun elp-set-master (funsym)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
344 "Set the master function for profiling."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
345 (interactive "aMaster function: ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
346 ;; when there's a master function, recording is turned off by
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
347 ;; default
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
348 (setq elp-master funsym
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
349 elp-record-p nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
350 ;; make sure master function is instrumented
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
351 (or (memq funsym elp-all-instrumented-list)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
352 (elp-instrument-function funsym)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
353
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
354 (defun elp-unset-master ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
355 "Unsets the master function."
10234
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
356 (interactive)
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
357 ;; when there's no master function, recording is turned on by default.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
358 (setq elp-master nil
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
359 elp-record-p t))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
360
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
361
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
362 (defsubst elp-get-time ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
363 ;; get current time in seconds and microseconds. I throw away the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
364 ;; most significant 16 bits of seconds since I doubt we'll ever want
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
365 ;; to profile lisp on the order of 18 hours. See notes at top of file.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
366 (let ((now (current-time)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
367 (+ (float (nth 1 now)) (/ (float (nth 2 now)) 1000000.0))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
368
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
369 (defun elp-wrapper (funsym interactive-p args)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
370 "This function has been instrumented for profiling by the ELP.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
371 ELP is the Emacs Lisp Profiler. To restore the function to its
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
372 original definition, use \\[elp-restore-function] or \\[elp-restore-all]."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
373 ;; turn on recording if this is the master function
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
374 (if (and elp-master
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
375 (eq funsym elp-master))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
376 (setq elp-record-p t))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
377 ;; get info vector and original function symbol
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
378 (let* ((info (get funsym elp-timer-info-property))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
379 (func (aref info 2))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
380 result)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
381 (or func
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
382 (error "%s is not instrumented for profiling." funsym))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
383 (if (not elp-record-p)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
384 ;; when not recording, just call the original function symbol
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
385 ;; and return the results.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
386 (setq result
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
387 (if interactive-p
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
388 (call-interactively func)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
389 (apply func args)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
390 ;; we are recording times
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
391 (let ((enter-time (elp-get-time)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
392 ;; increment the call-counter
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
393 (aset info 0 (1+ (aref info 0)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
394 ;; now call the old symbol function, checking to see if it
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
395 ;; should be called interactively. make sure we return the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
396 ;; correct value
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
397 (setq result
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
398 (if interactive-p
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
399 (call-interactively func)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
400 (apply func args)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
401 ;; calculate total time in function
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
402 (aset info 1 (+ (aref info 1) (- (elp-get-time) enter-time)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
403 ))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
404 ;; turn off recording if this is the master function
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
405 (if (and elp-master
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
406 (eq funsym elp-master))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
407 (setq elp-record-p nil))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
408 result))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
409
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
410
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
411 ;; shut the byte-compiler up
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
412 (defvar elp-field-len nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
413 (defvar elp-cc-len nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
414 (defvar elp-at-len nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
415 (defvar elp-et-len nil)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
416
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
417 (defun elp-sort-by-call-count (vec1 vec2)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
418 ;; sort by highest call count. See `sort'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
419 (>= (aref vec1 0) (aref vec2 0)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
420
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
421 (defun elp-sort-by-total-time (vec1 vec2)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
422 ;; sort by highest total time spent in function. See `sort'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
423 (>= (aref vec1 1) (aref vec2 1)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
424
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
425 (defun elp-sort-by-average-time (vec1 vec2)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
426 ;; sort by highest average time spent in function. See `sort'.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
427 (>= (aref vec1 2) (aref vec2 2)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
428
10234
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
429 (defsubst elp-pack-number (number width)
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
430 ;; pack the NUMBER string into WIDTH characters, watching out for
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
431 ;; very small or large numbers
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
432 (if (<= (length number) width)
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
433 number
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
434 ;; check for very large or small numbers
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
435 (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number)
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
436 (concat (substring
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
437 (substring number (match-beginning 1) (match-end 1))
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
438 0
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
439 (- width (match-end 2) (- (match-beginning 2)) 3))
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
440 "..."
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
441 (substring number (match-beginning 2) (match-end 2)))
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
442 (concat (substring number 0 width)))))
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
443
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
444 (defun elp-output-result (resultvec)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
445 ;; output the RESULTVEC into the results buffer. RESULTVEC is a 4 or
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
446 ;; more element vector where aref 0 is the call count, aref 1 is the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
447 ;; total time spent in the function, aref 2 is the average time
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
448 ;; spent in the function, and aref 3 is the symbol's string
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
449 ;; name. All other elements in the vector are ignored.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
450 (let* ((cc (aref resultvec 0))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
451 (tt (aref resultvec 1))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
452 (at (aref resultvec 2))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
453 (symname (aref resultvec 3))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
454 callcnt totaltime avetime)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
455 (setq callcnt (number-to-string cc)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
456 totaltime (number-to-string tt)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
457 avetime (number-to-string at))
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
458 ;; possibly prune the results
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
459 (if (and elp-report-limit
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
460 (numberp elp-report-limit)
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
461 (< cc elp-report-limit))
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
462 nil
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
463 (insert symname)
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
464 (insert-char 32 (+ elp-field-len (- (length symname)) 2))
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
465 ;; print stuff out, formatting it nicely
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
466 (insert callcnt)
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
467 (insert-char 32 (+ elp-cc-len (- (length callcnt)) 2))
10234
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
468 (let ((ttstr (elp-pack-number totaltime elp-et-len))
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
469 (atstr (elp-pack-number avetime elp-at-len)))
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
470 (insert ttstr)
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
471 (insert-char 32 (+ elp-et-len (- (length ttstr)) 2))
170c4c188d4f (elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents: 8745
diff changeset
472 (insert atstr))
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
473 (insert "\n"))))
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
474
8745
ebbea7d79174 Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 8744
diff changeset
475 ;;;###autoload
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
476 (defun elp-results ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
477 "Display current profiling results.
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
478 If `elp-reset-after-results' is non-nil, then current profiling
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
479 information for all instrumented functions are reset after results are
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
480 displayed."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
481 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
482 (let ((curbuf (current-buffer))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
483 (resultsbuf (get-buffer-create elp-results-buffer)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
484 (set-buffer resultsbuf)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
485 (erase-buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
486 (beginning-of-buffer)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
487 ;; get the length of the longest function name being profiled
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
488 (let* ((longest 0)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
489 (title "Function Name")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
490 (titlelen (length title))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
491 (elp-field-len titlelen)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
492 (cc-header "Call Count")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
493 (elp-cc-len (length cc-header))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
494 (et-header "Elapsed Time")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
495 (elp-et-len (length et-header))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
496 (at-header "Average Time")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
497 (elp-at-len (length at-header))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
498 (resvec
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
499 (mapcar
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
500 (function
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
501 (lambda (funsym)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
502 (let* ((info (get funsym elp-timer-info-property))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
503 (symname (format "%s" funsym))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
504 (cc (aref info 0))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
505 (tt (aref info 1)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
506 (if (not info)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
507 (insert "No profiling information found for: "
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
508 symname)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
509 (setq longest (max longest (length symname)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
510 (vector cc tt (if (zerop cc)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
511 0.0 ;avoid arithmetic div-by-zero errors
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
512 (/ (float tt) (float cc)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
513 symname)))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
514 elp-all-instrumented-list))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
515 ) ; end let*
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
516 (insert title)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
517 (if (> longest titlelen)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
518 (progn
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
519 (insert-char 32 (- longest titlelen))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
520 (setq elp-field-len longest)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
521 (insert " " cc-header " " et-header " " at-header "\n")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
522 (insert-char ?= elp-field-len)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
523 (insert " ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
524 (insert-char ?= elp-cc-len)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
525 (insert " ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
526 (insert-char ?= elp-et-len)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
527 (insert " ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
528 (insert-char ?= elp-at-len)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
529 (insert "\n")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
530 ;; if sorting is enabled, then sort the results list. in either
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
531 ;; case, call elp-output-result to output the result in the
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
532 ;; buffer
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
533 (if elp-sort-by-function
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
534 (setq resvec (sort resvec elp-sort-by-function)))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
535 (mapcar 'elp-output-result resvec))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
536 ;; now pop up results buffer
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
537 (set-buffer curbuf)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
538 (pop-to-buffer resultsbuf)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
539 ;; reset profiling info if desired
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
540 (and elp-reset-after-results
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
541 (elp-reset-all))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
542
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
543
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
544 (eval-when-compile
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
545 (require 'reporter))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
546
8745
ebbea7d79174 Add autoloads.
Richard M. Stallman <rms@gnu.org>
parents: 8744
diff changeset
547 ;;;###autoload
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
548 (defun elp-submit-bug-report ()
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
549 "Submit via mail, a bug report on elp."
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
550 (interactive)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
551 (and
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
552 (y-or-n-p "Do you want to submit a report on elp? ")
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
553 (require 'reporter)
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
554 (reporter-submit-bug-report
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
555 elp-help-address (concat "elp " elp-version)
8744
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
556 '(elp-report-limit
e1b824af0849 Update to 2.15.
Richard M. Stallman <rms@gnu.org>
parents: 8735
diff changeset
557 elp-reset-after-results
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
558 elp-sort-by-function))))
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
559
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
560
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
561 (provide 'elp)
10263
525b67bc4f17 Comment changes.
Richard M. Stallman <rms@gnu.org>
parents: 10234
diff changeset
562
8735
d1f0811de024 Initial revision
Richard M. Stallman <rms@gnu.org>
parents:
diff changeset
563 ;; elp.el ends here