Mercurial > emacs
comparison lisp/emacs-lisp/elp.el @ 41177:830a17080380
(elp-not-profilable): New var.
(elp-not-profilable-p): New function.
(elp-instrument-function): Use it. Use backquotes and push.
author | Stefan Monnier <monnier@iro.umontreal.ca> |
---|---|
date | Sat, 17 Nov 2001 00:58:21 +0000 |
parents | 67b464da13ec |
children | 0f4506820432 |
comparison
equal
deleted
inserted
replaced
41176:2d63191afacd | 41177:830a17080380 |
---|---|
201 "Controls whether functions should record times or not. | 201 "Controls whether functions should record times or not. |
202 This variable is set by the master function.") | 202 This variable is set by the master function.") |
203 | 203 |
204 (defvar elp-master nil | 204 (defvar elp-master nil |
205 "Master function symbol.") | 205 "Master function symbol.") |
206 | |
207 (defvar elp-not-profilable | |
208 '(elp-wrapper elp-elapsed-time error call-interactively apply current-time interactive-p) | |
209 "List of functions that cannot be profiled. | |
210 Those functions are used internally by the profiling code and profiling | |
211 them would thus lead to infinite recursion.") | |
212 | |
213 (defun elp-not-profilable-p (fun) | |
214 (or (memq fun elp-not-profilable) | |
215 (keymapp fun) | |
216 (condition-case nil | |
217 (when (subrp (symbol-function fun)) | |
218 (eq 'unevalled (cdr (subr-arity (symbol-function fun))))) | |
219 (error nil)))) | |
206 | 220 |
207 | 221 |
208 ;;;###autoload | 222 ;;;###autoload |
209 (defun elp-instrument-function (funsym) | 223 (defun elp-instrument-function (funsym) |
210 "Instrument FUNSYM for profiling. | 224 "Instrument FUNSYM for profiling. |
220 ;; definition. | 234 ;; definition. |
221 (elp-restore-function funsym) | 235 (elp-restore-function funsym) |
222 (let* ((funguts (symbol-function funsym)) | 236 (let* ((funguts (symbol-function funsym)) |
223 (infovec (vector 0 0 funguts)) | 237 (infovec (vector 0 0 funguts)) |
224 (newguts '(lambda (&rest args)))) | 238 (newguts '(lambda (&rest args)))) |
239 ;; We cannot profile functions used internally during profiling. | |
240 (when (elp-not-profilable-p funsym) | |
241 (error "ELP cannot profile the function: %s" funsym)) | |
225 ;; we cannot profile macros | 242 ;; we cannot profile macros |
226 (and (eq (car-safe funguts) 'macro) | 243 (and (eq (car-safe funguts) 'macro) |
227 (error "ELP cannot profile macro: %s" funsym)) | 244 (error "ELP cannot profile macro: %s" funsym)) |
228 ;; TBD: at some point it might be better to load the autoloaded | 245 ;; TBD: at some point it might be better to load the autoloaded |
229 ;; function instead of throwing an error. if we do this, then we | 246 ;; function instead of throwing an error. if we do this, then we |
235 (and (eq (car-safe funguts) 'autoload) | 252 (and (eq (car-safe funguts) 'autoload) |
236 (error "ELP cannot profile autoloaded function: %s" funsym)) | 253 (error "ELP cannot profile autoloaded function: %s" funsym)) |
237 ;; put rest of newguts together | 254 ;; put rest of newguts together |
238 (if (commandp funsym) | 255 (if (commandp funsym) |
239 (setq newguts (append newguts '((interactive))))) | 256 (setq newguts (append newguts '((interactive))))) |
240 (setq newguts (append newguts (list | 257 (setq newguts (append newguts `((elp-wrapper |
241 (list 'elp-wrapper | 258 (quote ,funsym) |
242 (list 'quote funsym) | 259 ,(when (commandp funsym) |
243 (list 'and | 260 '(interactive-p)) |
244 '(interactive-p) | 261 args)))) |
245 (not (not (commandp funsym)))) | |
246 'args)))) | |
247 ;; to record profiling times, we set the symbol's function | 262 ;; to record profiling times, we set the symbol's function |
248 ;; definition so that it runs the elp-wrapper function with the | 263 ;; definition so that it runs the elp-wrapper function with the |
249 ;; function symbol as an argument. We place the old function | 264 ;; function symbol as an argument. We place the old function |
250 ;; definition on the info vector. | 265 ;; definition on the info vector. |
251 ;; | 266 ;; |
277 (fset funsym newguts) | 292 (fset funsym newguts) |
278 (put funsym 'ad-advice-info advice-info)) | 293 (put funsym 'ad-advice-info advice-info)) |
279 (fset funsym newguts))) | 294 (fset funsym newguts))) |
280 | 295 |
281 ;; add this function to the instrumentation list | 296 ;; add this function to the instrumentation list |
282 (or (memq funsym elp-all-instrumented-list) | 297 (unless (memq funsym elp-all-instrumented-list) |
283 (setq elp-all-instrumented-list | 298 (push funsym elp-all-instrumented-list)))) |
284 (cons funsym elp-all-instrumented-list))))) | |
285 | 299 |
286 (defun elp-restore-function (funsym) | 300 (defun elp-restore-function (funsym) |
287 "Restore an instrumented function to its original definition. | 301 "Restore an instrumented function to its original definition. |
288 Argument FUNSYM is the symbol of a defined function." | 302 Argument FUNSYM is the symbol of a defined function." |
289 (interactive "aFunction to restore: ") | 303 (interactive "aFunction to restore: ") |
335 (elp-instrument-list | 349 (elp-instrument-list |
336 (mapcar | 350 (mapcar |
337 'intern | 351 'intern |
338 (all-completions | 352 (all-completions |
339 prefix obarray | 353 prefix obarray |
340 (function | 354 (lambda (sym) |
341 (lambda (sym) | 355 (and (fboundp sym) |
342 (and (fboundp sym) | 356 (not (or (memq (car-safe (symbol-function sym)) '(autoload macro)) |
343 (not (memq (car-safe (symbol-function sym)) '(autoload macro)))) | 357 (elp-not-profilable-p sym))))))))) |
344 )) | |
345 )))) | |
346 | 358 |
347 (defun elp-restore-list (&optional list) | 359 (defun elp-restore-list (&optional list) |
348 "Restore the original definitions for all functions in `elp-function-list'. | 360 "Restore the original definitions for all functions in `elp-function-list'. |
349 Use optional LIST if provided instead." | 361 Use optional LIST if provided instead." |
350 (interactive "PList of functions to restore: ") | 362 (interactive "PList of functions to restore: ") |