0
|
1 ;;; elp.el --- Emacs Lisp Profiler
|
|
2
|
|
3 ;; Copyright (C) 1994 Free Software Foundation, Inc.
|
|
4
|
4
|
5 ;; Author: 1994-1996 Barry A. Warsaw
|
|
6 ;; Maintainer: tools-help@python.org
|
0
|
7 ;; Created: 26-Feb-1994
|
4
|
8 ;; Version: 2.37
|
|
9 ;; Last Modified: 1996/10/23 04:06:58
|
0
|
10 ;; Keywords: debugging lisp tools
|
|
11
|
|
12 ;; This file is part of GNU Emacs.
|
|
13
|
|
14 ;; GNU Emacs is free software; you can redistribute it and/or modify
|
|
15 ;; it under the terms of the GNU General Public License as published by
|
|
16 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
17 ;; any later version.
|
|
18
|
|
19 ;; GNU Emacs is distributed in the hope that it will be useful,
|
|
20 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
21 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
22 ;; GNU General Public License for more details.
|
|
23
|
|
24 ;; You should have received a copy of the GNU General Public License
|
|
25 ;; along with GNU Emacs; see the file COPYING. If not, write to
|
|
26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
27
|
|
28 ;;; Commentary:
|
|
29 ;;
|
|
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
|
|
34 ;; M-x elp-results. If you want output to go to standard-output
|
|
35 ;; instead of a separate buffer, setq elp-use-standard-output to
|
|
36 ;; non-nil. With elp-reset-after-results set to non-nil, profiling
|
|
37 ;; information will be reset whenever the results are displayed. You
|
|
38 ;; can also reset all profiling info at any time with M-x
|
|
39 ;; elp-reset-all.
|
|
40 ;;
|
|
41 ;; You can also instrument all functions in a package, provided that
|
|
42 ;; the package follows the GNU coding standard of a common textural
|
|
43 ;; prefix. Use M-x elp-instrument-package for this.
|
|
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
|
|
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.
|
|
51 ;;
|
|
52 ;; Elp can instrument byte-compiled functions just as easily as
|
|
53 ;; interpreted functions, but it cannot instrument macros. However,
|
|
54 ;; when you redefine a function (e.g. with eval-defun), you'll need to
|
|
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.
|
|
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,
|
|
69 ;; but only during execution of bar, make bar the master. The call of
|
|
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.
|
|
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
|
|
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 ;; elp-submit-bug-report
|
|
98
|
|
99 ;; Note that there are plenty of factors that could make the times
|
|
100 ;; reported unreliable, including the accuracy and granularity of your
|
|
101 ;; system clock, and the overhead spent in lisp calculating and
|
|
102 ;; recording the intervals. I figure the latter is pretty constant,
|
|
103 ;; so while the times may not be entirely accurate, I think they'll
|
|
104 ;; give you a good feel for the relative amount of work spent in the
|
|
105 ;; various lisp routines you are profiling. Note further that times
|
|
106 ;; are calculated using wall-clock time, so other system load will
|
|
107 ;; affect accuracy too. You cannot profile anything longer than ~18
|
|
108 ;; hours since I throw away the most significant 16 bits of seconds
|
|
109 ;; returned by current-time: 2^16 == 65536 seconds == ~1092 minutes ==
|
|
110 ;; ~18 hours. I doubt you will ever want to profile stuff on the
|
|
111 ;; order of 18 hours anyway.
|
|
112
|
|
113 ;;; Background:
|
|
114 ;;
|
|
115 ;; This program was inspired by the only two existing Emacs Lisp
|
|
116 ;; profilers that I'm aware of, Boaz Ben-Zvi's profile.el, and Root
|
|
117 ;; Boy Jim's profiler.el. Both were written for Emacs 18 and both were
|
|
118 ;; pretty good first shots at profiling, but I found that they didn't
|
|
119 ;; provide the functionality or interface that I wanted, so I wrote
|
|
120 ;; this. I've tested elp in XEmacs 19 and Emacs 19. There's no point
|
|
121 ;; in even trying to make this work with Emacs 18.
|
|
122
|
|
123 ;; Unlike previous profilers, elp uses Emacs 19's built-in function
|
|
124 ;; current-time to return interval times. This obviates the need for
|
|
125 ;; both an external C program and Emacs processes to communicate with
|
|
126 ;; such a program, and thus simplifies the package as a whole.
|
|
127
|
|
128 ;; TBD:
|
|
129 ;; Make this act like a real profiler, so that it records time spent
|
|
130 ;; in all branches of execution.
|
|
131
|
|
132 ;;; Code:
|
|
133
|
|
134
|
|
135 ;; start of user configuration variables
|
|
136 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
|
|
137
|
|
138 (defvar elp-function-list nil
|
|
139 "*List of functions to profile.
|
|
140 Used by the command `elp-instrument-list'.")
|
|
141
|
|
142 (defvar elp-reset-after-results t
|
|
143 "*Non-nil means reset all profiling info after results are displayed.
|
|
144 Results are displayed with the `elp-results' command.")
|
|
145
|
|
146 (defvar elp-sort-by-function 'elp-sort-by-total-time
|
|
147 "*Non-nil specifies elp results sorting function.
|
|
148 These functions are currently available:
|
|
149
|
|
150 elp-sort-by-call-count -- sort by the highest call count
|
|
151 elp-sort-by-total-time -- sort by the highest total time
|
|
152 elp-sort-by-average-time -- sort by the highest average times
|
|
153
|
|
154 You can write you're own sort function. It should adhere to the
|
|
155 interface specified by the PRED argument for the `sort' defun. Each
|
|
156 \"element of LIST\" is really a 4 element vector where element 0 is
|
|
157 the call count, element 1 is the total time spent in the function,
|
|
158 element 2 is the average time spent in the function, and element 3 is
|
|
159 the symbol's name string.")
|
|
160
|
|
161 (defvar elp-report-limit 1
|
|
162 "*Prevents some functions from being displayed in the results buffer.
|
|
163 If a number, no function that has been called fewer than that number
|
|
164 of times will be displayed in the output buffer. If nil, all
|
|
165 functions will be displayed.")
|
|
166
|
|
167 (defvar elp-use-standard-output nil
|
|
168 "*Non-nil says to output to `standard-output' instead of a buffer.")
|
|
169
|
|
170 (defvar elp-recycle-buffers-p t
|
|
171 "*Nil says to not recycle the `elp-results-buffer'.
|
|
172 In other words, a new unique buffer is create every time you run
|
|
173 \\[elp-results].")
|
|
174
|
|
175
|
|
176 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
|
177 ;; end of user configuration variables
|
|
178
|
|
179
|
4
|
180 (defconst elp-version "2.37"
|
0
|
181 "ELP version number.")
|
|
182
|
4
|
183 (defconst elp-help-address "tools-help@python.org"
|
0
|
184 "Address accepting submissions of bug reports and questions.")
|
|
185
|
|
186 (defvar elp-results-buffer "*ELP Profiling Results*"
|
|
187 "Buffer name for outputting profiling results.")
|
|
188
|
|
189 (defconst elp-timer-info-property 'elp-info
|
|
190 "ELP information property name.")
|
|
191
|
|
192 (defvar elp-all-instrumented-list nil
|
|
193 "List of all functions currently being instrumented.")
|
|
194
|
|
195 (defvar elp-record-p t
|
|
196 "Controls whether functions should record times or not.
|
|
197 This variable is set by the master function.")
|
|
198
|
|
199 (defvar elp-master nil
|
|
200 "Master function symbol.")
|
|
201
|
|
202
|
|
203 ;;;###autoload
|
|
204 (defun elp-instrument-function (funsym)
|
|
205 "Instrument FUNSYM for profiling.
|
|
206 FUNSYM must be a symbol of a defined function."
|
|
207 (interactive "aFunction to instrument: ")
|
4
|
208 ;; restore the function. this is necessary to avoid infinite
|
|
209 ;; recursion of already instrumented functions (i.e. elp-wrapper
|
|
210 ;; calling elp-wrapper ad infinitum). it is better to simply
|
|
211 ;; restore the function than to throw an error. this will work
|
|
212 ;; properly in the face of eval-defun because if the function was
|
|
213 ;; redefined, only the timer info will be nil'd out since
|
|
214 ;; elp-restore-function is smart enough not to trash the new
|
|
215 ;; definition.
|
|
216 (elp-restore-function funsym)
|
0
|
217 (let* ((funguts (symbol-function funsym))
|
|
218 (infovec (vector 0 0 funguts))
|
|
219 (newguts '(lambda (&rest args))))
|
|
220 ;; we cannot profile macros
|
|
221 (and (eq (car-safe funguts) 'macro)
|
4
|
222 (error "ELP cannot profile macro: %s" funsym))
|
|
223 ;; TBD: at some point it might be better to load the autoloaded
|
|
224 ;; function instead of throwing an error. if we do this, then we
|
|
225 ;; probably want elp-instrument-package to be updated with the
|
|
226 ;; newly loaded list of functions. i'm not sure it's smart to do
|
|
227 ;; the autoload here, since that could have side effects, and
|
|
228 ;; elp-instrument-function is similar (in my mind) to defun-ish
|
|
229 ;; type functionality (i.e. it shouldn't execute the function).
|
|
230 (and (eq (car-safe funguts) 'autoload)
|
|
231 (error "ELP cannot profile autoloaded function: %s" funsym))
|
0
|
232 ;; put rest of newguts together
|
|
233 (if (commandp funsym)
|
|
234 (setq newguts (append newguts '((interactive)))))
|
|
235 (setq newguts (append newguts (list
|
|
236 (list 'elp-wrapper
|
|
237 (list 'quote funsym)
|
|
238 (list 'and
|
|
239 '(interactive-p)
|
|
240 (not (not (commandp funsym))))
|
|
241 'args))))
|
|
242 ;; to record profiling times, we set the symbol's function
|
|
243 ;; definition so that it runs the elp-wrapper function with the
|
|
244 ;; function symbol as an argument. We place the old function
|
|
245 ;; definition on the info vector.
|
|
246 ;;
|
|
247 ;; The info vector data structure is a 3 element vector. The 0th
|
|
248 ;; element is the call-count, i.e. the total number of times this
|
|
249 ;; function has been entered. This value is bumped up on entry to
|
|
250 ;; the function so that non-local exists are still recorded. TBD:
|
|
251 ;; I haven't tested non-local exits at all, so no guarantees.
|
|
252 ;;
|
|
253 ;; The 1st element is the total amount of time in usecs that have
|
|
254 ;; been spent inside this function. This number is added to on
|
|
255 ;; function exit.
|
|
256 ;;
|
|
257 ;; The 2nd element is the old function definition list. This gets
|
|
258 ;; funcall'd in between start/end time retrievals. I believe that
|
|
259 ;; this lets us profile even byte-compiled functions.
|
|
260
|
|
261 ;; put the info vector on the property list
|
|
262 (put funsym elp-timer-info-property infovec)
|
|
263
|
|
264 ;; set the symbol's new profiling function definition to run
|
|
265 ;; elp-wrapper
|
|
266 (fset funsym newguts)
|
|
267
|
|
268 ;; add this function to the instrumentation list
|
|
269 (or (memq funsym elp-all-instrumented-list)
|
|
270 (setq elp-all-instrumented-list
|
|
271 (cons funsym elp-all-instrumented-list)))
|
|
272 ))
|
|
273
|
|
274 ;;;###autoload
|
|
275 (defun elp-restore-function (funsym)
|
|
276 "Restore an instrumented function to its original definition.
|
|
277 Argument FUNSYM is the symbol of a defined function."
|
|
278 (interactive "aFunction to restore: ")
|
|
279 (let ((info (get funsym elp-timer-info-property)))
|
|
280 ;; delete the function from the all instrumented list
|
|
281 (setq elp-all-instrumented-list
|
|
282 (delq funsym elp-all-instrumented-list))
|
|
283
|
|
284 ;; if the function was the master, reset the master
|
|
285 (if (eq funsym elp-master)
|
|
286 (setq elp-master nil
|
|
287 elp-record-p t))
|
|
288
|
|
289 ;; zap the properties
|
|
290 (put funsym elp-timer-info-property nil)
|
|
291
|
|
292 ;; restore the original function definition, but if the function
|
|
293 ;; wasn't instrumented do nothing. we do this after the above
|
|
294 ;; because its possible the function got un-instrumented due to
|
|
295 ;; circumstances beyond our control. Also, check to make sure
|
|
296 ;; that the current function symbol points to elp-wrapper. If
|
4
|
297 ;; not, then the user probably did an eval-defun, or loaded a
|
|
298 ;; byte-compiled version, while the function was instrumented and
|
|
299 ;; we don't want to destroy the new definition. can it ever be
|
|
300 ;; the case that a lisp function can be compiled instrumented?
|
0
|
301 (and info
|
4
|
302 (not (compiled-function-p (symbol-function funsym)))
|
0
|
303 (assq 'elp-wrapper (symbol-function funsym))
|
|
304 (fset funsym (aref info 2)))))
|
|
305
|
|
306 ;;;###autoload
|
|
307 (defun elp-instrument-list (&optional list)
|
|
308 "Instrument for profiling, all functions in `elp-function-list'.
|
|
309 Use optional LIST if provided instead."
|
|
310 (interactive "PList of functions to instrument: ")
|
|
311 (let ((list (or list elp-function-list)))
|
4
|
312 (mapcar 'elp-instrument-function list)))
|
0
|
313
|
|
314 ;;;###autoload
|
|
315 (defun elp-instrument-package (prefix)
|
|
316 "Instrument for profiling, all functions which start with PREFIX.
|
|
317 For example, to instrument all ELP functions, do the following:
|
|
318
|
|
319 \\[elp-instrument-package] RET elp- RET"
|
|
320 (interactive "sPrefix of package to instrument: ")
|
|
321 (elp-instrument-list
|
|
322 (mapcar 'intern (all-completions prefix obarray
|
|
323 (function
|
|
324 (lambda (sym)
|
|
325 (and (fboundp sym)
|
|
326 (not (eq (car-safe
|
|
327 (symbol-function sym))
|
|
328 'macro)))))))))
|
|
329
|
|
330 (defun elp-restore-list (&optional list)
|
|
331 "Restore the original definitions for all functions in `elp-function-list'.
|
|
332 Use optional LIST if provided instead."
|
|
333 (interactive "PList of functions to restore: ")
|
|
334 (let ((list (or list elp-function-list)))
|
|
335 (mapcar 'elp-restore-function list)))
|
|
336
|
|
337 (defun elp-restore-all ()
|
|
338 "Restores the original definitions of all functions being profiled."
|
|
339 (interactive)
|
|
340 (elp-restore-list elp-all-instrumented-list))
|
|
341
|
|
342
|
|
343 (defun elp-reset-function (funsym)
|
|
344 "Reset the profiling information for FUNSYM."
|
|
345 (interactive "aFunction to reset: ")
|
|
346 (let ((info (get funsym elp-timer-info-property)))
|
|
347 (or info
|
|
348 (error "%s is not instrumented for profiling." funsym))
|
|
349 (aset info 0 0) ;reset call counter
|
|
350 (aset info 1 0.0) ;reset total time
|
|
351 ;; don't muck with aref 2 as that is the old symbol definition
|
|
352 ))
|
|
353
|
|
354 (defun elp-reset-list (&optional list)
|
|
355 "Reset the profiling information for all functions in `elp-function-list'.
|
|
356 Use optional LIST if provided instead."
|
|
357 (interactive "PList of functions to reset: ")
|
|
358 (let ((list (or list elp-function-list)))
|
|
359 (mapcar 'elp-reset-function list)))
|
|
360
|
|
361 (defun elp-reset-all ()
|
|
362 "Reset the profiling information for all functions being profiled."
|
|
363 (interactive)
|
|
364 (elp-reset-list elp-all-instrumented-list))
|
|
365
|
|
366 (defun elp-set-master (funsym)
|
|
367 "Set the master function for profiling."
|
|
368 (interactive "aMaster function: ")
|
|
369 ;; when there's a master function, recording is turned off by
|
|
370 ;; default
|
|
371 (setq elp-master funsym
|
|
372 elp-record-p nil)
|
|
373 ;; make sure master function is instrumented
|
|
374 (or (memq funsym elp-all-instrumented-list)
|
|
375 (elp-instrument-function funsym)))
|
|
376
|
|
377 (defun elp-unset-master ()
|
|
378 "Unsets the master function."
|
|
379 (interactive)
|
|
380 ;; when there's no master function, recording is turned on by default.
|
|
381 (setq elp-master nil
|
|
382 elp-record-p t))
|
|
383
|
|
384
|
|
385 (defsubst elp-get-time ()
|
|
386 ;; get current time in seconds and microseconds. I throw away the
|
|
387 ;; most significant 16 bits of seconds since I doubt we'll ever want
|
|
388 ;; to profile lisp on the order of 18 hours. See notes at top of file.
|
|
389 (let ((now (current-time)))
|
|
390 (+ (float (nth 1 now)) (/ (float (nth 2 now)) 1000000.0))))
|
|
391
|
|
392 (defun elp-wrapper (funsym interactive-p args)
|
|
393 "This function has been instrumented for profiling by the ELP.
|
|
394 ELP is the Emacs Lisp Profiler. To restore the function to its
|
|
395 original definition, use \\[elp-restore-function] or \\[elp-restore-all]."
|
|
396 ;; turn on recording if this is the master function
|
|
397 (if (and elp-master
|
|
398 (eq funsym elp-master))
|
|
399 (setq elp-record-p t))
|
|
400 ;; get info vector and original function symbol
|
|
401 (let* ((info (get funsym elp-timer-info-property))
|
|
402 (func (aref info 2))
|
|
403 result)
|
|
404 (or func
|
|
405 (error "%s is not instrumented for profiling." funsym))
|
|
406 (if (not elp-record-p)
|
|
407 ;; when not recording, just call the original function symbol
|
|
408 ;; and return the results.
|
|
409 (setq result
|
|
410 (if interactive-p
|
|
411 (call-interactively func)
|
|
412 (apply func args)))
|
|
413 ;; we are recording times
|
|
414 (let ((enter-time (elp-get-time)))
|
|
415 ;; increment the call-counter
|
|
416 (aset info 0 (1+ (aref info 0)))
|
|
417 ;; now call the old symbol function, checking to see if it
|
|
418 ;; should be called interactively. make sure we return the
|
|
419 ;; correct value
|
|
420 (setq result
|
|
421 (if interactive-p
|
|
422 (call-interactively func)
|
|
423 (apply func args)))
|
|
424 ;; calculate total time in function
|
|
425 (aset info 1 (+ (aref info 1) (- (elp-get-time) enter-time)))
|
|
426 ))
|
|
427 ;; turn off recording if this is the master function
|
|
428 (if (and elp-master
|
|
429 (eq funsym elp-master))
|
|
430 (setq elp-record-p nil))
|
|
431 result))
|
|
432
|
|
433
|
|
434 ;; shut the byte-compiler up
|
|
435 (defvar elp-field-len nil)
|
|
436 (defvar elp-cc-len nil)
|
|
437 (defvar elp-at-len nil)
|
|
438 (defvar elp-et-len nil)
|
|
439
|
|
440 (defun elp-sort-by-call-count (vec1 vec2)
|
|
441 ;; sort by highest call count. See `sort'.
|
|
442 (>= (aref vec1 0) (aref vec2 0)))
|
|
443
|
|
444 (defun elp-sort-by-total-time (vec1 vec2)
|
|
445 ;; sort by highest total time spent in function. See `sort'.
|
|
446 (>= (aref vec1 1) (aref vec2 1)))
|
|
447
|
|
448 (defun elp-sort-by-average-time (vec1 vec2)
|
|
449 ;; sort by highest average time spent in function. See `sort'.
|
|
450 (>= (aref vec1 2) (aref vec2 2)))
|
|
451
|
|
452 (defsubst elp-pack-number (number width)
|
|
453 ;; pack the NUMBER string into WIDTH characters, watching out for
|
|
454 ;; very small or large numbers
|
|
455 (if (<= (length number) width)
|
|
456 number
|
|
457 ;; check for very large or small numbers
|
|
458 (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number)
|
|
459 (concat (substring
|
|
460 (substring number (match-beginning 1) (match-end 1))
|
|
461 0
|
|
462 (- width (match-end 2) (- (match-beginning 2)) 3))
|
|
463 "..."
|
|
464 (substring number (match-beginning 2) (match-end 2)))
|
|
465 (concat (substring number 0 width)))))
|
|
466
|
|
467 (defun elp-output-result (resultvec)
|
|
468 ;; output the RESULTVEC into the results buffer. RESULTVEC is a 4 or
|
|
469 ;; more element vector where aref 0 is the call count, aref 1 is the
|
|
470 ;; total time spent in the function, aref 2 is the average time
|
|
471 ;; spent in the function, and aref 3 is the symbol's string
|
|
472 ;; name. All other elements in the vector are ignored.
|
|
473 (let* ((cc (aref resultvec 0))
|
|
474 (tt (aref resultvec 1))
|
|
475 (at (aref resultvec 2))
|
|
476 (symname (aref resultvec 3))
|
|
477 callcnt totaltime avetime)
|
|
478 (setq callcnt (number-to-string cc)
|
|
479 totaltime (number-to-string tt)
|
|
480 avetime (number-to-string at))
|
|
481 ;; possibly prune the results
|
|
482 (if (and elp-report-limit
|
|
483 (numberp elp-report-limit)
|
|
484 (< cc elp-report-limit))
|
|
485 nil
|
|
486 (insert symname)
|
|
487 (insert-char 32 (+ elp-field-len (- (length symname)) 2))
|
|
488 ;; print stuff out, formatting it nicely
|
|
489 (insert callcnt)
|
|
490 (insert-char 32 (+ elp-cc-len (- (length callcnt)) 2))
|
|
491 (let ((ttstr (elp-pack-number totaltime elp-et-len))
|
|
492 (atstr (elp-pack-number avetime elp-at-len)))
|
|
493 (insert ttstr)
|
|
494 (insert-char 32 (+ elp-et-len (- (length ttstr)) 2))
|
|
495 (insert atstr))
|
|
496 (insert "\n"))))
|
|
497
|
|
498 ;;;###autoload
|
|
499 (defun elp-results ()
|
|
500 "Display current profiling results.
|
|
501 If `elp-reset-after-results' is non-nil, then current profiling
|
|
502 information for all instrumented functions are reset after results are
|
|
503 displayed."
|
|
504 (interactive)
|
|
505 (let ((curbuf (current-buffer))
|
|
506 (resultsbuf (if elp-recycle-buffers-p
|
|
507 (get-buffer-create elp-results-buffer)
|
|
508 (generate-new-buffer elp-results-buffer))))
|
|
509 (set-buffer resultsbuf)
|
|
510 (erase-buffer)
|
|
511 (beginning-of-buffer)
|
|
512 ;; get the length of the longest function name being profiled
|
|
513 (let* ((longest 0)
|
|
514 (title "Function Name")
|
|
515 (titlelen (length title))
|
|
516 (elp-field-len titlelen)
|
|
517 (cc-header "Call Count")
|
|
518 (elp-cc-len (length cc-header))
|
|
519 (et-header "Elapsed Time")
|
|
520 (elp-et-len (length et-header))
|
|
521 (at-header "Average Time")
|
|
522 (elp-at-len (length at-header))
|
|
523 (resvec
|
|
524 (mapcar
|
|
525 (function
|
|
526 (lambda (funsym)
|
|
527 (let* ((info (get funsym elp-timer-info-property))
|
|
528 (symname (format "%s" funsym))
|
|
529 (cc (aref info 0))
|
|
530 (tt (aref info 1)))
|
|
531 (if (not info)
|
|
532 (insert "No profiling information found for: "
|
|
533 symname)
|
|
534 (setq longest (max longest (length symname)))
|
|
535 (vector cc tt (if (zerop cc)
|
|
536 0.0 ;avoid arithmetic div-by-zero errors
|
|
537 (/ (float tt) (float cc)))
|
|
538 symname)))))
|
|
539 elp-all-instrumented-list))
|
|
540 ) ; end let*
|
|
541 (insert title)
|
|
542 (if (> longest titlelen)
|
|
543 (progn
|
|
544 (insert-char 32 (- longest titlelen))
|
|
545 (setq elp-field-len longest)))
|
|
546 (insert " " cc-header " " et-header " " at-header "\n")
|
|
547 (insert-char ?= elp-field-len)
|
|
548 (insert " ")
|
|
549 (insert-char ?= elp-cc-len)
|
|
550 (insert " ")
|
|
551 (insert-char ?= elp-et-len)
|
|
552 (insert " ")
|
|
553 (insert-char ?= elp-at-len)
|
|
554 (insert "\n")
|
|
555 ;; if sorting is enabled, then sort the results list. in either
|
|
556 ;; case, call elp-output-result to output the result in the
|
|
557 ;; buffer
|
|
558 (if elp-sort-by-function
|
|
559 (setq resvec (sort resvec elp-sort-by-function)))
|
|
560 (mapcar 'elp-output-result resvec))
|
|
561 ;; now pop up results buffer
|
|
562 (set-buffer curbuf)
|
|
563 (pop-to-buffer resultsbuf)
|
|
564 ;; copy results to standard-output?
|
|
565 (if (or elp-use-standard-output noninteractive)
|
|
566 (princ (buffer-substring (point-min) (point-max))))
|
|
567 ;; reset profiling info if desired
|
|
568 (and elp-reset-after-results
|
|
569 (elp-reset-all))))
|
|
570
|
|
571
|
|
572 (eval-when-compile
|
|
573 (require 'reporter))
|
|
574
|
|
575 ;;;###autoload
|
|
576 (defun elp-submit-bug-report ()
|
|
577 "Submit via mail, a bug report on elp."
|
|
578 (interactive)
|
|
579 (and
|
|
580 (y-or-n-p "Do you want to submit a report on elp? ")
|
|
581 (require 'reporter)
|
|
582 (reporter-submit-bug-report
|
|
583 elp-help-address (concat "elp " elp-version)
|
|
584 '(elp-report-limit
|
|
585 elp-reset-after-results
|
|
586 elp-sort-by-function))))
|
|
587
|
|
588
|
|
589 (provide 'elp)
|
|
590 ;; elp.el ends here
|