PerfStats.mesaPerfStatsisapackageusedforgatheringperformanceinformation,ofteninthecontextofatestprogram.Itimplementscountersandstopwatch-liketimers,andwillprintsummarystatisticstoastream.Lasteditedby:MBrownonAugust26,19829:12pmDIRECTORYIOUSING[STREAM],RopeUSING[ROPE];PerfStats:CEDARDEFINITIONS=BEGINROPE:TYPE=Rope.ROPE;STREAM:TYPE=IO.STREAM;Counter:TYPE=REFCounterObject;CounterObject:PRIVATETYPE=RECORD[pName:ROPE,counter:LONGCARDINAL_NULL,next:Counter];DefinedheresowecanuseaninlineforInc.CreateCounter:PROC[name:ROPE]RETURNS[Counter];DuplicateName:ERROR;RaisedonCreateCounterorCreateTimerifnamematchesanexistingevent'sname.InitializeCounter:PROC[event:Counter];DestroyCounter:PROC[event:Counter];Inc:PROC[event:Counter]=INLINE{event.counter_event.counter+1};Timer:TYPE=REFTimerObject;TimerObject:TYPE;CreateTimer:PROC[name:ROPE]RETURNS[Timer];InitializeTimer:PROC[event:Timer];DestroyTimer:PROC[event:Timer];Start:PROC[event:Timer];Stop:PROC[event:Timer];Initialize:PROC[];Initializesallevents.Print:PROC[heading:ROPE_NIL,oStream:STREAM,verbose:BOOL_FALSE];PrintscurrentstateofstatsmoduletoputChar,thencallscleanupifnotNIL;resetsglitchcount.Ifverbosethenprintsallevents,otherwiseonlyeventswithnonzerocounts.END.HowtousePerfStatseventsPerfStatsdefinestwotypesof"event":counterandtimer.EacheventhasaROPEname,suppliedwhentheeventiscreated(CreateCounter,CreateTimer)andusedtoidentifytheeventinprintedoutput.An1p a q ]Bv" * 2L57]9>x@AOC [ {  #h'*t- 0T6 ;=8>l Z1XH"r U!SqsSqrQSqsSq~SqQrQQsQrUQsgQQ Na r>Na Na sNarLKsKrKKstKYKrKKsKrIQsIQrIQIQs-IQrIQ|IQsYIQrIQszIQErEEsBEr'EEsEE DA rDADA8s DAr"tDA#HDAs'DABr{BOBsBiBrBB"s)ZBr*B+Bs.'B/B2q1@?: "$(*t= s=r=g=sM==r= =s"=r#=$=s)=*5=; rk;$;s};q: x !F )"*x.3N5A:Q>t8ps 8pr 8p8ps8p8p!'t6 s}6rz6"6s6j6 t5s5r55s}55r 5!$5s%;5%5 .t0 8:o1r1c1s1r11s1~1 0 r0P0s0t, s,r,4,s,|,r,,s!,r",#,s(,),t*s*r*}*sb**t)@ sI)@rG)@)@s)@7)@et's'r''s''.t%s%r%u%sZ%%t sD rA  sd  q d_tpsprppspprpps+pr p!ps"p#pr)p*&ps.Qp/.pr4p5kps8Gpr9p:ps=rp=pq& %'$,/279A;?CBSx!7$A(* .k4V7R;Y>UCqrisip gu 66q ~R!&)i-15%7v8 9 q< =R @E 5 WK Q (+.0y5p7;}=AAGNw)TVm$attempttocreateaneventwiththesamenameasanexistingeventwillERRORDuplicateName.Countereventsareusedforloggingthefreqencywithwhichaspecificactionorsetofactionsisperformed.IfeisaPerfStats.Counter,thene.Inc[]causese'scountertobeincrementedby1.e.Inc[]isveryinexpensivetoperform.Timereventsareusedforloggingthetimerequiredforaspecificactionorsetofactions.IfeisaPerfStats.Timer,thene.Start[]recordsthecurrenttimeinavariableassociatedwithe.Thenwhene.Stop[]isperformedatsomelatertime,itnotesthedifferencebetweenthecurrenttimeandthetimerecordedbythepreviouse.Start[].Atpresenttheaverage,maximum,andminimumtimesaremaintainedinthetimerevent.e.Start[]ande.Stop[]involveoneprocedurecalleach,andmustreadtheprocessorclockandmanipulatee'sstatistics;hencetheyaremoreexpensivethane.Inc[].OntheDorado,thetimerresolutionis32microseconds,andthecostofaStart-Stoppairisabout33microseconds.OntheDolphinthesetimesare64microsecondsand417microseconds,respectively.AcalltoPerfStats.PrintprintsthecurrentstateofallactiveeventstoanoutputIO.STREAMcalledoStream.(Actually,unlessitsparameterverboseisTRUE,PrintprintsnothingforcounterswithnoInccallsandtimerswithnoStart-Stopcalls.)PrinttakesaROPEcalledheadingasaparameter,andprintsitaspartoftheoutput.PrintcallsoStream.FlushwhenitisthroughsendingcharacterstooStream.PrintistheonlywaytogetinformationoutofPerfStats;thereisnowaytointerrogateaneventdirectly.Whentwocallstoe.Start[]occurinsuccessionwithnointerveninge.Stop[],thefirste.Start[]isignored;whentwocallstoe.Stop[]occurconsecutively,thelastisignored.Eachofthesesituationscountsasa"glitch",andthenumberofglitchesisreportedfordebuggingpurposesduringPrint.GlitchesmayoccureveninprogramswhosecallstoStartandStopappeartomatchproperly,duetoafailuretocalle.Stop[]duringtheunwindofaprocedureactivationthatcallede.Start[].WeconsiderittoocumbersometoprovideacatchforUNWINDsimplytoavoidglitches,sowerecoverfromthemwithonlyaprintedwarning.Aseparateprocedure,PerfStats.Initialize,isprovidedinordertoresetallevents(clearsallcounters,forgetsalltimes,exceptthatthestartingtimeofarunningtimerisnotforgotten).Individualeventsmayalsobeinitialized(e.InitializeCounter[],e.InitializeTimer[]).Aneventiseliminatedbycallingadestroyprocedure(e.DestroyCounter[],e.DestroyTimer[].)ThisremovestheeventfromconsiderationbyPrint,andmakesitsstoragereclaimable.AnexampleTocompileaprogramthatusesthePerfStatspackage,importthePerfStatsdefinitionsmodule.Tobindtheprogram,usetheimplementationPerfStatsImplandimportIO,RopeandSystemforitsuse.ThefollowingistheskeletonofatestprogramthatusesthePerfStatspackage.DIRECTORYPerfStats,...SampleTest:PROGRAMIMPORTSPerfStats,...=BEGINoStream:IO.STREAM=...;insertCounter:PerfStats.Counter=PerfStats.CreateCounter["callstoInsert"];lookupTimer:PerfStats.Timer=PerfStats.CreateTimer["callstoLookup"];...Insert:PROC[x:Widget]={insertCounter.Inc[];...};--InsertLookup:PROC[k:WidgetKey]RETURNS[x:Widget]={lookupTimer.Start[];...2q b&wqd0"&>').2}v5b&5b&q9|b&:b& _ ipP!&)-.379K;U<A|B ] _ b !!%5'+-^/ 68@:>G?B` \I  Y$a." %F*-.3v79;=CEgFHZ X5 #'*,L-u2 8;=AD Vk ap|"h$ *0 2b7:+<?,B=G T 9~ 9 %,/&5/8; B CF SA \! #*O- 037?:~=CF Qu   "{%,%/^v4Qu5Qu68<>A FG O  !P"n%j& ./158;s=J> ELGc N'  qN' K [ pY#.&O')-134v9K9Kq?K@KC I Elj!v#RI$ Iq&uI'sI+/46d;?ACF HI TN}"d%v'HI'HIq*HI+BHI.35F6w =&?CDF F  < #&().3 :;B3EGC D N A %I(* ,.0z 7P9C< Bl p 5 &)+ 286:=pBD? @ 2h)F &)+-1368w; B*FHZ ?quc!r&(/j49?=BE =v d #&+),069:;@IAD ;#^ #&* 028(9n; CHD :' !v:':'qQ:':'1$&(-g0479;3? 7 a "$9)+).0=3c5Q9L=?}E' 5  )!#"#),. 0o 7 =BDG 4J %? 1 " zJ#d)5AfDk 0 8 1  #').? u + q (n S%+~/218' >DbF & 8U  (+rv/&0A&q1&1&5w8<>@ $8 ;&Z &C)+.E40v !qv  qG G  vkq!"$iv&N'q vQqvq 4 v44qy4w4v4 T4q$44%1402  vj#qvq"#./   v_  q c 'I. o voq2o  \vz \3 \q \} \B v \x \q# \$ \%*, vu q  w) NTVm$jlookupTimer.Stop[]};--Lookup...Test1[];--callsInsertandLookupPerfStats.Print["Test1",oStream];PerfStats.Initialize[];Test2[];--callsInsertandLookupPerfStats.Print["Test2",oStream];insertCounter.DestroyCounter[];lookupTimer.DestroyTimer[];END.--SampleTestChangeLogCreatedbyMBrownonNovember4,19803:35PMByeditingDBStats.ChangedbyMBrownonNovember7,19809:31AMAddInitializeCounterEventandInitializeTimerEvent.ChangedbyMBrownonJanuary10,19819:24PMCreatedPilot/collectiblestorageversion.PrintnowtakesputCharandcleanupasparms.RenamedtobePerfStats;madetypeandprocnameslessverbose.Movedmostcommentstodocumentationfile(PerfStats.bravo).ChangedbyMBrownonJanuary11,19814:46PMAddedDuplicateNameERROR.AddedverboseparmtoPrint.ChangedbyMBrownon18-Aug-8118:28:40CedarString->Rope.ChangedbyMBrownon7-Dec-8115:23:08UseIOStream,ROPE.ChangedbyMBrownonJune24,19821:16pmIOStream->IO,CEDAR.ChangedbyMBrownonAugust26,19829:21pmFormatinterfacewithnodestructure,mergedocumentationbackin.3q b& vub&qb& ` ^v ]0 ]0q]0u]0 v0]0]0q#]0$d]0 [v Y YqYuY  X: vX:q)X: V vlVqVv Tq ;T T p Ox K!?% r(K(Kq IX ~x F X!%r(F)Fq Db Cx A $r'A(oAq ?lh"&U).,249;U@1FG =  #&,}1V4;= G; <x 9 $r'9(o9q 7' "?&*|,!x 4 =q 21 ?x /mq -; `x *"Z%iq (EQx %C #&q #OB>| u$z -0w)TVm$ TIMESROMAN HELVETICA TIMESROMAN TIMESROMANY TIMESROMANLAUREL TIMESROMAN TIMESROMAN TIMESROMAN Lj/-perfstats.press26-Aug-82 21:40:13