; FP interpreter/compiler ; Copyright (c) 1982 Scott B. Baden ; Berkeley, California ; Dynamics Statistics by Dorab Patel (UCLA) ; ; Copyright (c) 1982 Regents of the University of California. ; All rights reserved. The Berkeley software License Agreement ; specifies the terms and conditions for redistribution. ; (setq SCCS-fpMeasures.l "@(#)fpMeasures.l 5.1 (Berkeley) 5/31/85") ; Initialize and update the 'Measures' plist with ; the run-time measurement data ; ; Special symbol 'TracedFns' also manipulated ; It contains the list of currently traced user defined functions. ; The attributes for each functional form and function are: ; times: the total number of times it has been called ; size: the sum of the top-level sizes of the arguments given to it ; funargno: the number of functional arguments to this form ; (in general this is only for construct) ; funargtype: the type and total number of functions of that type ; supplied to this functional form. ; This is an alist ((fntype.times) ...) (include specials.l) (declare (special statport dummy)) (declare (localf InitSize InitFunArgTyp InitFunArgNo trace1 extractName goodStats untrace1 SendMeasures)) ; The following functions are global. i.e. used externally ; startDynStats clrDynStats IncrTimes IncrSize ; IncrFunArgNo IncrFunArgTyp size Trace ; PrintMeasures IncrUDF Untrace stopDynStats ; This is called by the main routine to initialize all the ; measurement stuff (defun clrDynStats nil (dontLoseStats) (initStats)) (defun dontLoseStats nil (cond ((goodStats) ; check to see if there are stats to report (patom "output dynamic statistics? ") (let ((response (car (explodec (ratom))))) (If ptport then (msg (P ptport) response)) (Tyi) (cond ((eq response 'y) (patom "File: ") (let ((statFile (cond ((eq (tyipeek) #.CR) nil) (t (let ((fl (ratom))) (If ptport then (msg (P ptport) fl)) fl))))) (Tyi) (PrintMeasures statFile)))))))) (defun initStats nil (InitMeasures `(,@#.dyadFns ,@#.miscFns ,@#.multiAdicFns ,@#.libFns ,@#.funcForms)) (InitSize #.multiAdicFns) (InitSize #.funcForms) (InitFunArgNo '(constr$fp)) ; included here even though it's not a functional form (InitFunArgTyp '(select$fp)) (InitFunArgTyp #.funcForms)) ; Makes the symbol 'Measures' have the property indicators ; corresponding to the function names in 'ListOfFns' and the values ; to be ((times.0)). (defun InitMeasures (ListOfFns) (setplist 'Measures (apply 'append (mapcar '(lambda (x) (list x (list (cons 'times 0)))) ListOfFns)))) (defun goodStats nil (do ((M (plist 'Measures) (cddr M))) ((null M) nil) (cond ((not (zerop (cdr (assoc 'times (cadr M))))) (return t))))) ; This is used to stop the collection of dynamic statistics ; needs to untrace functions if they still are. i.e. do the traced-expr stuff ; note that rds which calls this, also calls PrintMeasures, though ; this may change. (defun stopDynStats nil (cond (TracedFns ; if any fns still being traced (Untrace TracedFns))) ; untrace them (setq DynTraceFlg nil)) (defun extractName (fnName) (patom (implode (reverse (cons "'" (cdddr (reverse (explodec (concat "'" fnName))))))))) ; this is the function called by the system function trace to ; enable the tracing of the User Defined Functions specified ; NOTE: successive calls will add to the UDFs to be traced. (defun Trace (arglist) (setq traceport poport) (mapc '(lambda (x) (cond ((memq x TracedFns) ; if already traced (setq arglist (delq x arglist 1)) ; delete from arglist (extractName x) ; and tell the user (patom " is already being traced") (terpr)))) arglist) (mapc 'trace1 arglist)) ; set up traced-expr stuff ; This is called by the system function untrace to disable the tracing ; of user defined functions. ; This removes the named user defined function from the list ; of traced functions (defun Untrace (arglist) (mapc '(lambda (x) (cond ((memq x TracedFns) ; if being traced (setq TracedFns (delq x TracedFns)) ; remove (untrace1 x)) ; restore stuff (t (extractName x) ; else complain (patom " is not being traced") (terpr)))) arglist)) ; This is called by Trace on each individual function that is to ; be traced. It does the manipulation of the traced-expr property (defun trace1 (name) ; actually you should check for getd name returning something decent (let ((zExpr (getd name))) (cond ((null zExpr) (patom "Can't trace the undefined fn ") (extractName name) (patom ".") (terpr)) (t (putprop name zExpr 'traced-expr) ; put fn def on traced-expr (setq TracedFns (append1 TracedFns name)) ; update TracedFns (InitUDF name) ; set up the measurement stuff (putd name ; make a new function def `(lambda (x) (prog (tmp) (setq level (1+ level)) ; increment level counter (printLevel) (patom " >Enter> " traceport) (patom (extName ',name) traceport) (patom " [" traceport) (d_isplay x traceport) (patom "]" traceport) (terpri traceport) ; now call the actual function (setq tmp (funcall (get ',name 'traced-expr) x)) (printLevel) (patom " " port)) ((atom obj) (patom obj port)) ((listp obj) (patom "<" port) (maplist '(lambda (x) (d_isplay (car x) port) (cond ((not (onep (length x))) (patom " " port)))) obj) (patom ">" port)))) (defun measAlph (al seq) (IncrFunArgTyp 'alpha$fp al) (IncrTimes 'alpha$fp) (IncrSize 'alpha$fp (size seq))) (defun measIns (ins seq) (IncrFunArgTyp 'insert$fp ins) (IncrTimes 'insert$fp) (IncrSize 'insert$fp (size seq))) (defun measTi (ains seq) (IncrFunArgTyp 'ti$fp ains) (IncrTimes 'ti$fp) (IncrSize 'ti$fp (size seq))) (defun measSel (sel seq) (IncrFunArgTyp 'select$fp sel) (IncrTimes 'select$fp) (IncrSize 'select$fp (size seq))) (defun measCons (cons seq) (IncrFunArgTyp 'constant$fp cons) (IncrTimes 'constant$fp) (IncrSize 'constant$fp (size seq))) (defun measCond (c1 c2 c3 seq) (IncrFunArgTyp 'condit$fp c1) (IncrFunArgTyp 'condit$fp c2) (IncrFunArgTyp 'condit$fp c3) (IncrTimes 'condit$fp) (IncrSize 'condit$fp (size seq))) (defun measWhile (w1 w2 seq) (IncrFunArgTyp 'while$fp w1) (IncrFunArgTyp 'while$fp w2) (IncrTimes 'while$fp) (IncrSize 'while$fp (size seq))) (defun measComp (cm1 cm2 seq) (IncrFunArgTyp 'compos$fp cm1) (IncrFunArgTyp 'compos$fp cm2) (IncrTimes 'compos$fp) (IncrSize 'compos$fp (size seq))) (defun measConstr (fns seq) (mapcar '(lambda (x) (IncrFunArgTyp 'constr$fp x)) fns) (IncrFunArgNo 'constr$fp (length fns)) (IncrTimes 'constr$fp) (IncrSize 'constr$fp (size seq))) ; get the corect name of the functional form (defmacro getFform (xx) `(implode (nreverse `(p f ,@(cdr (nreverse (explodec (cxr 0 ,xx))))))))