Mercurial > emacs
comparison lisp/emacs-lisp/profile.el @ 16375:2dacebab0fd4
Delete several \n\'s.
(profile-fix-fun): Delete an if whose test is never true.
Handle doc strings that are also the function value.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Wed, 02 Oct 1996 21:42:42 +0000 |
parents | 8895613b61dd |
children | 11218164bc54 |
comparison
equal
deleted
inserted
replaced
16374:b3b88a1ee6aa | 16375:2dacebab0fd4 |
---|---|
83 | 83 |
84 (defvar profile-timer-process nil "Process running the timer.") | 84 (defvar profile-timer-process nil "Process running the timer.") |
85 (defvar profile-time-list nil | 85 (defvar profile-time-list nil |
86 "List of cumulative calls and time for each profiled function.") | 86 "List of cumulative calls and time for each profiled function.") |
87 (defvar profile-init-list nil | 87 (defvar profile-init-list nil |
88 "List of entry time for each function. \n\ | 88 "List of entry time for each function. |
89 Both how many times invoked and real time of start.") | 89 Both how many times invoked and real time of start.") |
90 (defvar profile-max-fun-name 0 "Max length of name of any function profiled.") | 90 (defvar profile-max-fun-name 0 "Max length of name of any function profiled.") |
91 (defvar profile-temp-result- nil "Should NOT be used anywhere else.") | 91 (defvar profile-temp-result- nil "Should NOT be used anywhere else.") |
92 (defvar profile-time (cons 0 0) "Used to return result from a filter.") | 92 (defvar profile-time (cons 0 0) "Used to return result from a filter.") |
93 (defvar profile-buffer "*profile*" "Name of profile buffer.") | 93 (defvar profile-buffer "*profile*" "Name of profile buffer.") |
95 ;;; | 95 ;;; |
96 ;;; F U N C T I O N S | 96 ;;; F U N C T I O N S |
97 ;;; | 97 ;;; |
98 | 98 |
99 (defun profile-functions (&optional flist) | 99 (defun profile-functions (&optional flist) |
100 "Profile all the functions listed in `profile-functions-list'.\n\ | 100 "Profile all the functions listed in `profile-functions-list'. |
101 With argument FLIST, use the list FLIST instead." | 101 With argument FLIST, use the list FLIST instead." |
102 (interactive "P") | 102 (interactive "P") |
103 (if (null flist) (setq flist profile-functions-list)) | 103 (if (null flist) (setq flist profile-functions-list)) |
104 (mapcar 'profile-a-function flist)) | 104 (mapcar 'profile-a-function flist)) |
105 | 105 |
251 (cons (cons fun (cons 0 (cons 0 0))) profile-init-list)) | 251 (cons (cons fun (cons 0 (cons 0 0))) profile-init-list)) |
252 (if (< profile-max-fun-name funlen) (setq profile-max-fun-name funlen)) | 252 (if (< profile-max-fun-name funlen) (setq profile-max-fun-name funlen)) |
253 (fset fun (profile-fix-fun fun def)))) | 253 (fset fun (profile-fix-fun fun def)))) |
254 | 254 |
255 (defun profile-fix-fun (fun def) | 255 (defun profile-fix-fun (fun def) |
256 "Take function FUN and return it fixed for profiling.\n\ | 256 "Take function FUN and return it fixed for profiling. |
257 DEF is (symbol-function FUN)." | 257 DEF is (symbol-function FUN)." |
258 (let (prefix first second third (count 2) inter suffix) | 258 (let (prefix first second third (count 2) inter suffix) |
259 (if (< (length def) 3) nil ; nothing to see | 259 (if (< (length def) 3) |
260 nil ; nothing to see | |
260 (setq first (car def) second (car (cdr def)) | 261 (setq first (car def) second (car (cdr def)) |
261 third (car (nthcdr 2 def))) | 262 third (car (nthcdr 2 def))) |
262 (setq prefix (list first second)) | 263 (setq prefix (list first second)) |
263 (if (and (stringp third) (< (length def) 3)) nil ; nothing to see | 264 ;; Skip the doc string, if there is a string |
264 (if (not (stringp third)) (setq inter third) | 265 ;; which serves only as a doc string, |
265 (setq count 3 ; suffix to start after doc string | 266 ;; and put it in PREFIX. |
266 prefix (nconc prefix (list third)) | 267 (if (or (not (stringp third)) (not (nthcdr 3 def))) |
267 inter (car (nthcdr 3 def))) ; fourth sexp | 268 ;; Either no doc string, or it is also the function value. |
268 ) | 269 (setq inter third) |
269 (if (not (and (listp inter) | 270 ;; Skip the doc string, |
270 (eq (car inter) 'interactive))) nil | 271 (setq count 3 |
271 (setq prefix (nconc prefix (list inter))) | 272 prefix (nconc prefix (list third)) |
272 (setq count (1+ count))) ; skip this sexp for suffix | 273 inter (car (nthcdr 3 def)))) |
273 (setq suffix (nthcdr count def)) | 274 ;; Check for an interactive spec. |
274 (if (equal (car suffix) '(profile-get-time)) nil;; already set | 275 ;; If found, put it inu PREFIX and skip it. |
275 ;; prepare new function | 276 (if (not (and (listp inter) |
276 (nconc prefix | 277 (eq (car inter) 'interactive))) |
277 (list '(profile-get-time)) ; read time | 278 nil |
278 (list (list 'profile-start-function | 279 (setq prefix (nconc prefix (list inter))) |
279 (list 'quote fun))) | 280 (setq count (1+ count))) ; skip this sexp for suffix |
280 (list (list 'setq 'profile-temp-result- | 281 ;; Set SUFFIX to the function body forms. |
281 (nconc (list 'progn) suffix))) | 282 (setq suffix (nthcdr count def)) |
282 (list '(profile-get-time)) ; read time | 283 (if (equal (car suffix) '(profile-get-time)) |
283 (list (list 'profile-update-function | 284 nil |
284 (list 'quote fun))) | 285 ;; Prepare new function definition. |
285 (list 'profile-temp-result-) | 286 (nconc prefix |
286 )))))) | 287 (list '(profile-get-time)) ; read time |
288 (list (list 'profile-start-function | |
289 (list 'quote fun))) | |
290 (list (list 'setq 'profile-temp-result- | |
291 (nconc (list 'progn) suffix))) | |
292 (list '(profile-get-time)) ; read time | |
293 (list (list 'profile-update-function | |
294 (list 'quote fun))) | |
295 (list 'profile-temp-result-) | |
296 ))))) | |
287 | 297 |
288 (defun profile-restore-fun (fun) | 298 (defun profile-restore-fun (fun) |
289 "Restore profiled function FUN to its original state." | 299 "Restore profiled function FUN to its original state." |
290 (let ((def (symbol-function (car fun))) body index) | 300 (let ((def (symbol-function (car fun))) body index) |
291 ;; move index beyond header | 301 ;; move index beyond header |