Mercurial > emacs
annotate lisp/emacs-lisp/elp.el @ 64955:dfba32942470
Fix dependency bug: Wrap `desktop-buffer-mode-handlers'
modification in `eval-after-load' form.
author | Thien-Thi Nguyen <ttn@gnuvola.org> |
---|---|
date | Sun, 14 Aug 2005 12:40:02 +0000 |
parents | 5b1a238fcbb4 |
children | 25c21897d6a9 2d92f5c9d6ae |
rev | line source |
---|---|
8735 | 1 ;;; elp.el --- Emacs Lisp Profiler |
2 | |
64751
5b1a238fcbb4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
3 ;; Copyright (C) 1994, 1995, 1997, 1998, 2001, 2002, 2003, 2004, |
5b1a238fcbb4
Update years in copyright notice; nfc.
Thien-Thi Nguyen <ttn@gnuvola.org>
parents:
64085
diff
changeset
|
4 ;; 2005 Free Software Foundation, Inc. |
8744 | 5 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37785
diff
changeset
|
6 ;; Author: Barry A. Warsaw |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37785
diff
changeset
|
7 ;; Maintainer: FSF |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37785
diff
changeset
|
8 ;; Created: 26-Feb-1994 |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37785
diff
changeset
|
9 ;; Keywords: debugging lisp tools |
8735 | 10 |
8744 | 11 ;; This file is part of GNU Emacs. |
8735 | 12 |
8744 | 13 ;; GNU Emacs is free software; you can redistribute it and/or modify |
8735 | 14 ;; it under the terms of the GNU General Public License as published by |
8744 | 15 ;; the Free Software Foundation; either version 2, or (at your option) |
16 ;; any later version. | |
17 | |
18 ;; GNU Emacs is distributed in the hope that it will be useful, | |
8735 | 19 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
20 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
21 ;; GNU General Public License for more details. | |
8744 | 22 |
8735 | 23 ;; You should have received a copy of the GNU General Public License |
14169 | 24 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 25 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
26 ;; Boston, MA 02110-1301, USA. | |
8735 | 27 |
28 ;;; Commentary: | |
29 ;; | |
10280 | 30 ;; If you want to profile a bunch of functions, set elp-function-list |
31 ;; to the list of symbols, then do a M-x elp-instrument-list. This | |
32 ;; hacks those functions so that profiling information is recorded | |
33 ;; whenever they are called. To print out the current results, use | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
34 ;; M-x elp-results. If you want output to go to standard-output |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
35 ;; instead of a separate buffer, setq elp-use-standard-output to |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
36 ;; non-nil. With elp-reset-after-results set to non-nil, profiling |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
37 ;; information will be reset whenever the results are displayed. You |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
38 ;; can also reset all profiling info at any time with M-x |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
39 ;; elp-reset-all. |
8744 | 40 ;; |
41 ;; You can also instrument all functions in a package, provided that | |
42348 | 42 ;; the package follows the GNU coding standard of a common textual |
10280 | 43 ;; prefix. Use M-x elp-instrument-package for this. |
8735 | 44 ;; |
45 ;; If you want to sort the results, set elp-sort-by-function to some | |
46 ;; predicate function. The three most obvious choices are predefined: | |
47 ;; elp-sort-by-call-count, elp-sort-by-average-time, and | |
10280 | 48 ;; elp-sort-by-total-time. Also, you can prune from the output, all |
49 ;; functions that have been called fewer than a given number of times | |
50 ;; by setting elp-report-limit. | |
8735 | 51 ;; |
52 ;; Elp can instrument byte-compiled functions just as easily as | |
8744 | 53 ;; 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
|
54 ;; when you redefine a function (e.g. with eval-defun), you'll need to |
10280 | 55 ;; re-instrument it with M-x elp-instrument-function. This will also |
56 ;; reset profiling information for that function. Elp can handle | |
57 ;; interactive functions (i.e. commands), but of course any time spent | |
58 ;; idling for user prompts will show up in the timing results. | |
8735 | 59 ;; |
60 ;; You can also designate a `master' function. Profiling times will | |
61 ;; be gathered for instrumented functions only during execution of | |
62 ;; this master function. Thus, if you have some defuns like: | |
63 ;; | |
64 ;; (defun foo () (do-something-time-intensive)) | |
65 ;; (defun bar () (foo)) | |
66 ;; (defun baz () (bar) (foo)) | |
67 ;; | |
68 ;; 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
|
69 ;; but only during execution of bar, make bar the master. The call of |
10280 | 70 ;; foo from baz will not add to foo's total timing sums. Use M-x |
71 ;; elp-set-master and M-x elp-unset-master to utilize this feature. | |
72 ;; Only one master function can be set at a time. | |
8735 | 73 |
74 ;; You can restore any function's original function definition with | |
75 ;; elp-restore-function. The other instrument, restore, and reset | |
76 ;; functions are provided for symmetry. | |
77 | |
10263 | 78 ;; Here is a list of variable you can use to customize elp: |
79 ;; elp-function-list | |
80 ;; elp-reset-after-results | |
81 ;; elp-sort-by-function | |
82 ;; elp-report-limit | |
83 ;; | |
84 ;; Here is a list of the interactive commands you can use: | |
85 ;; elp-instrument-function | |
86 ;; elp-restore-function | |
87 ;; elp-instrument-list | |
88 ;; elp-restore-list | |
89 ;; elp-instrument-package | |
90 ;; elp-restore-all | |
91 ;; elp-reset-function | |
92 ;; elp-reset-list | |
93 ;; elp-reset-all | |
94 ;; elp-set-master | |
95 ;; elp-unset-master | |
96 ;; elp-results | |
97 | |
10280 | 98 ;; Note that there are plenty of factors that could make the times |
99 ;; reported unreliable, including the accuracy and granularity of your | |
100 ;; system clock, and the overhead spent in lisp calculating and | |
101 ;; recording the intervals. I figure the latter is pretty constant, | |
102 ;; so while the times may not be entirely accurate, I think they'll | |
103 ;; give you a good feel for the relative amount of work spent in the | |
104 ;; various lisp routines you are profiling. Note further that times | |
105 ;; are calculated using wall-clock time, so other system load will | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
106 ;; affect accuracy too. |
10280 | 107 |
10263 | 108 ;;; Background: |
109 | |
17527
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
110 ;; This program was inspired by the only two existing Emacs Lisp |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
111 ;; profilers that I'm aware of, Boaz Ben-Zvi's profile.el, and Root |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
112 ;; Boy Jim's profiler.el. Both were written for Emacs 18 and both were |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
113 ;; pretty good first shots at profiling, but I found that they didn't |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
114 ;; provide the functionality or interface that I wanted, so I wrote |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
115 ;; this. I've tested elp in XEmacs 19 and Emacs 19. There's no point |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
116 ;; in even trying to make this work with Emacs 18. |
10263 | 117 |
118 ;; Unlike previous profilers, elp uses Emacs 19's built-in function | |
119 ;; current-time to return interval times. This obviates the need for | |
120 ;; both an external C program and Emacs processes to communicate with | |
10280 | 121 ;; 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
|
122 |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
123 ;; TBD: |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
124 ;; Make this act like a real profiler, so that it records time spent |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
125 ;; in all branches of execution. |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
126 |
8735 | 127 ;;; Code: |
128 | |
129 | |
17527
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
130 ;; start of user configuration variables |
8735 | 131 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv |
132 | |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
133 (defgroup elp nil |
64030
c2d80c96de71
(elp): Finish `defgroup' description with period.
Juanma Barranquero <lekktu@gmail.com>
parents:
58008
diff
changeset
|
134 "Emacs Lisp Profiler." |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
135 :group 'lisp) |
8735 | 136 |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
137 (defcustom elp-function-list nil |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
138 "*List of functions to profile. |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
139 Used by the command `elp-instrument-list'." |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
140 :type '(repeat function) |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
141 :group 'elp) |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
142 |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
143 (defcustom elp-reset-after-results t |
8735 | 144 "*Non-nil means reset all profiling info after results are displayed. |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
145 Results are displayed with the `elp-results' command." |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
146 :type 'boolean |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
147 :group 'elp) |
8735 | 148 |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
149 (defcustom elp-sort-by-function 'elp-sort-by-total-time |
8735 | 150 "*Non-nil specifies elp results sorting function. |
151 These functions are currently available: | |
152 | |
153 elp-sort-by-call-count -- sort by the highest call count | |
154 elp-sort-by-total-time -- sort by the highest total time | |
155 elp-sort-by-average-time -- sort by the highest average times | |
156 | |
157 You can write you're own sort function. It should adhere to the | |
158 interface specified by the PRED argument for the `sort' defun. Each | |
159 \"element of LIST\" is really a 4 element vector where element 0 is | |
160 the call count, element 1 is the total time spent in the function, | |
161 element 2 is the average time spent in the function, and element 3 is | |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
162 the symbol's name string." |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
163 :type 'function |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
164 :group 'elp) |
8735 | 165 |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
166 (defcustom elp-report-limit 1 |
8744 | 167 "*Prevents some functions from being displayed in the results buffer. |
168 If a number, no function that has been called fewer than that number | |
169 of times will be displayed in the output buffer. If nil, all | |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
170 functions will be displayed." |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
171 :type '(choice integer |
17527
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
172 (const :tag "Show All" nil)) |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
173 :group 'elp) |
8744 | 174 |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
175 (defcustom elp-use-standard-output nil |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
176 "*Non-nil says to output to `standard-output' instead of a buffer." |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
177 :type 'boolean |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
178 :group 'elp) |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
179 |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
180 (defcustom elp-recycle-buffers-p t |
42206 | 181 "*nil says to not recycle the `elp-results-buffer'. |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
182 In other words, a new unique buffer is create every time you run |
17423
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
183 \\[elp-results]." |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
184 :type 'boolean |
43e483167dd3
Add defgroup; use defcustom for user vars.
Richard M. Stallman <rms@gnu.org>
parents:
17420
diff
changeset
|
185 :group 'elp) |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
186 |
8735 | 187 |
188 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
189 ;; end of user configuration variables |
8735 | 190 |
191 | |
192 (defvar elp-results-buffer "*ELP Profiling Results*" | |
193 "Buffer name for outputting profiling results.") | |
194 | |
195 (defconst elp-timer-info-property 'elp-info | |
196 "ELP information property name.") | |
197 | |
198 (defvar elp-all-instrumented-list nil | |
199 "List of all functions currently being instrumented.") | |
200 | |
201 (defvar elp-record-p t | |
202 "Controls whether functions should record times or not. | |
203 This variable is set by the master function.") | |
204 | |
205 (defvar elp-master nil | |
206 "Master function symbol.") | |
207 | |
41177
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
208 (defvar elp-not-profilable |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
209 '(elp-wrapper elp-elapsed-time error call-interactively apply current-time interactive-p) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
210 "List of functions that cannot be profiled. |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
211 Those functions are used internally by the profiling code and profiling |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
212 them would thus lead to infinite recursion.") |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
213 |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
214 (defun elp-not-profilable-p (fun) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
215 (or (memq fun elp-not-profilable) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
216 (keymapp fun) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
217 (condition-case nil |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
218 (when (subrp (symbol-function fun)) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
219 (eq 'unevalled (cdr (subr-arity (symbol-function fun))))) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
220 (error nil)))) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
221 |
17527
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
222 |
8745 | 223 ;;;###autoload |
8735 | 224 (defun elp-instrument-function (funsym) |
225 "Instrument FUNSYM for profiling. | |
226 FUNSYM must be a symbol of a defined function." | |
227 (interactive "aFunction to instrument: ") | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
228 ;; restore the function. this is necessary to avoid infinite |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
229 ;; recursion of already instrumented functions (i.e. elp-wrapper |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
230 ;; calling elp-wrapper ad infinitum). it is better to simply |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
231 ;; restore the function than to throw an error. this will work |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
232 ;; properly in the face of eval-defun because if the function was |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
233 ;; redefined, only the timer info will be nil'd out since |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
234 ;; elp-restore-function is smart enough not to trash the new |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
235 ;; definition. |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
236 (elp-restore-function funsym) |
8735 | 237 (let* ((funguts (symbol-function funsym)) |
238 (infovec (vector 0 0 funguts)) | |
239 (newguts '(lambda (&rest args)))) | |
41177
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
240 ;; We cannot profile functions used internally during profiling. |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
241 (when (elp-not-profilable-p funsym) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
242 (error "ELP cannot profile the function: %s" funsym)) |
8744 | 243 ;; we cannot profile macros |
244 (and (eq (car-safe funguts) 'macro) | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
245 (error "ELP cannot profile macro: %s" funsym)) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
246 ;; TBD: at some point it might be better to load the autoloaded |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
247 ;; function instead of throwing an error. if we do this, then we |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
248 ;; probably want elp-instrument-package to be updated with the |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
249 ;; newly loaded list of functions. i'm not sure it's smart to do |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
250 ;; the autoload here, since that could have side effects, and |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
251 ;; elp-instrument-function is similar (in my mind) to defun-ish |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
252 ;; type functionality (i.e. it shouldn't execute the function). |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
253 (and (eq (car-safe funguts) 'autoload) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
254 (error "ELP cannot profile autoloaded function: %s" funsym)) |
8735 | 255 ;; put rest of newguts together |
256 (if (commandp funsym) | |
257 (setq newguts (append newguts '((interactive))))) | |
41177
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
258 (setq newguts (append newguts `((elp-wrapper |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
259 (quote ,funsym) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
260 ,(when (commandp funsym) |
57884
9fdca2852881
(elp-instrument-function): Use called-interactively-p.
Richard M. Stallman <rms@gnu.org>
parents:
57520
diff
changeset
|
261 '(called-interactively-p)) |
41177
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
262 args)))) |
8735 | 263 ;; to record profiling times, we set the symbol's function |
264 ;; definition so that it runs the elp-wrapper function with the | |
265 ;; function symbol as an argument. We place the old function | |
266 ;; definition on the info vector. | |
267 ;; | |
268 ;; The info vector data structure is a 3 element vector. The 0th | |
269 ;; element is the call-count, i.e. the total number of times this | |
270 ;; function has been entered. This value is bumped up on entry to | |
271 ;; the function so that non-local exists are still recorded. TBD: | |
272 ;; I haven't tested non-local exits at all, so no guarantees. | |
273 ;; | |
274 ;; The 1st element is the total amount of time in usecs that have | |
275 ;; been spent inside this function. This number is added to on | |
276 ;; function exit. | |
277 ;; | |
278 ;; The 2nd element is the old function definition list. This gets | |
279 ;; funcall'd in between start/end time retrievals. I believe that | |
280 ;; this lets us profile even byte-compiled functions. | |
281 | |
282 ;; put the info vector on the property list | |
283 (put funsym elp-timer-info-property infovec) | |
284 | |
37785
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
285 ;; Set the symbol's new profiling function definition to run |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
286 ;; elp-wrapper. |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
287 (let ((advice-info (get funsym 'ad-advice-info))) |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
288 (if advice-info |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
289 (progn |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
290 ;; If function is advised, don't let Advice change |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
291 ;; its definition from under us during the `fset'. |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
292 (put funsym 'ad-advice-info nil) |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
293 (fset funsym newguts) |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
294 (put funsym 'ad-advice-info advice-info)) |
908fb90452ba
(elp-instrument-function): Handle advised
Gerd Moellmann <gerd@gnu.org>
parents:
37730
diff
changeset
|
295 (fset funsym newguts))) |
8735 | 296 |
297 ;; add this function to the instrumentation list | |
41177
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
298 (unless (memq funsym elp-all-instrumented-list) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
299 (push funsym elp-all-instrumented-list)))) |
8735 | 300 |
301 (defun elp-restore-function (funsym) | |
302 "Restore an instrumented function to its original definition. | |
303 Argument FUNSYM is the symbol of a defined function." | |
304 (interactive "aFunction to restore: ") | |
305 (let ((info (get funsym elp-timer-info-property))) | |
306 ;; delete the function from the all instrumented list | |
307 (setq elp-all-instrumented-list | |
308 (delq funsym elp-all-instrumented-list)) | |
309 | |
310 ;; if the function was the master, reset the master | |
311 (if (eq funsym elp-master) | |
312 (setq elp-master nil | |
313 elp-record-p t)) | |
314 | |
315 ;; zap the properties | |
316 (put funsym elp-timer-info-property nil) | |
317 | |
318 ;; restore the original function definition, but if the function | |
319 ;; wasn't instrumented do nothing. we do this after the above | |
320 ;; because its possible the function got un-instrumented due to | |
321 ;; circumstances beyond our control. Also, check to make sure | |
322 ;; that the current function symbol points to elp-wrapper. If | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
323 ;; not, then the user probably did an eval-defun, or loaded a |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
324 ;; byte-compiled version, while the function was instrumented and |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
325 ;; we don't want to destroy the new definition. can it ever be |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
326 ;; the case that a lisp function can be compiled instrumented? |
8735 | 327 (and info |
17420
782c3dac70b1
(elp-functionp): Definitions deleted; use functionp.
Richard M. Stallman <rms@gnu.org>
parents:
17419
diff
changeset
|
328 (functionp funsym) |
29211
88e33ac31c14
(elp-restore-function): Don't use obsolete byte-code-function-p.
Dave Love <fx@gnu.org>
parents:
21172
diff
changeset
|
329 (not (byte-code-function-p (symbol-function funsym))) |
8735 | 330 (assq 'elp-wrapper (symbol-function funsym)) |
331 (fset funsym (aref info 2))))) | |
332 | |
8745 | 333 ;;;###autoload |
8735 | 334 (defun elp-instrument-list (&optional list) |
335 "Instrument for profiling, all functions in `elp-function-list'. | |
336 Use optional LIST if provided instead." | |
337 (interactive "PList of functions to instrument: ") | |
338 (let ((list (or list elp-function-list))) | |
339 (mapcar 'elp-instrument-function list))) | |
340 | |
8745 | 341 ;;;###autoload |
8744 | 342 (defun elp-instrument-package (prefix) |
343 "Instrument for profiling, all functions which start with PREFIX. | |
344 For example, to instrument all ELP functions, do the following: | |
345 | |
346 \\[elp-instrument-package] RET elp- RET" | |
347 (interactive "sPrefix of package to instrument: ") | |
37730
76d0f25cf1a3
(elp-instrument-package): Don't allow empty prefixes.
Eli Zaretskii <eliz@gnu.org>
parents:
33128
diff
changeset
|
348 (if (zerop (length prefix)) |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37785
diff
changeset
|
349 (error "Instrumenting all Emacs functions would render Emacs unusable")) |
8744 | 350 (elp-instrument-list |
17527
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
351 (mapcar |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
352 'intern |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
353 (all-completions |
2f06477dce5d
(elp-report-limit): Change prompt string.
Richard M. Stallman <rms@gnu.org>
parents:
17424
diff
changeset
|
354 prefix obarray |
41177
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
355 (lambda (sym) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
356 (and (fboundp sym) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
357 (not (or (memq (car-safe (symbol-function sym)) '(autoload macro)) |
830a17080380
(elp-not-profilable): New var.
Stefan Monnier <monnier@iro.umontreal.ca>
parents:
38414
diff
changeset
|
358 (elp-not-profilable-p sym))))))))) |
8744 | 359 |
8735 | 360 (defun elp-restore-list (&optional list) |
361 "Restore the original definitions for all functions in `elp-function-list'. | |
362 Use optional LIST if provided instead." | |
363 (interactive "PList of functions to restore: ") | |
364 (let ((list (or list elp-function-list))) | |
365 (mapcar 'elp-restore-function list))) | |
366 | |
367 (defun elp-restore-all () | |
368 "Restores the original definitions of all functions being profiled." | |
369 (interactive) | |
370 (elp-restore-list elp-all-instrumented-list)) | |
371 | |
372 | |
373 (defun elp-reset-function (funsym) | |
374 "Reset the profiling information for FUNSYM." | |
375 (interactive "aFunction to reset: ") | |
376 (let ((info (get funsym elp-timer-info-property))) | |
377 (or info | |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37785
diff
changeset
|
378 (error "%s is not instrumented for profiling" funsym)) |
8735 | 379 (aset info 0 0) ;reset call counter |
380 (aset info 1 0.0) ;reset total time | |
381 ;; don't muck with aref 2 as that is the old symbol definition | |
382 )) | |
383 | |
384 (defun elp-reset-list (&optional list) | |
385 "Reset the profiling information for all functions in `elp-function-list'. | |
386 Use optional LIST if provided instead." | |
387 (interactive "PList of functions to reset: ") | |
388 (let ((list (or list elp-function-list))) | |
389 (mapcar 'elp-reset-function list))) | |
390 | |
391 (defun elp-reset-all () | |
392 "Reset the profiling information for all functions being profiled." | |
393 (interactive) | |
394 (elp-reset-list elp-all-instrumented-list)) | |
395 | |
396 (defun elp-set-master (funsym) | |
397 "Set the master function for profiling." | |
398 (interactive "aMaster function: ") | |
399 ;; when there's a master function, recording is turned off by | |
400 ;; default | |
401 (setq elp-master funsym | |
402 elp-record-p nil) | |
403 ;; make sure master function is instrumented | |
404 (or (memq funsym elp-all-instrumented-list) | |
405 (elp-instrument-function funsym))) | |
406 | |
407 (defun elp-unset-master () | |
408 "Unsets the master function." | |
10234
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
409 (interactive) |
8735 | 410 ;; when there's no master function, recording is turned on by default. |
411 (setq elp-master nil | |
412 elp-record-p t)) | |
413 | |
414 | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
415 (defsubst elp-elapsed-time (start end) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
416 (+ (* (- (car end) (car start)) 65536.0) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
417 (- (car (cdr end)) (car (cdr start))) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
418 (/ (- (car (cdr (cdr end))) (car (cdr (cdr start)))) 1000000.0))) |
8735 | 419 |
420 (defun elp-wrapper (funsym interactive-p args) | |
421 "This function has been instrumented for profiling by the ELP. | |
422 ELP is the Emacs Lisp Profiler. To restore the function to its | |
423 original definition, use \\[elp-restore-function] or \\[elp-restore-all]." | |
424 ;; turn on recording if this is the master function | |
425 (if (and elp-master | |
426 (eq funsym elp-master)) | |
427 (setq elp-record-p t)) | |
428 ;; get info vector and original function symbol | |
429 (let* ((info (get funsym elp-timer-info-property)) | |
430 (func (aref info 2)) | |
431 result) | |
432 (or func | |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37785
diff
changeset
|
433 (error "%s is not instrumented for profiling" funsym)) |
8735 | 434 (if (not elp-record-p) |
435 ;; when not recording, just call the original function symbol | |
436 ;; and return the results. | |
437 (setq result | |
438 (if interactive-p | |
439 (call-interactively func) | |
440 (apply func args))) | |
441 ;; we are recording times | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
442 (let (enter-time exit-time) |
8735 | 443 ;; increment the call-counter |
444 (aset info 0 (1+ (aref info 0))) | |
445 ;; now call the old symbol function, checking to see if it | |
446 ;; should be called interactively. make sure we return the | |
447 ;; correct value | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
448 (if interactive-p |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
449 (setq enter-time (current-time) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
450 result (call-interactively func) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
451 exit-time (current-time)) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
452 (setq enter-time (current-time) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
453 result (apply func args) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
454 exit-time (current-time))) |
8735 | 455 ;; calculate total time in function |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
456 (aset info 1 (+ (aref info 1) (elp-elapsed-time enter-time exit-time))) |
8735 | 457 )) |
458 ;; turn off recording if this is the master function | |
459 (if (and elp-master | |
460 (eq funsym elp-master)) | |
461 (setq elp-record-p nil)) | |
462 result)) | |
463 | |
464 | |
465 ;; shut the byte-compiler up | |
466 (defvar elp-field-len nil) | |
467 (defvar elp-cc-len nil) | |
468 (defvar elp-at-len nil) | |
469 (defvar elp-et-len nil) | |
470 | |
471 (defun elp-sort-by-call-count (vec1 vec2) | |
472 ;; sort by highest call count. See `sort'. | |
473 (>= (aref vec1 0) (aref vec2 0))) | |
474 | |
475 (defun elp-sort-by-total-time (vec1 vec2) | |
476 ;; sort by highest total time spent in function. See `sort'. | |
477 (>= (aref vec1 1) (aref vec2 1))) | |
478 | |
479 (defun elp-sort-by-average-time (vec1 vec2) | |
480 ;; sort by highest average time spent in function. See `sort'. | |
481 (>= (aref vec1 2) (aref vec2 2))) | |
482 | |
10234
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
483 (defsubst elp-pack-number (number width) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
484 ;; 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
|
485 ;; very small or large numbers |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
486 (if (<= (length number) width) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
487 number |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
488 ;; check for very large or small numbers |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
489 (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
490 (concat (substring |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
491 (substring number (match-beginning 1) (match-end 1)) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
492 0 |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
493 (- width (match-end 2) (- (match-beginning 2)) 3)) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
494 "..." |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
495 (substring number (match-beginning 2) (match-end 2))) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
496 (concat (substring number 0 width))))) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
497 |
8735 | 498 (defun elp-output-result (resultvec) |
499 ;; output the RESULTVEC into the results buffer. RESULTVEC is a 4 or | |
500 ;; more element vector where aref 0 is the call count, aref 1 is the | |
501 ;; total time spent in the function, aref 2 is the average time | |
502 ;; spent in the function, and aref 3 is the symbol's string | |
503 ;; name. All other elements in the vector are ignored. | |
504 (let* ((cc (aref resultvec 0)) | |
505 (tt (aref resultvec 1)) | |
506 (at (aref resultvec 2)) | |
507 (symname (aref resultvec 3)) | |
508 callcnt totaltime avetime) | |
509 (setq callcnt (number-to-string cc) | |
510 totaltime (number-to-string tt) | |
511 avetime (number-to-string at)) | |
8744 | 512 ;; possibly prune the results |
513 (if (and elp-report-limit | |
514 (numberp elp-report-limit) | |
515 (< cc elp-report-limit)) | |
516 nil | |
56711
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
517 (elp-output-insert-symname symname) |
8744 | 518 (insert-char 32 (+ elp-field-len (- (length symname)) 2)) |
519 ;; print stuff out, formatting it nicely | |
520 (insert callcnt) | |
521 (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
|
522 (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
|
523 (atstr (elp-pack-number avetime elp-at-len))) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
524 (insert ttstr) |
170c4c188d4f
(elp-pack-number): New function.
Richard M. Stallman <rms@gnu.org>
parents:
8745
diff
changeset
|
525 (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
|
526 (insert atstr)) |
8744 | 527 (insert "\n")))) |
8735 | 528 |
56711
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
529 (defvar elp-results-symname-map |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
530 (let ((map (make-sparse-keymap))) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
531 (define-key map [mouse-2] 'elp-results-jump-to-definition-by-mouse) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
532 (define-key map "\C-m" 'elp-results-jump-to-definition) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
533 map) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
534 "Keymap used on the function name column." ) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
535 |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
536 (defun elp-results-jump-to-definition-by-mouse (event) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
537 "Jump to the definition of the function under the place specified by EVENT." |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
538 (interactive "e") |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
539 (posn-set-point (event-end event)) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
540 (elp-results-jump-to-definition)) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
541 |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
542 (defun elp-results-jump-to-definition () |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
543 "Jump to the definition of the function under the point." |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
544 (interactive) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
545 (find-function (get-text-property (point) 'elp-symname))) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
546 |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
547 (defun elp-output-insert-symname (symname) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
548 ;; Insert SYMNAME with text properties. |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
549 (insert (propertize symname |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
550 'elp-symname (intern symname) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
551 'keymap elp-results-symname-map |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
552 'mouse-face 'highlight |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
553 'help-echo (substitute-command-keys "\\{elp-results-symname-map}")))) |
eee6cc3fe45e
(elp-results-symname-map): New keymap.
Masatake YAMATO <jet@gyve.org>
parents:
52401
diff
changeset
|
554 |
8745 | 555 ;;;###autoload |
8735 | 556 (defun elp-results () |
557 "Display current profiling results. | |
558 If `elp-reset-after-results' is non-nil, then current profiling | |
559 information for all instrumented functions are reset after results are | |
560 displayed." | |
561 (interactive) | |
562 (let ((curbuf (current-buffer)) | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
563 (resultsbuf (if elp-recycle-buffers-p |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
564 (get-buffer-create elp-results-buffer) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
565 (generate-new-buffer elp-results-buffer)))) |
8735 | 566 (set-buffer resultsbuf) |
567 (erase-buffer) | |
568 ;; get the length of the longest function name being profiled | |
569 (let* ((longest 0) | |
570 (title "Function Name") | |
571 (titlelen (length title)) | |
572 (elp-field-len titlelen) | |
573 (cc-header "Call Count") | |
574 (elp-cc-len (length cc-header)) | |
575 (et-header "Elapsed Time") | |
576 (elp-et-len (length et-header)) | |
577 (at-header "Average Time") | |
578 (elp-at-len (length at-header)) | |
579 (resvec | |
580 (mapcar | |
581 (function | |
582 (lambda (funsym) | |
583 (let* ((info (get funsym elp-timer-info-property)) | |
584 (symname (format "%s" funsym)) | |
585 (cc (aref info 0)) | |
586 (tt (aref info 1))) | |
587 (if (not info) | |
588 (insert "No profiling information found for: " | |
589 symname) | |
590 (setq longest (max longest (length symname))) | |
591 (vector cc tt (if (zerop cc) | |
592 0.0 ;avoid arithmetic div-by-zero errors | |
593 (/ (float tt) (float cc))) | |
594 symname))))) | |
595 elp-all-instrumented-list)) | |
596 ) ; end let* | |
597 (insert title) | |
598 (if (> longest titlelen) | |
599 (progn | |
600 (insert-char 32 (- longest titlelen)) | |
601 (setq elp-field-len longest))) | |
602 (insert " " cc-header " " et-header " " at-header "\n") | |
603 (insert-char ?= elp-field-len) | |
604 (insert " ") | |
605 (insert-char ?= elp-cc-len) | |
606 (insert " ") | |
607 (insert-char ?= elp-et-len) | |
608 (insert " ") | |
609 (insert-char ?= elp-at-len) | |
610 (insert "\n") | |
611 ;; if sorting is enabled, then sort the results list. in either | |
612 ;; case, call elp-output-result to output the result in the | |
613 ;; buffer | |
614 (if elp-sort-by-function | |
615 (setq resvec (sort resvec elp-sort-by-function))) | |
616 (mapcar 'elp-output-result resvec)) | |
617 ;; now pop up results buffer | |
618 (set-buffer curbuf) | |
619 (pop-to-buffer resultsbuf) | |
17419
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
620 ;; copy results to standard-output? |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
621 (if (or elp-use-standard-output noninteractive) |
c9f73399244c
(elp-functionp): New function.
Richard M. Stallman <rms@gnu.org>
parents:
14858
diff
changeset
|
622 (princ (buffer-substring (point-min) (point-max)))) |
8735 | 623 ;; reset profiling info if desired |
624 (and elp-reset-after-results | |
625 (elp-reset-all)))) | |
33095 | 626 |
627 (defun elp-unload-hook () | |
628 (elp-restore-all)) | |
57520
b7788b1f6e70
(elp-unload-hook): Set the variable.
Richard M. Stallman <rms@gnu.org>
parents:
56711
diff
changeset
|
629 (add-hook 'elp-unload-hook 'elp-unload-hook) |
8735 | 630 |
631 (provide 'elp) | |
10263 | 632 |
52401 | 633 ;;; arch-tag: c4eef311-9b3e-4bb2-8a54-3485d41b4eb1 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
37785
diff
changeset
|
634 ;;; elp.el ends here |