SPYLarryMasinter17October1984SPYisatooltohelpyoumakeprogramsrunfaster.Itgivesyouapictureofwheretheprogramisspendingitstime.SPYhastwoparts:a'sampler'whichyourunwhilerunningyourprogram,whichmonitorswhattheprogramisdoing,anda'displayer'whichdisplaysthedatagatheredbythesampler.The'sampler'periodicallyinterruptstherunningprogramtoaccountthefunctionsinthecurrentcallstack.ThisallowsSPYtoremembernotonly(proportionally)howlongisspentineachindividualfunction,butalsohowlongeachfunctionseenonthecallstack.Thesamplerdatastructuresweredesignedtominimizeinterferencewiththenormalrunningoftheprogram--thereislittlenoticableperformancedegradation.BecauseSPYdoesn'tlogeverycallandreturn,youcanrunitevenoverlongcomputations,unlikeDOSTATS.The'displayer'usestheGRAPHERpackagetodisplaythedatagatheredbythesampler.Inthegraph,theheightofeachnodeisadjustedtobeproportionaltotheamountoftime.JustasMasterscopeandBrowsergiveaninteractivepictureofthestaticstructureoftheprogram,SPYgivesaninteractivepictureofthedynamicstructure.Thedisplayerisinteractiveaswellasgraphical.Thatis,youcanlookatthedatainavarietyofways,sinceitseemsthereisnoonepicturethatsaysitall.Sincethedisplayerknowsthewholecallgraph,itcanshowtheentiretreestructure(withseparatecallstoafunctionaccountedseparately)ormergingseparatecallstothesamefunctions.Sincethesamplerrecordstheentirecallingstackwhenitsamples,itcanaccountforbothindividualandcumulativetime.Whenthesamplerruns,ifafunctionisonthetopofthestack,itaddstoitsindividualtotal;ifthefunctionisonthestackatall,thesampleraddstothecumulativetotal.Whenthereareseveralcallstothesamefunctionwithinthegraph,thedisplayercaneither'merge'thenodes(showthetotaltimeforthefunctioninonenode)ornot.Ifanodeismerged,thenoneoftheboxesinthegraphwillhaveallofthetimeforthatfunctionaccountedtoit,andtherestwillbeleftas'ghost'boxes.SPYhasavarietyofwaysofcontrollingwhichnodeswillbemerged.HowtoUseSPY(SPY.BUTTON)[Function]Thisfunctionputsupalittlemenuwiththesinglebutton"SPY"onit.Pushingitoncewillturnonsampling(SPY.START).Pushingitagainwillturnoffsampling(SPY.END)anddisplaytheresults(SPY.TREE10).Thisisthesimplestwayofspyingonoperations.Notethatyoucan'tturnoffsamplingifthemouseprocessislockedout.Alternatively,youcanturnSPYingonandoffbyusingthefollowingfunctions:(SPY.START)[Function]ReinitializestheinternalSPYdatastructures,andturnsonsampling.(SPY.END)[Function]Turnsoffsampling,andcleansupthedatastructures.(WITH.SPYform)[Macro] q?` p q?` g_p(}akq+ak*3_r*9_%])".]%\R&,U/g\R*3Z*9Z Y 7xk%.',h-14^5:=#&( /139A< ?FHGJJU TaT Rh Rh P   !J#)F/506[8?,@CDHHJJP O#!$}'2w59I:>@D JJO Ms:8 %)S+|.047=@ G7JJMs K U#&+02L4:< ?A"DxJJK J%  !!$)=+/2e5Z:G=(?BDGJJJ% H~ ( !!H~ F F E0 %\'+.i179? GJJC A B!E#)%)/14s:=AC JJA @;@;s@;^@;r@; ,!')=)=@;s@; 0@;r@;0`25 6 =c@BKEGJJ@; > <6 !z"&*+-05b8^;3B?DJJ> <*9I $'n+.48>ACEJJ< ;F c(%(*-60 7;H=C<HGJJ;F 9" J!"C$*),e/ 6n93 @D#HHJJ9 7S*/6 #@$'t+`,/13w3w7s7 97r7:$>?RAGHJJ7 6Q d}!u i""6Qs6Q )6Qr6Q*)-6Q 4 4 31 Yn9 $x*M.1d68>AREJJ3 1\ vZ  R"(*7-1&257'8J;=<BFKI JJ1\ / {& "%4(}*-3:@C{F:HJJ/ . v '8!#&( /481:<B . ,g ,g * *%>)(*3,/-)*3'r*9'r % % $$ "',16;@ G$$ "} "}  :y!$p'+E0,468{=?cBEHJJ /l . |$'+"-40;E>eC~FNJJ/ bD"$P(* 2v58;?;BYDJJ  W4"; +.1m49+BDJKKa `Cw &% .&3U7;B8`C ^ ^ \ >"e(\ [N [N Y s% -&16;@ GY X X VY.}s. #<&j').48:<AsC. JJVY T \ `"')@-//2_8:< E HGJJT S = "%(I*0 8L9;@FHJJS Qd r3 '(+-25=? HoIJJQd OJ:D %t' /H6&8[<*@O N N Lo p  &),-149[:?DsHZJJ) (FB!$ +-'.k/2T5;"<@BFHGJJ( &h &h $ $ # ^o_ t&I),p137:@E1HGJJ# !s &  $'*0 7;>AFHGJJ!s  A!k%b(*-.%2}58<| % % ~!(,26:?>DAsEHJJ~ ~e$((+. 57<9>ABxEMJJ0m! * 6B9=?EJJJ0't" $  +@ q?` 3B"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" / / oq;pǏ;vm۷ooo_w/m[n۹oϟ /WmXu[۾woo iۻ[۷ooo_wǫ?qreKoBDFJJKJu"$&x(-.036:<ADDGIJ Hm Hm F B F 5l" q?` 5l 5l#v#* q?` 5l 5lJTJZ5l 3r 3 2 : !q$&'+.10348;>@CDHGJJ2 0wC0w . . -)  1" )*/2$5: BZCHGJJ-)+\!#()+@0r257:'>[ E8H3JJ+)rS$'#*29;BIJJ)(4[2(4 & & $ L"&,/ 35 <:@B JJ$#? 1! ),/2 35n cEFoHGJJ#?! #E$+.x3K!   J!$*1/168 ?8CJ     Ut5UrU;U    6>T "%p)+03.6l9 BSD FJJ ` X5%8&p'(-^0158/=6?@.@4`    p DF q?` D DIZ q?` D D 8r 8  d3;!%#')-0U2q :?3BtDjG#JJ MI"%A Jq q?``4` `  #0dx0 He)H pep @e@ 0b0""""""""""Thecasewhereafunctionismergedwitharecursivecalltoitselfishandledspecially:theheadoftherecursionismarkedwithawidercheckeredborderwwwwwwwwwwwwwwwptp hq̓1)H)J)tH9 A 8p)H!)@Dd)HhCc4pphwwwwwwwwwwwwwwwpandthetailoftherecursionisinverted`?9ͣ?smֵ~ߵ`m񽯞?`m`?/?Ͳ`Intherecursivecase,youcanwindupwithasituationlikethis:==*UUUUP*UUUUP(PP(PP(PP(PP(`8Q$P($К8P($wwww` P$P0)`8PP(p`PP(`PP(p`PP(0PP*s% )cUUUUP-`(*5(UUUUP% };q% EcwwwvØDL0L 8p`pH 0H  8p`pH 0I  :Rowwww`rVo HR :RoqH H 8pH H 8wwwvLL;Inthiscase,AcallsB,andcallsCwhichcallsA.AllofthetimeisreallyspentinB,althoughonly10%isduetothecallfromthetop-level,and90%isunderacalltoCwhichcalledAwhichcalledB.Inthissituation,Cisalsorecursive,ofcourse,andalsohastherecursiveborder.Ifyoufindthisdisplayconfusing,youshouldtrytheMergeNoneoptionandseeifyougetaclearerpicture.MergeDefaultmeanstomergeanyfunctionthatisnotinSPY.NOMERGEFNS,initiallysetto(ERRORSET\EVAL\EVALFORMAPPLYEVAL).MergeNonemeansnottomergeatallMergeAllmeanstomergeanytwonodesforthesamefunction.ThedefaultforIndividualmodeisMergeAll.ThedefaultforCumulativemodeisMergeDefault."Individualvs.Cumulative"SPYinitiallycomesupwiththeheightoftheboxesshowingtheamountoftimethefunctionwasonthecurrentcallstack.Thisiscalled"cumulative"mode,sincetheeachfunctiongetsthetimethatbothitandthefunctionsitcallsaccountfor.Thereisanotherkindofdisplay,called"Individual",inwhichtheboxesareproportionaltotheamountoftimethefunctionwasonthetopofthestack.Forexample,ifyouchangethe\MOUSE.PROCESSdisplaytoIndividual,youcangetadisplaylikethis:%A fr hsp hs ar a _ p D q?`) D_ D_g q?` D_ D_d_ ^ r ^ \b   5S"%'"-*/1v15`57< CEI JJ\b Z d'8!.',TZ Y Y V: p D q?`v DV: DV:OZ q?` DV: DV:V: Tr #~+"XT R R P2 p D" q?`; DP2 DP2J q?` DP2 DP2P2 Nr N L z 3c!%&%,.1L K= K= CC B , z p6 q?`O pCC pCC2Kd q?` pCC pCCpvCC Ar A ? 'wACt"%'X)q+*-02%59;j<C4FLIJJ? >N %: 6#&b'+-/1r26;<|@DFH!JJ>N <  ;3$J'T*p-+/6";t<?CEJJ< ; "0$)!+.</s245:D?); 9Y 9Y 7  #P)-..245ANFI JJ7 6 FP>!%6 4d 4d 2M~ " 2 13KN $>&s(,w2G1 /o /o -  h_&6(-0 7;< F&- ,! ,! *z *z (t ky ( '1r '1 % &7~"$X&*03:8:f=@2EHJJ% # dX{ (,0Y26;>A1DdG\JJ# "< >3> #R'\(.$1X38G/ ```ipԥ"@@k"@,@"@,i"@wwwwwww`i0"@f>8,`,`` ,@,,,?*UUUT?UUUUj0` *UUUT,0` UUUUj,0`@(00`P 00a(,0$c<03\dAI.CbP ,Hܥ(R)04RAJPBd(XR!00ҔAJBhP h874 ҕAYICp(,H( !02$ ҕAYHPiBhP ,H(")04$җJPDiBd(0"c<07:\b1D.{bP 00a(,00`P ,00`@(0` P 0`(,0`P ,?(?P (,P ,@( P (,P ,(P (,UUUUUUUUUUTUUUUUU@P ,* (@UUUUUUUUUUTUUUUUU@P * (,P@P ,(( (QgIg0d1@Q&}ޗ*@ JPH( H%*H*R%),R JHX% Y@RV%) ,@ YIaN+h% h%)R@ YHP>HH% I@RR%) *@ JP"H( H%)H*R%),Qw1a"O0gȱ@Qޑ ,(( (P@P (( (,UUUUUUUUUUTUUUUUU@P ,* (UUUUUUUUUUTUUUUUU@P * (,P ,(P (,P ,(P (,P ,(P (,P ,(P (,P ,(P (,P ,(P (,P ,(P UUUUUUUUT,*,UUUUUUUUT*,/"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Whichshowsthat80%ofthetotaltimeunder\MOUSE.PROCESSwasspentinsidethefunctionIQUOTIENT.(Whew,somethinggoingonwrongthere...whyisn'titgettingthemicrocodedversionofdivide?).Onethingtowatchoutfor:whenyouswitchbetweenIndividualandCumulativemodes,the"threshold"staysthesame.(SometimesthethresholdforIndividualneedstobehigher;otherwise,functionswilltendtodisappearintheIndividualtree.)Also,switchingtoIndividualalsochangesto"MergeAll",whileswitchingto"Cumulative"changesyouto"MergeDefault".(SPY.LEGEND)[function]Ifyouforgetwhatallofthedifferentshadingsandbordersmean,thisfunctionbringsupawindowwhichshowswhattheymean.Internalcontrols:SPY.FREQUENCY[variable]Howmanytimespersecondtosample?Initiallysetto10.(Maximum60).SPY.NOMERGEFNS[variable]Functionsonthislistwon'tgetmergedunderMergeDefault.Includes(ERRORSET\EVALEVALFORMAPPLYEVAL).Youmayneedtoaddmore.SPY.TREE[variable]Thisvariable(samenameasthefunction)isusedtoholdthedatafromthelastsampling.YoucansaveitawayandrestoreitusingUGLYVARS.SPY.BORDERS[variable]Usedtocontroltheborderdisplayonatree.Thisisalistof(nodetypedescriptionborderwidthtextureinteriortexture)(SPY.LEGEND)[function]BringsupawindowwhichshowstheinterpretationofSPY.BORDERS.SPY.FRAGMENTS[variable]IfNIL,SPYwillnotinclude'ghost'boxes.InitiallyT. G frIhspJjhs Qr q?` Q Q& q?` Q QNTNTQ P0r P0 N N L6#"&2* 69=B5EJJL K; 3"B$C(-0349<` D*I JJK; IgJ!%v(%,~2s 9; CeHGJJI G  $B $&-D/ 6l:C JJG FFW~O #@ *-1v89 @CI JJFF D O ' ,/60<<D B B AQ AQ ? "',16;@E|E|? > M> <\ + .C!'*S/36[<@VBRCcHH<\ :C: 9 9 7gH7g 5 5 4 "',16;@E|E|4 2r FL2r 0 < 6#(*?+.!.o570 /$ /$ -} "',16;@E|E|-} + + */]g#( 17>C*JJ*/ (`@ $m( & & %:"',16;@E|E|%: # # ! 0:*$W%(*-0-3a69A;B?E&GJJ! E +^Q" E    "',16;@E|E| P P  b_!"&(*+)-I.5 =6 EJJ  [ [  "',16;@E|E|  M f84E! *, 5f    "',16;@E|E| q  q  + *G#() & q?`*6SPY.SHOWCOUNTS[variable]IfNIL,SPYwillnotdisplaythepercentageinthenode-boxunlessthenode-boxhasbeenmadehighertoaccomodatethetextinthenode.InitiallyT.SPY.FONT[variable]Fontusedtodisplaynodelabels.Initially(GACHA10).SPY.MAXLINES[variable]Maximumheightofanodeinthegraph,measuredinmultiplesofthefontheightofSPY.FONT.KNOWNPROBLEMSWITHTHISVERSIONOFSPYTheDolphinandDoradohaveabugwhichwillcauseincorrectlylargeamountsoftimetobeaccumulatedtotheroutineswhichgetandsendpacketstothe3MBEthernet.Itwillshowupassamplesunder\3MBGETPACKET(orwhatever).TherestofthedataintheSPYdisplayisrelativelyaccurate,andyoumayneedto'delete'thatnode.SPYdoesn'tknowanythingabouttheinterpreterortheinternalworkingsofInterlisp-D.Internalfunctionswhicharenot"realframep"anddon'tnormallyshowuponBTbacktraces(butdoonBT!)willbeshowninspy.Thisincludesthingslike\INTERPRETER1whichwillappearunderneathanyinterpretedfunctioncall.Finally,anumberofenhancementsandextentionsareplanned;suggestionsandrequestsarewelcome.) fr hsp hs ar a `C "',16;@E|E|`C ^ ^ \ + *g $b%(X.25a;>:AEJJ\ [N %| %'[N Y Y X"',16;@E|E|X VY VY T (ok#)X+T S S Qd "',16;@ FQd O(|r#*~,2.36K9W=?F*O N N Lo Lo J B&$&(zJ I! I! Gz r $8(+0 7;ACG"HJJGz E e>!$a'j*0`2W58?@CyG"IJJE D, ;! (+.03`68;>>%CD JJD, B vo"%)^B @ @ ?7 +Q # +=-,/5u;= EcJJ?7 =Q "%)a/o355N7h9m @CEGJJ= ; !&Y)A 3{7:? HJJ; :B H:B 8 8 67 "% -n0A6 ? BCH[JJ6 5M5M q?`Y FRUTIGER  FRUTIGER  FRUTIGER  FRUTIGER ~GACHA ')(P [#tyj/|z~'{ERIS}HARMONY>LIBRARY>SPY.TEDIT;4 STANSBURY.PA27-Nov-84 11:02:26