Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!samsung!spool.mu.edu!news.cs.indiana.edu!purdue!yeh From: yeh@cs.purdue.EDU (Wei Jen Yeh) Newsgroups: comp.lang.lisp Subject: Re: monitoring functions Summary: Solution found Keywords: modify code at runtime Message-ID: <14140@medusa.cs.purdue.edu> Date: 1 Apr 91 23:27:25 GMT References: <14131@medusa.cs.purdue.edu> <1991Apr1.181743.18493@Think.COM> Sender: news@cs.purdue.EDU Organization: Department of Computer Science, Purdue University Lines: 47 Thanks to Barry for his solutions. I enclosed his solutions with a minor modification to make the modified function return the same value as the old one does. (It may not work for functions returning multiple values.) My thanks also go to others for pointing out the "advice" function (which akcl does not have), and Mark Kantrowitz for providing info on a metering package. (defun monitor_1fun (fname) (if (fboundp fname) (if (get fname 'monitored) (error "Function ~A is already being monitored." fname) (let ((old-function (symbol-function fname))) (setf (get fname 'monitored) old-function) (setf (symbol-function fname) #'(lambda (&rest args) (prog2 (start_bench fname) (apply old-function args) (end_bench fname)))) (push fname *monitor_list*) *monitor_list*)) (error "Function ~A is not defined." fname))) (defun unmonitor_1fun (fname) (let ((old-function (get fname 'monitored))) (if old-function (progn (setf (symbol-function fname) old-function) (remprop fname 'monitored) (setq *monitor_list* (delete fname *monitor_list*))) (error "Function ~A is not being monitored" fname)))) > -- > Barry Margolin, Thinking Machines Corp. > > barmar@think.com Wei Jen Yeh yeh@cs.purdue.edu Department of Computer Science Purdue University West Lafayette, Indiana -- Wei Jen Yeh yeh@cs.purdue.edu Department of Computer Science Purdue University West Lafayette, Indiana