Mercurial > emacs
comparison lisp/emacs-lisp/elp.el @ 10234:170c4c188d4f
(elp-pack-number): New function.
(elp-output-results): Use elp-pack-number to truncate time strings,
watching out for very small or very large numbers.
(elp-unset-master): Make it an interactive command.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sat, 24 Dec 1994 04:27:01 +0000 |
parents | ebbea7d79174 |
children | 525b67bc4f17 |
comparison
equal
deleted
inserted
replaced
10233:100a10bb4d47 | 10234:170c4c188d4f |
---|---|
1 ;;; elp.el --- Emacs Lisp Profiler | 1 ;;; elp.el --- Emacs Lisp Profiler |
2 | 2 |
3 ;; Copyright (C) 1994 Barry A. Warsaw | |
3 ;; Copyright (C) 1994 Free Software Foundation, Inc. | 4 ;; Copyright (C) 1994 Free Software Foundation, Inc. |
4 | 5 |
5 ;; Author: 1994 Barry A. Warsaw <bwarsaw@cnri.reston.va.us> | 6 ;; Author: 1994 Barry A. Warsaw <bwarsaw@cnri.reston.va.us> |
6 ;; Maintainer: tools-help@anthem.nlm.nih.gov | 7 ;; Maintainer: tools-help@anthem.nlm.nih.gov |
7 ;; Created: 26-Feb-1994 | 8 ;; Created: 26-Feb-1994 |
8 ;; Version: 2.18 | 9 ;; Version: 2.22 |
9 ;; Last Modified: 1994/09/14 14:00:09 | 10 ;; Last Modified: 1994/12/23 17:46:21 |
10 ;; Keywords: Emacs Lisp Profile Timing | 11 ;; Keywords: Emacs Lisp Profile Timing |
11 | 12 |
12 ;; This file is part of GNU Emacs. | 13 ;; This file is part of GNU Emacs. |
13 | 14 |
14 ;; GNU Emacs is free software; you can redistribute it and/or modify | 15 ;; GNU Emacs is free software; you can redistribute it and/or modify |
30 ;; This program is based on the only two existing Emacs Lisp profilers | 31 ;; This program is based on the only two existing Emacs Lisp profilers |
31 ;; that I'm aware of, Boaz Ben-Zvi's profile.el, and Root Boy Jim's | 32 ;; that I'm aware of, Boaz Ben-Zvi's profile.el, and Root Boy Jim's |
32 ;; profiler.el. Both were written for Emacs 18 and both were pretty | 33 ;; profiler.el. Both were written for Emacs 18 and both were pretty |
33 ;; good first shots at profiling, but I found that they didn't provide | 34 ;; good first shots at profiling, but I found that they didn't provide |
34 ;; the functionality or interface that I wanted. So I wrote this. | 35 ;; the functionality or interface that I wanted. So I wrote this. |
35 ;; I've tested elp in Lucid Emacs 19.9 and Emacs 19.22. There's no | 36 ;; I've tested elp in both Emacs 19's. There's no point in even |
36 ;; point in even trying to make this work with Emacs 18. | 37 ;; trying to make this work with Emacs 18. |
37 | 38 |
38 ;; Unlike previous profilers, elp uses Emacs 19's built-in function | 39 ;; Unlike previous profilers, elp uses Emacs 19's built-in function |
39 ;; current-time to return interval times. This obviates the need for | 40 ;; current-time to return interval times. This obviates the need for |
40 ;; both an external C program and Emacs processes to communicate with | 41 ;; both an external C program and Emacs processes to communicate with |
41 ;; such a program, and thus simplifies the package as a whole. One | 42 ;; such a program, and thus simplifies the package as a whole. One |
52 ;; give you a good feel for the relative amount of work spent in the | 53 ;; give you a good feel for the relative amount of work spent in the |
53 ;; various lisp routines you are profiling. Note further that times | 54 ;; various lisp routines you are profiling. Note further that times |
54 ;; are calculated using wall-clock time, so other system load will | 55 ;; are calculated using wall-clock time, so other system load will |
55 ;; affect accuracy too. | 56 ;; affect accuracy too. |
56 | 57 |
57 ;; There are only 3 variables you can change to customize behavior of | 58 ;; Here is a list of variable you can use to customize elp: |
58 ;; elp. See below for their description. | 59 ;; elp-function-list |
60 ;; elp-reset-after-results | |
61 ;; elp-sort-by-function | |
62 ;; elp-report-limit | |
59 ;; | 63 ;; |
60 ;; Here is a list of the interactive commands you can use: | 64 ;; Here is a list of the interactive commands you can use: |
61 ;; elp-instrument-function | 65 ;; elp-instrument-function |
62 ;; elp-restore-function | 66 ;; elp-restore-function |
63 ;; elp-instrument-list | 67 ;; elp-instrument-list |
65 ;; elp-instrument-package | 69 ;; elp-instrument-package |
66 ;; elp-restore-all | 70 ;; elp-restore-all |
67 ;; elp-reset-function | 71 ;; elp-reset-function |
68 ;; elp-reset-list | 72 ;; elp-reset-list |
69 ;; elp-reset-all | 73 ;; elp-reset-all |
74 ;; elp-set-master | |
75 ;; elp-unset-master | |
70 ;; elp-results | 76 ;; elp-results |
71 ;; elp-submit-bug-report | 77 ;; elp-submit-bug-report |
72 ;; | 78 ;; |
73 ;; Here are some brief usage notes. If you want to profile a bunch of | 79 ;; Here are some brief usage notes. If you want to profile a bunch of |
74 ;; functions, set elp-function-list to the list of symbols, then call | 80 ;; functions, set elp-function-list to the list of symbols, then call |
75 ;; elp-instrument-list. This hacks the functions so that profiling | 81 ;; elp-instrument-list. This hacks the functions so that profiling |
76 ;; information is recorded whenever they are called. To print out the | 82 ;; information is recorded whenever they are called. To print out the |
77 ;; current results, use elp-results. With elp-reset-after-results set | 83 ;; current results, use elp-results. With elp-reset-after-results set |
78 ;; to non-nil, profiling information will be reset whenever the | 84 ;; to non-nil, profiling information will be reset whenever the |
79 ;; results are displayed. You can also reset all profiling info at any | 85 ;; results are displayed. You can also reset all profiling info at |
80 ;; time with elp-reset-all. | 86 ;; any time with elp-reset-all. |
81 ;; | 87 ;; |
82 ;; You can also instrument all functions in a package, provided that | 88 ;; You can also instrument all functions in a package, provided that |
83 ;; the package follows the GNU coding standard of a common textural | 89 ;; the package follows the GNU coding standard of a common textural |
84 ;; prefix. elp-instrument-package does this. | 90 ;; prefix. Use the elp-instrument-package command for this. |
85 ;; | 91 ;; |
86 ;; If you want to sort the results, set elp-sort-by-function to some | 92 ;; If you want to sort the results, set elp-sort-by-function to some |
87 ;; predicate function. The three most obvious choices are predefined: | 93 ;; predicate function. The three most obvious choices are predefined: |
88 ;; elp-sort-by-call-count, elp-sort-by-average-time, and | 94 ;; elp-sort-by-call-count, elp-sort-by-average-time, and |
89 ;; elp-sort-by-total-time. Also, you can prune from the output | 95 ;; elp-sort-by-total-time. Also, you can prune from the output |
90 ;; display, all functions that have been called fewer than a given | 96 ;; display, all functions that have been called fewer than a given |
91 ;; number of times by setting elp-report-limit to that number. | 97 ;; number of times by setting elp-report-limit to that number. |
92 ;; | 98 ;; |
93 ;; Elp can instrument byte-compiled functions just as easily as | 99 ;; Elp can instrument byte-compiled functions just as easily as |
94 ;; interpreted functions, but it cannot instrument macros. However, | 100 ;; interpreted functions, but it cannot instrument macros. However, |
95 ;; when you redefine a function (e.g. with eval-defun), you'll need | 101 ;; when you redefine a function (e.g. with eval-defun), you'll need to |
96 ;; to re-instrument it with elp-instrument-function. Re-instrumenting | 102 ;; re-instrument it with elp-instrument-function. Re-instrumenting |
97 ;; resets profiling information for that function. Elp can also | 103 ;; resets profiling information for that function. Elp can also |
98 ;; handle interactive functions (i.e. commands), but of course any | 104 ;; handle interactive functions (i.e. commands), but of course any |
99 ;; time spent idling for user prompts will show up in the timing | 105 ;; time spent idling for user prompts will show up in the timing |
100 ;; results. | 106 ;; results. |
101 ;; | 107 ;; |
106 ;; (defun foo () (do-something-time-intensive)) | 112 ;; (defun foo () (do-something-time-intensive)) |
107 ;; (defun bar () (foo)) | 113 ;; (defun bar () (foo)) |
108 ;; (defun baz () (bar) (foo)) | 114 ;; (defun baz () (bar) (foo)) |
109 ;; | 115 ;; |
110 ;; and you want to find out the amount of time spent in bar and foo, | 116 ;; and you want to find out the amount of time spent in bar and foo, |
111 ;; but only during execution of bar, make bar the master and the call | 117 ;; but only during execution of bar, make bar the master. The call of |
112 ;; of foo from baz will not add to foo's total timing sums. Use | 118 ;; foo from baz will not add to foo's total timing sums. Use |
113 ;; elp-set-master and elp-unset-master to utilize this feature. Only | 119 ;; elp-set-master and elp-unset-master to utilize this feature. Only |
114 ;; one master function can be used at a time. | 120 ;; one master function can be used at a time. |
115 | 121 |
116 ;; You can restore any function's original function definition with | 122 ;; You can restore any function's original function definition with |
117 ;; elp-restore-function. The other instrument, restore, and reset | 123 ;; elp-restore-function. The other instrument, restore, and reset |
118 ;; functions are provided for symmetry. | 124 ;; functions are provided for symmetry. |
125 | |
126 ;; LCD Archive Entry: | |
127 ;; elp|Barry A. Warsaw|tools-help@anthem.nlm.nih.gov| | |
128 ;; Emacs Lisp Profiler| | |
129 ;; 1994/12/23 17:46:21|2.22|~/misc/elp.el.Z| | |
119 | 130 |
120 ;;; Code: | 131 ;;; Code: |
121 | 132 |
122 | 133 |
123 ;; start user configuration variables | 134 ;; start user configuration variables |
154 | 165 |
155 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | 166 ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
156 ;; end user configuration variables | 167 ;; end user configuration variables |
157 | 168 |
158 | 169 |
159 (defconst elp-version "2.18" | 170 (defconst elp-version "2.22" |
160 "ELP version number.") | 171 "ELP version number.") |
161 | 172 |
162 (defconst elp-help-address "tools-help@anthem.nlm.nih.gov" | 173 (defconst elp-help-address "tools-help@anthem.nlm.nih.gov" |
163 "Address accepting submissions of bug reports and questions.") | 174 "Address accepting submissions of bug reports and questions.") |
164 | 175 |
334 (or (memq funsym elp-all-instrumented-list) | 345 (or (memq funsym elp-all-instrumented-list) |
335 (elp-instrument-function funsym))) | 346 (elp-instrument-function funsym))) |
336 | 347 |
337 (defun elp-unset-master () | 348 (defun elp-unset-master () |
338 "Unsets the master function." | 349 "Unsets the master function." |
350 (interactive) | |
339 ;; when there's no master function, recording is turned on by default. | 351 ;; when there's no master function, recording is turned on by default. |
340 (setq elp-master nil | 352 (setq elp-master nil |
341 elp-record-p t)) | 353 elp-record-p t)) |
342 | 354 |
343 | 355 |
406 | 418 |
407 (defun elp-sort-by-average-time (vec1 vec2) | 419 (defun elp-sort-by-average-time (vec1 vec2) |
408 ;; sort by highest average time spent in function. See `sort'. | 420 ;; sort by highest average time spent in function. See `sort'. |
409 (>= (aref vec1 2) (aref vec2 2))) | 421 (>= (aref vec1 2) (aref vec2 2))) |
410 | 422 |
423 (defsubst elp-pack-number (number width) | |
424 ;; pack the NUMBER string into WIDTH characters, watching out for | |
425 ;; very small or large numbers | |
426 (if (<= (length number) width) | |
427 number | |
428 ;; check for very large or small numbers | |
429 (if (string-match "^\\(.*\\)\\(e[+-].*\\)$" number) | |
430 (concat (substring | |
431 (substring number (match-beginning 1) (match-end 1)) | |
432 0 | |
433 (- width (match-end 2) (- (match-beginning 2)) 3)) | |
434 "..." | |
435 (substring number (match-beginning 2) (match-end 2))) | |
436 (concat (substring number 0 width))))) | |
437 | |
411 (defun elp-output-result (resultvec) | 438 (defun elp-output-result (resultvec) |
412 ;; output the RESULTVEC into the results buffer. RESULTVEC is a 4 or | 439 ;; output the RESULTVEC into the results buffer. RESULTVEC is a 4 or |
413 ;; more element vector where aref 0 is the call count, aref 1 is the | 440 ;; more element vector where aref 0 is the call count, aref 1 is the |
414 ;; total time spent in the function, aref 2 is the average time | 441 ;; total time spent in the function, aref 2 is the average time |
415 ;; spent in the function, and aref 3 is the symbol's string | 442 ;; spent in the function, and aref 3 is the symbol's string |
430 (insert symname) | 457 (insert symname) |
431 (insert-char 32 (+ elp-field-len (- (length symname)) 2)) | 458 (insert-char 32 (+ elp-field-len (- (length symname)) 2)) |
432 ;; print stuff out, formatting it nicely | 459 ;; print stuff out, formatting it nicely |
433 (insert callcnt) | 460 (insert callcnt) |
434 (insert-char 32 (+ elp-cc-len (- (length callcnt)) 2)) | 461 (insert-char 32 (+ elp-cc-len (- (length callcnt)) 2)) |
435 (if (> (length totaltime) elp-et-len) | 462 (let ((ttstr (elp-pack-number totaltime elp-et-len)) |
436 (insert (substring totaltime 0 elp-et-len) " ") | 463 (atstr (elp-pack-number avetime elp-at-len))) |
437 (insert totaltime) | 464 (insert ttstr) |
438 (insert-char 32 (+ elp-et-len (- (length totaltime)) 2))) | 465 (insert-char 32 (+ elp-et-len (- (length ttstr)) 2)) |
439 (if (> (length avetime) elp-at-len) | 466 (insert atstr)) |
440 (insert (substring avetime 0 elp-at-len)) | |
441 (insert avetime)) | |
442 (insert "\n")))) | 467 (insert "\n")))) |
443 | 468 |
444 ;;;###autoload | 469 ;;;###autoload |
445 (defun elp-results () | 470 (defun elp-results () |
446 "Display current profiling results. | 471 "Display current profiling results. |
526 elp-reset-after-results | 551 elp-reset-after-results |
527 elp-sort-by-function)))) | 552 elp-sort-by-function)))) |
528 | 553 |
529 | 554 |
530 (provide 'elp) | 555 (provide 'elp) |
531 | |
532 ;; elp.el ends here | 556 ;; elp.el ends here |