(DEFINE-FILE-INFO READTABLE "INTERLISP" PACKAGE "INTERLISP") (FILECREATED "16-May-90 12:14:36" {DSK}local>lde>lispcore>sources>BRKDWN.;2 25376 changes to%: (VARS BRKDWNCOMS) previous date%: "23-Oct-86 21:37:08" {DSK}local>lde>lispcore>sources>BRKDWN.;1) (* ; " Copyright (c) 1982, 1983, 1984, 1986, 1990 by Venue & Xerox Corporation. All rights reserved. The following program was created in 1982 but has not been published within the meaning of the copyright law, is furnished under license, and may not be used, copied and/or disclosed except in accordance with the terms of said license. ") (PRETTYCOMPRINT BRKDWNCOMS) (RPAQQ BRKDWNCOMS [(DECLARE%: FIRST (ADDVARS (NOSWAPFNS BRKDWN2))) (FNS BREAKDOWN BRKDWNINIT BRKDWNSETUP BRKDWN1 BRKDWNFORM BRKDWNCOMPILE2 BRKDWNTIME BRKDWNCONSES BRKDWNBOXES BRKDWNFBOXES RESULTS BRKDWNRESULTS BRKDWNRESULTS1 BRKDWNRESULTS2 BRKDWNCLEAR) (DECLARE%: EVAL@COMPILE (MACROS BRKDWNMACRO BRKDWNINCA) (MACROS BRKDWNADDTOA BRKDWNDIFFA CPUTIME IBOXCOUNT FBOXCOUNT BRKDWNELT BRKDWNSETA BRKDWNARRAY)) [VARS (BRKDWNLENGTH 0) (BRKDWNCOMPFLG NIL) BRKDWNARGS BRKDWNTYPES (BRKDWNFLTFMT (NUMFORMATCODE '(FLOAT 7 3 NIL NIL 10] (VARS (BRKDWNTYPE 'TIME) (BRKDWNLABELS) (BRKDWNLST)) (GLOBALVARS BRKDWNARGS BRKDWNLABELS BRKDWNLENGTH BRKDWNLST BRKDWNTOTLST BDLST BDSINK BDPTR) (BLOCKS (NIL BRKDWNTIME BRKDWNCONSES BRKDWNBOXES (LINKFNS . T)) (BREAKDOWN BREAKDOWN BRKDWNSETUP BRKDWN1 BRKDWNFORM BRKDWNCOMPILE2 (GLOBALVARS NOSWAPFLG)) (BRKDWNRESULTS BRKDWNRESULTS BRKDWNRESULTS1 BRKDWNRESULTS2)) (DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA BREAKDOWN) (NLAML BRKDWNFBOXES BRKDWNBOXES BRKDWNCONSES BRKDWNTIME) (LAMA]) (DECLARE%: FIRST (ADDTOVAR NOSWAPFNS BRKDWN2) ) (DEFINEQ (BREAKDOWN (NLAMBDA FNS (* lmm "14-Aug-84 19:18") (SETQ FNS (NLAMBDA.ARGS FNS)) (BRKDWNINIT) (SETQ BRKDWNLST (SUBSET BRKDWNLST (FUNCTION (LAMBDA (X) (PROG ((DEF (GETD (CAR X)))) (* This enables both adding to and subtracting from the BREAKDOWN list.  If functions originally on BRKDWNLST are still broken, they are kept.  Then the new functions are added. The second alternative in the OR is for  functions with open-coded BRKDWN2.) (RETURN (AND (OR (AND (EXPRP DEF) (EQ (CAADDR DEF) 'BRKDWN2)) (AND DEF (EQP DEF (CADDDR X)))) (NOT (MEMB (CAR X) FNS))))))))) (COND (BRKDWNTYPE (* BRKDWN1 initializes BRKDWNLABELS and BRKDWNLENGTH and compiles a measuring  function, when necessary, for the measurement indicated by BRKDWNTYPE.  BRKDWNTYPE is initially set to TIME.) (BRKDWN1))) (CONSCOUNT 0) (BRKDWNCLEAR BDLST (ADD1 BRKDWNLENGTH)) (* BDLST is initialized to point to the first cell of an unboxed array and is  used for storing the last values of the statistics to be measured.  BDSINK is a dummy array for accumulating values not charged to any function.) (SETQ BDPTR BDSINK) (COND (FNS (PROG ((N 1)) (for X in FNS do (if (NUMBERP X) then (SETQ N X) NIL else (for X in (BREAK0 X T NIL 'BRKDWN2) do (if (LISTP X) then (PRINT X T T) else (* BRKDWNSETUP returns a list of the form  (PTR N) or (PTR N CODE DEF) which becomes an element of BRKDWNLST after adding  FN in front.) (SETQ BRKDWNLST (NCONC1 BRKDWNLST (CONS X (BRKDWNSETUP X (GETD X) (BRKDWNARRAY (ADD1 BRKDWNLENGTH )) N))))))))))) (MAPC BRKDWNLST (FUNCTION (LAMBDA (FNS) (BRKDWNCLEAR (CADR FNS) (ADD1 BRKDWNLENGTH))))) (* If a completely new BREAKDOWN was done, this isn't really necessary, but it  may have been just an additive BREAKDOWN, so counters for old functions should  be zeroed. Note that BREAKDOWN of NIL just zeroes counters without unbreaking  any functions. Note also that BRKDWNTYPE can be changed without unbreaking and  rebreaking, since redefining the function BRKDWN2 will take care of everything,  except that if more things are being measured, the statistic arrays must all be  lengthened (BRKDWN1 takes care of this.)) (MAPCAR BRKDWNLST (FUNCTION CAR)))) (BRKDWNINIT (LAMBDA NIL (* lmm "14-MAR-80 09:04") (COND ((NOT BDPTR) (SETQ BRKDWNLENGTH 0) (SETQ BDLST (BRKDWNARRAY 1)) (SETQ BDSINK (BRKDWNARRAY 1)) (SETQ BDPTR BDSINK))))) (BRKDWNSETUP (LAMBDA (FN DEF PTR N) (* lpd "31-MAY-77 16:28") (PROG ((BDEF (CADDR DEF)) (TEM (LIST PTR N))) (* Form of brokendown function is BDEF= (BRKDWN2 FORM PTR N) where PTR points  to the first cell of an unboxed array%: this cell contains the number of times  the function has been called, and following cells contain the  (negative of the) parameter/s being measured.  N is number of times FORM is to be evaluated.  If N is greater than 1, FORM should not involve any side effects since it will  be performed more than once.) (COND (BRKDWNCOMPFLG (* Compile the BRKDWN2 form open, redefining FN.  The PUTD nonsense is so that the compiler doesn't unbreak FN in the process of  redefining it.) (PUTD 'BRKDWNFN NIL) (BRKDWNCOMPILE2 'BRKDWNFN (LIST (CAR DEF) (CADR DEF) (LIST 'PROG (CDDDR BRKDWNARGS) (LIST 'RETURN (BRKDWNFORM BRKDWNLABELS (LIST 'SETQ 'BDY (COND ((NEQ N 1) (LIST 'RPTQ N (CADR BDEF))) (T (CADR BDEF)))) (KWOTE PTR)))))) (PUTD FN (GETD 'BRKDWNFN)) (PUTD 'BRKDWNFN NIL) (* * Save the address of the code, for checking whether the function is still  broken, and the old definition, to allow rebreaking if BRKDWNTYPE changes.) (NCONC1 TEM (GETD FN)) (NCONC1 TEM DEF)) (T (RPLACD (CDR BDEF) TEM))) (RETURN TEM)))) (BRKDWN1 (LAMBDA NIL (* lmm "19-Jul-84 18:55") (PROG ((LST (OR (LISTP BRKDWNTYPE) (LIST BRKDWNTYPE))) LEN X Y) (* * Form of each entry on BRKDWNTYPES is  (NAME FORM1 FORM2) e.g. (TIME (LAMBDA NIL  (CLOCK 2)) (LAMBDA (X) (FQUOTIENT X (TICKPS)))) FORM1 is the parameter being  measured, FORM2 (optional) can be used to convert the value of FORM1 to some  other units, e.g. clock ticks to seconds.) (OR (GETD (SETQ Y (PACK (CONS 'BRKDWN LST)))) (BRKDWNCOMPILE2 Y `(NLAMBDA %, BRKDWNARGS (DECLARE (LOCALVARS . T)) %, (BRKDWNFORM LST '(PROG NIL BDLP (SETQ BDY (EVAL BDEXP)) (COND ((NEQ BDN 1) (SUB1VAR BDN) (GO BDLP)))) (CADR BRKDWNARGS))))) (PUTD 'BRKDWN2 (GETD Y) T) (* * The function used for breaking the functions of interest is BRKDWNNAME  e.g. BRKDWNTIME, BRKDWNCONSES etc. Its definition is created, if not already  defined, by BRKDWNFORM and then compiled.  BRKDWNTIME and BRKDWNCONSES are already defined in the system since they are  used so frequently.) (COND ((IGREATERP (SETQ LEN (LENGTH LST)) BRKDWNLENGTH) (* More statistics are being measured, so go though all the broken functions  and give them larger statistic arrays.) (MAPC BRKDWNLST (FUNCTION (LAMBDA (FNS) (PROG ((A (BRKDWNARRAY (ADD1 LEN)))) (COND ((CDDDR FNS) (* Function has open-coded BRKDWN2 and  must be recompiled.) (RPLACD FNS (BRKDWNSETUP (CAR FNS) (PUTD (CAR FNS) (CAR (CDDDDR FNS))) A (CADDR FNS)))) (T (RPLACA (CDDR (CADDR (GETD (CAR FNS)))) A))) (RPLACA (CDR FNS) A))))))) (SETQ BRKDWNLENGTH (LENGTH (SETQ BRKDWNLABELS (APPEND LST)))) (SETQ BRKDWNTOTLST (CONS NIL (APPEND BRKDWNLABELS))) (SETQ BDLST (BRKDWNARRAY (ADD1 BRKDWNLENGTH))) (SETQ BDSINK (BRKDWNARRAY (ADD1 BRKDWNLENGTH))) (SETQ BRKDWNTYPE NIL)))) (BRKDWNFORM (LAMBDA (LST SETFORM PTR) (* lpd "31-MAY-77 16:29") (PROG ((I 1) (LST1 (CONS)) (LST2 (CONS))) (* Computes the body of the BRKDWNNAME function  (closed or open coded) when LST is the list of things being measured.  PTR is the (name of the) pointer to the statistics array.) (MAPC LST (FUNCTION (LAMBDA (STAT) (PROG ((X (CADR (ASSOC STAT BRKDWNTYPES)))) (OR X (HELP STAT '"not found")) (TCONC LST1 (LIST 'BRKDWNINCA 'BDPTR 'BDLST I X)) (TCONC LST2 (LIST 'BRKDWNINCA 'BDZ 'BDLST I X)) (ADD1VAR I))))) (RETURN (LIST 'BRKDWNMACRO (CONS 'PROGN (CAR LST1)) (CONS 'PROGN (CAR LST2)) SETFORM PTR))))) (BRKDWNCOMPILE2 (LAMBDA (FN DEF) (* lmm "19-Jul-84 18:53") (DECLARE (SPECVARS LCFIL LAPFLG STRF SVFLG LSTFIL SPECVARS LOCALVARS)) (DECLARE (GLOBALVARS NLAMA NLAML LAMS LAMA NOFIXFNSLST NOFIXVARSLST)) (RESETVARS ((NLAMA NLAMA) (NLAML NLAML) (LAMS LAMS) (LAMA LAMA) (NOFIXFNSLST NOFIXFNSLST) (NOFIXVARSLST NOFIXVARSLST)) (RETURN (RESETLST (* RESETLST to provide reset context for macros under COMPILE1 as generated  e.g. by DECL.) (PROG ((LCFIL) (LAPFLG) (STRF T) (SVFLG) (LSTFIL T) (SPECVARS T) (LOCALVARS (COND ((NEQ LOCALVARS T) (UNION SYSLOCALVARS LOCALVARS)) (T SYSLOCALVARS)))) (RETURN (COMPILE1 FN DEF T)))))))) (BRKDWNTIME (NLAMBDA (BDEXP BDX BDN BDY BDZ) (* lpd " 1-JUN-77 14:39") (DECLARE (LOCALVARS . T)) (BRKDWNMACRO (BRKDWNINCA BDPTR BDLST 1 (CPUTIME)) (BRKDWNINCA BDZ BDLST 1 (CPUTIME)) (PROG NIL BDLP (SETQ BDY (EVAL BDEXP)) (COND ((NEQ BDN 1) (SUB1VAR BDN) (GO BDLP)))) BDX))) (BRKDWNCONSES (NLAMBDA (BDEXP BDX BDN BDY BDZ) (DECLARE (LOCALVARS . T)) (* lpd "31-MAY-77 16:31") (BRKDWNMACRO (BRKDWNINCA BDPTR BDLST 1 (CONSCOUNT)) (BRKDWNINCA BDZ BDLST 1 (CONSCOUNT)) (PROG NIL BDLP (SETQ BDY (EVAL BDEXP)) (COND ((NEQ BDN 1) (SUB1VAR BDN) (GO BDLP)))) BDX))) (BRKDWNBOXES (NLAMBDA (BDEXP BDX BDN BDY BDZ) (DECLARE (LOCALVARS . T)) (* wt%: "15-MAR-78 16:31") (BRKDWNMACRO (BRKDWNINCA BDPTR BDLST 1 (IBOXCOUNT)) (BRKDWNINCA BDZ BDLST 1 (IBOXCOUNT)) (PROG NIL BDLP (SETQ BDY (EVAL BDEXP)) (COND ((NEQ BDN 1) (SUB1VAR BDN) (GO BDLP)))) BDX))) (BRKDWNFBOXES (NLAMBDA (BDEXP BDX BDN BDY BDZ) (DECLARE (LOCALVARS . T)) (* wt%: "15-MAR-78 16:32") (BRKDWNMACRO (BRKDWNINCA BDPTR BDLST 1 (FBOXCOUNT)) (BRKDWNINCA BDZ BDLST 1 (FBOXCOUNT)) (PROG NIL BDLP (SETQ BDY (EVAL BDEXP)) (COND ((NEQ BDN 1) (SUB1VAR BDN) (GO BDLP)))) BDX))) (RESULTS (LAMBDA (RETURNVALUESFLG) (* wt%: "15-MAR-78 19:49") (BRKDWNRESULTS RETURNVALUESFLG))) (BRKDWNRESULTS (LAMBDA (RETURNVALUESFLG) (* wt%: "15-MAR-78 16:25") (PROG (CL:VALUES (I 1)) (CONSCOUNT 0) (MAP BRKDWNTOTLST (FUNCTION (LAMBDA (X) (RPLACA X 0)))) (SETQ CL:VALUES (MAPCAR BRKDWNLST (FUNCTION (LAMBDA (X) (BRKDWNRESULTS1 (LIST (CAR X)) (CADR X) (CADDR X)))))) (COND (RETURNVALUESFLG (* Return values, don't print.) (RETURN CL:VALUES))) (RESETFORM (FLTFMT BRKDWNFLTFMT) (MAPC BRKDWNLABELS (FUNCTION (LAMBDA (LABEL) (LISPXTERPRI T) (PROG ((TOT (CAR (FNTH (CDR BRKDWNTOTLST) I))) (TERP (CADDR (ASSOC LABEL BRKDWNTYPES)))) (LISPXPRIN1 '"FUNCTIONS " T) (LISPXPRIN1 LABEL T) (LISPXTAB 23 NIL T) (LISPXPRIN1 '"# CALLS" T) (LISPXTAB 33 NIL T) (LISPXPRIN1 '"PER CALL" T) (LISPXTAB 46 NIL T) (LISPXPRIN1 '"%% " T) (MAPC CL:VALUES (FUNCTION (LAMBDA (X) (BRKDWNRESULTS2 (CAR X) (CAR (FNTH (CDDR X) I)) (CADR X) TOT TERP)))) (BRKDWNRESULTS2 'TOTAL TOT (CAR BRKDWNTOTLST) TOT TERP)) (ADD1VAR I)))))))) (BRKDWNRESULTS1 (LAMBDA (NLST PTR N) (* lmm " 8-Aug-84 12:40") (* NLST is a list of the form (NAME NCALLS STAT1 ...  STATn) which is smashed (and extended if necessary) with the values from PTR.) (PROG ((I 0) (TOT BRKDWNTOTLST) (LST NLST) VAL) LP (SETQ VAL (IMINUS (BRKDWNELT PTR I))) (RPLACA TOT (PLUS (CAR TOT) (COND ((OR (EQ N 1) (EQ I 0)) VAL) (T (FQUOTIENT VAL N))))) (COND ((LISTP (CDR LST)) (RPLACA (SETQ LST (CDR LST)) VAL)) (T (RPLACD LST (SETQ LST (LIST VAL))))) (COND ((SETQ TOT (CDR TOT)) (ADD1VAR I) (GO LP))) (RETURN NLST)))) (BRKDWNRESULTS2 (LAMBDA (NAME X NCALLS TOT TERP) (* lpd " 1-JUN-77 14:36") (PROG ((TEM (COND (TERP (APPLY* TERP X)) (T X)))) (LISPXPRIN2 NAME T T) (LISPXTAB 14 NIL T) (LISPXPRIN2 TEM T T) (LISPXTAB 26 NIL T) (LISPXPRIN2 NCALLS T T) (LISPXTAB 34 NIL T) (LISPXPRIN2 (FQUOTIENT TEM NCALLS) T T) (LISPXTAB 45 NIL T) (AND (NEQ NAME 'TOTAL) (LISPXPRIN2 (FIX (FPLUS .5 (FTIMES 100 (FQUOTIENT X TOT)))) T T)) (LISPXTERPRI T)))) (BRKDWNCLEAR (LAMBDA (PTR N) (PROG ((I N)) LP (COND ((NEQ I 0) (SUB1VAR I) (BRKDWNSETA PTR I 0) (GO LP)))))) ) (DECLARE%: EVAL@COMPILE (DECLARE%: EVAL@COMPILE (PUTPROPS BRKDWNMACRO MACRO ((FORM1 FORM2 SETFORM PTR) (PROGN FORM1 (BRKDWNADDTOA PTR 0 -1) (SETQ BDZ BDPTR) (SETQ BDPTR PTR) SETFORM (SETQ BDZ (PROG1 BDPTR (SETQ BDPTR BDZ))) FORM2 BDY))) (PUTPROPS BRKDWNINCA MACRO ((PTR LST I VAL) (BRKDWNADDTOA PTR I (BRKDWNDIFFA LST I VAL)))) ) (DECLARE%: EVAL@COMPILE [PROGN (PUTPROPS BRKDWNADDTOA DMACRO ((PTR I VAL) (* BOXIPLUS a little faster) (\BOXIPLUS (BRKDWNELT PTR I) VAL))) (PUTPROPS BRKDWNADDTOA MACRO (OPENLAMBDA (PTR I VAL) (SETA PTR (ADD1 I) (IPLUS (ELT PTR (ADD1 I)) VAL))))] [PROGN (PUTPROPS BRKDWNDIFFA DMACRO (OPENLAMBDA (PTR I VAL) (PROG1 (IDIFFERENCE (BRKDWNELT PTR I) VAL) (BRKDWNSETA PTR I VAL)))) (PUTPROPS BRKDWNDIFFA MACRO (OPENLAMBDA (PTR I VAL) (IDIFFERENCE (ELT PTR (ADD1 I)) (SETA PTR (ADD1 I) VAL))))] (PUTPROPS CPUTIME MACRO (NIL (CLOCK 2))) (PUTPROPS IBOXCOUNT MACRO (NIL (BOXCOUNT))) (PUTPROPS FBOXCOUNT MACRO (NIL (BOXCOUNT 'FLOATP))) (PROGN (PUTPROPS BRKDWNELT MACRO ((ARR I) (ELT ARR (ADD1 I)))) (PUTPROPS BRKDWNELT DMACRO (= . ELT))) [PROGN (PUTPROPS BRKDWNSETA DMACRO ((ARR I VAL) (\PUTBASEFIXP (BRKDWNELT ARR I) 0 VAL))) (PUTPROPS BRKDWNSETA MACRO ((ARR I VAL) (SETA ARR (ADD1 I) VAL)))] [PROGN (PUTPROPS BRKDWNARRAY DMACRO ((N) (PROG ((BLOCK (ARRAY (ADD1 N) 'POINTER NIL 0))) [for I from 0 to N do (SETA BLOCK I (NCREATE 'FIXP] (RETURN BLOCK)))) (PUTPROPS BRKDWNARRAY MACRO ((N) (ARRAY N N)))] ) ) (RPAQQ BRKDWNLENGTH 0) (RPAQQ BRKDWNCOMPFLG NIL) (RPAQQ BRKDWNARGS (BDEXP BDX BDN BDY BDZ)) (RPAQQ BRKDWNTYPES ([TIME (CPUTIME) (LAMBDA (X) (FQUOTIENT X 1000] (CONSES (CONSCOUNT)) (PAGEFAULTS (PAGEFAULTS)) (BOXES (IBOXCOUNT)) (FBOXES (FBOXCOUNT)))) (RPAQ BRKDWNFLTFMT (NUMFORMATCODE '(FLOAT 7 3 NIL NIL 10))) (RPAQQ BRKDWNTYPE TIME) (RPAQQ BRKDWNLABELS NIL) (RPAQQ BRKDWNLST NIL) (DECLARE%: DOEVAL@COMPILE DONTCOPY (GLOBALVARS BRKDWNARGS BRKDWNLABELS BRKDWNLENGTH BRKDWNLST BRKDWNTOTLST BDLST BDSINK BDPTR) ) (DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY (BLOCK%: NIL BRKDWNTIME BRKDWNCONSES BRKDWNBOXES (LINKFNS . T)) (BLOCK%: BREAKDOWN BREAKDOWN BRKDWNSETUP BRKDWN1 BRKDWNFORM BRKDWNCOMPILE2 (GLOBALVARS NOSWAPFLG)) (BLOCK%: BRKDWNRESULTS BRKDWNRESULTS BRKDWNRESULTS1 BRKDWNRESULTS2) ) (DECLARE%: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDTOVAR NLAMA BREAKDOWN) (ADDTOVAR NLAML BRKDWNFBOXES BRKDWNBOXES BRKDWNCONSES BRKDWNTIME) (ADDTOVAR LAMA ) ) (PUTPROPS BRKDWN COPYRIGHT ("Venue & Xerox Corporation" T 1982 1983 1984 1986 1990)) (DECLARE%: DONTCOPY (FILEMAP (NIL (2123 21017 (BREAKDOWN 2133 . 6169) (BRKDWNINIT 6171 . 6448) (BRKDWNSETUP 6450 . 8723) ( BRKDWN1 8725 . 12179) (BRKDWNFORM 12181 . 13161) (BRKDWNCOMPILE2 13163 . 14433) (BRKDWNTIME 14435 . 14902) (BRKDWNCONSES 14904 . 15382) (BRKDWNBOXES 15384 . 15862) (BRKDWNFBOXES 15864 . 16343) (RESULTS 16345 . 16495) (BRKDWNRESULTS 16497 . 19200) (BRKDWNRESULTS1 19202 . 20176) (BRKDWNRESULTS2 20178 . 20833) (BRKDWNCLEAR 20835 . 21015))))) STOP