comparison lisp/emacs-lisp/profile.el @ 14791:7d2e0f0d9bf7

(profile-convert-byte-code): New function. (profile-a-function): Use profile-convert-byte-code.
author Richard M. Stallman <rms@gnu.org>
date Fri, 08 Mar 1996 17:44:00 +0000
parents 83f275dcd93a
children 8895613b61dd
comparison
equal deleted inserted replaced
14790:70553c545976 14791:7d2e0f0d9bf7
216 (if (< (cdr accum) profile-million) nil 216 (if (< (cdr accum) profile-million) nil
217 (setcar accum (1+ (car accum))) 217 (setcar accum (1+ (car accum)))
218 (setcdr accum (- (cdr accum) profile-million))) 218 (setcdr accum (- (cdr accum) profile-million)))
219 ))) 219 )))
220 220
221 (defun profile-convert-byte-code (function)
222 (let ((defn (symbol-function function)))
223 (if (byte-code-function-p defn)
224 ;; It is a compiled code object.
225 (let* ((contents (append defn nil))
226 (body
227 (list (list 'byte-code (nth 1 contents)
228 (nth 2 contents) (nth 3 contents)))))
229 (if (nthcdr 5 contents)
230 (setq body (cons (list 'interactive (nth 5 contents)) body)))
231 (if (nth 4 contents)
232 ;; Use `documentation' here, to get the actual string,
233 ;; in case the compiled function has a reference
234 ;; to the .elc file.
235 (setq body (cons (documentation function) body)))
236 (fset function (cons 'lambda (cons (car contents) body)))))))
237
221 (defun profile-a-function (fun) 238 (defun profile-a-function (fun)
222 "Profile the function FUN." 239 "Profile the function FUN."
223 (interactive "aFunction to profile: ") 240 (interactive "aFunction to profile: ")
241 (profile-convert-byte-code fun)
224 (let ((def (symbol-function fun)) (funlen (length (symbol-name fun)))) 242 (let ((def (symbol-function fun)) (funlen (length (symbol-name fun))))
225 (if (eq (car def) 'lambda) nil 243 (if (eq (car def) 'lambda) nil
226 (error "To profile: %s must be a user-defined function" fun)) 244 (error "To profile: %s must be a user-defined function" fun))
227 (setq profile-time-list ; add a new entry 245 (setq profile-time-list ; add a new entry
228 (cons (cons fun (cons 0 0)) profile-time-list)) 246 (cons (cons fun (cons 0 0)) profile-time-list))