Mercurial > hg > xemacs-beta
comparison lisp/utils/elp.el @ 4:b82b59fe008d r19-15b3
Import from CVS: tag r19-15b3
author | cvs |
---|---|
date | Mon, 13 Aug 2007 08:46:56 +0200 |
parents | 376386a54a3c |
children | cca96a509cfe |
comparison
equal
deleted
inserted
replaced
3:30df88044ec6 | 4:b82b59fe008d |
---|---|
1 ;;; elp.el --- Emacs Lisp Profiler | 1 ;;; elp.el --- Emacs Lisp Profiler |
2 | 2 |
3 ;; Copyright (C) 1994 Free Software Foundation, Inc. | 3 ;; Copyright (C) 1994 Free Software Foundation, Inc. |
4 | 4 |
5 ;; Author: 1994-1995 Barry A. Warsaw | 5 ;; Author: 1994-1996 Barry A. Warsaw |
6 ;; Maintainer: tools-help@merlin.cnri.reston.va.us | 6 ;; Maintainer: tools-help@python.org |
7 ;; Created: 26-Feb-1994 | 7 ;; Created: 26-Feb-1994 |
8 ;; Version: 2.32 | 8 ;; Version: 2.37 |
9 ;; Last Modified: 1995/07/12 18:53:17 | 9 ;; Last Modified: 1996/10/23 04:06:58 |
10 ;; Keywords: debugging lisp tools | 10 ;; Keywords: debugging lisp tools |
11 | 11 |
12 ;; This file is part of GNU Emacs. | 12 ;; This file is part of GNU Emacs. |
13 | 13 |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | 14 ;; GNU Emacs is free software; you can redistribute it and/or modify |
22 ;; GNU General Public License for more details. | 22 ;; GNU General Public License for more details. |
23 | 23 |
24 ;; You should have received a copy of the GNU General Public License | 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 | 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. | 26 ;; the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. |
27 | |
28 ;;; Synched up with: FSF 19.30. | |
29 ;;; In typical "What the hell?" fashion, the version distributed | |
30 ;;; with FSF 19.30 claims to be version 2.33 while ours is version 2.32, | |
31 ;;; but ours is actually more recent. Is this another example of | |
32 ;;; FSFmacs version corruption? | |
33 | 27 |
34 ;;; Commentary: | 28 ;;; Commentary: |
35 ;; | 29 ;; |
36 ;; If you want to profile a bunch of functions, set elp-function-list | 30 ;; If you want to profile a bunch of functions, set elp-function-list |
37 ;; to the list of symbols, then do a M-x elp-instrument-list. This | 31 ;; to the list of symbols, then do a M-x elp-instrument-list. This |
78 ;; Only one master function can be set at a time. | 72 ;; Only one master function can be set at a time. |
79 | 73 |
80 ;; You can restore any function's original function definition with | 74 ;; You can restore any function's original function definition with |
81 ;; elp-restore-function. The other instrument, restore, and reset | 75 ;; elp-restore-function. The other instrument, restore, and reset |
82 ;; functions are provided for symmetry. | 76 ;; functions are provided for symmetry. |
83 | |
84 ;; Note that there are plenty of factors that could make the times | |
85 ;; reported unreliable, including the accuracy and granularity of your | |
86 ;; system clock, and the overhead spent in lisp calculating and | |
87 ;; recording the intervals. The latter I figure is pretty constant | |
88 ;; so, while the times may not be entirely accurate, I think they'll | |
89 ;; give you a good feel for the relative amount of work spent in the | |
90 ;; various lisp routines you are profiling. Note further that times | |
91 ;; are calculated using wall-clock time, so other system load will | |
92 ;; affect accuracy too. | |
93 | 77 |
94 ;; Here is a list of variable you can use to customize elp: | 78 ;; Here is a list of variable you can use to customize elp: |
95 ;; elp-function-list | 79 ;; elp-function-list |
96 ;; elp-reset-after-results | 80 ;; elp-reset-after-results |
97 ;; elp-sort-by-function | 81 ;; elp-sort-by-function |
143 | 127 |
144 ;; TBD: | 128 ;; TBD: |
145 ;; Make this act like a real profiler, so that it records time spent | 129 ;; Make this act like a real profiler, so that it records time spent |
146 ;; in all branches of execution. | 130 ;; in all branches of execution. |
147 | 131 |
148 ;; LCD Archive Entry: | |
149 ;; elp|Barry A. Warsaw|tools-help@merlin.cnri.reston.va.us| | |
150 ;; Emacs Lisp Profiler| | |
151 ;; 1995/07/12 18:53:17|2.32|~/misc/elp.el.Z| | |
152 | |
153 ;;; Code: | 132 ;;; Code: |
154 | 133 |
155 | 134 |
156 ;; start of user configuration variables | 135 ;; start of user configuration variables |
157 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv | 136 ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv |
196 | 175 |
197 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 176 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
198 ;; end of user configuration variables | 177 ;; end of user configuration variables |
199 | 178 |
200 | 179 |
201 (defconst elp-version "2.32" | 180 (defconst elp-version "2.37" |
202 "ELP version number.") | 181 "ELP version number.") |
203 | 182 |
204 (defconst elp-help-address "tools-help@merlin.cnri.reston.va.us" | 183 (defconst elp-help-address "tools-help@python.org" |
205 "Address accepting submissions of bug reports and questions.") | 184 "Address accepting submissions of bug reports and questions.") |
206 | 185 |
207 (defvar elp-results-buffer "*ELP Profiling Results*" | 186 (defvar elp-results-buffer "*ELP Profiling Results*" |
208 "Buffer name for outputting profiling results.") | 187 "Buffer name for outputting profiling results.") |
209 | 188 |
224 ;;;###autoload | 203 ;;;###autoload |
225 (defun elp-instrument-function (funsym) | 204 (defun elp-instrument-function (funsym) |
226 "Instrument FUNSYM for profiling. | 205 "Instrument FUNSYM for profiling. |
227 FUNSYM must be a symbol of a defined function." | 206 FUNSYM must be a symbol of a defined function." |
228 (interactive "aFunction to instrument: ") | 207 (interactive "aFunction to instrument: ") |
229 ;; raise an error if the function is already instrumented | 208 ;; restore the function. this is necessary to avoid infinite |
230 (and (get funsym elp-timer-info-property) | 209 ;; recursion of already instrumented functions (i.e. elp-wrapper |
231 (error "Symbol `%s' is already instrumented for profiling." funsym)) | 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) | |
232 (let* ((funguts (symbol-function funsym)) | 217 (let* ((funguts (symbol-function funsym)) |
233 (infovec (vector 0 0 funguts)) | 218 (infovec (vector 0 0 funguts)) |
234 (newguts '(lambda (&rest args)))) | 219 (newguts '(lambda (&rest args)))) |
235 ;; we cannot profile macros | 220 ;; we cannot profile macros |
236 (and (eq (car-safe funguts) 'macro) | 221 (and (eq (car-safe funguts) 'macro) |
237 (error "ELP cannot profile macro %s" funsym)) | 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)) | |
238 ;; put rest of newguts together | 232 ;; put rest of newguts together |
239 (if (commandp funsym) | 233 (if (commandp funsym) |
240 (setq newguts (append newguts '((interactive))))) | 234 (setq newguts (append newguts '((interactive))))) |
241 (setq newguts (append newguts (list | 235 (setq newguts (append newguts (list |
242 (list 'elp-wrapper | 236 (list 'elp-wrapper |
298 ;; restore the original function definition, but if the function | 292 ;; restore the original function definition, but if the function |
299 ;; wasn't instrumented do nothing. we do this after the above | 293 ;; wasn't instrumented do nothing. we do this after the above |
300 ;; because its possible the function got un-instrumented due to | 294 ;; because its possible the function got un-instrumented due to |
301 ;; circumstances beyond our control. Also, check to make sure | 295 ;; circumstances beyond our control. Also, check to make sure |
302 ;; that the current function symbol points to elp-wrapper. If | 296 ;; that the current function symbol points to elp-wrapper. If |
303 ;; not, then the user probably did an eval-defun while the | 297 ;; not, then the user probably did an eval-defun, or loaded a |
304 ;; function was instrumented and we don't want to destroy the new | 298 ;; byte-compiled version, while the function was instrumented and |
305 ;; definition. | 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? | |
306 (and info | 301 (and info |
302 (not (compiled-function-p (symbol-function funsym))) | |
307 (assq 'elp-wrapper (symbol-function funsym)) | 303 (assq 'elp-wrapper (symbol-function funsym)) |
308 (fset funsym (aref info 2))))) | 304 (fset funsym (aref info 2))))) |
309 | 305 |
310 ;;;###autoload | 306 ;;;###autoload |
311 (defun elp-instrument-list (&optional list) | 307 (defun elp-instrument-list (&optional list) |
312 "Instrument for profiling, all functions in `elp-function-list'. | 308 "Instrument for profiling, all functions in `elp-function-list'. |
313 Use optional LIST if provided instead." | 309 Use optional LIST if provided instead." |
314 (interactive "PList of functions to instrument: ") | 310 (interactive "PList of functions to instrument: ") |
315 (let ((list (or list elp-function-list))) | 311 (let ((list (or list elp-function-list))) |
316 (mapcar | 312 (mapcar 'elp-instrument-function list))) |
317 (function | |
318 (lambda (funsym) | |
319 (condition-case nil | |
320 (elp-instrument-function funsym) | |
321 (error nil)))) | |
322 list))) | |
323 | 313 |
324 ;;;###autoload | 314 ;;;###autoload |
325 (defun elp-instrument-package (prefix) | 315 (defun elp-instrument-package (prefix) |
326 "Instrument for profiling, all functions which start with PREFIX. | 316 "Instrument for profiling, all functions which start with PREFIX. |
327 For example, to instrument all ELP functions, do the following: | 317 For example, to instrument all ELP functions, do the following: |
595 elp-reset-after-results | 585 elp-reset-after-results |
596 elp-sort-by-function)))) | 586 elp-sort-by-function)))) |
597 | 587 |
598 | 588 |
599 (provide 'elp) | 589 (provide 'elp) |
600 | |
601 ;; elp.el ends here | 590 ;; elp.el ends here |