5.3 Documentation addenda
monitor function-or-method monitor-functions function-list
;;; The following example shows how to monitor a method. For ;;; examples of monitoring functions, see the section "Using the ;;; Performance Monitor." This example assumes that the CLOS module ;;; has been loaded. ;; Invoke the production mode of the Compiler. > (proclaim '(optimize (speed 3) (safety 1) (compilation-speed 0))) T ;; Define a generic function PLUS. > (defgeneric plus (x y)) #<Standard-Generic-Function PLUS (0)> ;; Define a POLYNOMIAL class that PLUS can operate on. > (defclass polynomial () ;; A polynomial has just a vector of coefficients. ((coefficients :initarg :coefficients :accessor poly-coeff :initform #(0)))) #<Standard-Class POLYNOMIAL> ;; Define a PLUS method for polynomials. > (defmethod plus ((x polynomial) (y polynomial)) (let* ((x-coef (poly-coeff x)) (y-coef (poly-coeff y)) (maxlen (max (length x-coef) (length y-coef))) (minlen (min (length x-coef) (length y-coef))) (result-coefficients (make-array maxlen))) (unless (= maxlen (length x-coef)) ;; Make sure x is longer. (rotatef x-coef y-coef)) (dotimes (i maxlen) (setf (aref result-coefficients i) (if (>= i minlen) (aref x-coef i) (+ (aref y-coef i) (aref x-coef i))))) (make-instance 'polynomial :coefficients result- coefficients))) #<Standard-Method PLUS (POLYNOMIAL POLYNOMIAL)> ;; Compile the PLUS method for polynomials. > (compile '(method plus (polynomial polynomial))) (METHOD PLUS (POLYNOMIAL POLYNOMIAL)) ;; Make the method eligible for monitoring. > (monitor (method plus (polynomial polynomial))) ((METHOD PLUS (POLYNOMIAL POLYNOMIAL))) ;; Enable the monitoring procedure. > (start-monitoring) T > (plus (make-instance 'polynomial :coefficients #(3 4 5 2 0 8 7)) (make-instance 'polynomial :coefficients #(3 4 5 2 0 7))) #<Polynomial #XDD6383> ;; Disable monitoring. > (stop-monitoring) NIL ;; Show the results of monitoring. > (print-monitor '(method plus (polynomial polynomial))) Monitor information for (METHOD PLUS (POLYNOMIAL POLYNOMIAL)) Number of calls : 1 Inclusive Time (secs) : 0.010 Exclusive Time (secs) : 0.010 Inclusive Consing (words) : 290 Exclusive Consing (words) : 290 NIL ;; Make the method ineligible for monitoring. > (unmonitor (method plus (polynomial polynomial))) ((METHOD PLUS (POLYNOMIAL POLYNOMIAL)))
Generated with Harlequin WebMaker