From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=0.7 required=5.0 tests=BAYES_00,INVALID_DATE, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.lang.ada:2830 comp.lang.misc:3643 Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!think!kulla!barmar From: barmar@kulla (Barry Margolin) Newsgroups: comp.lang.ada,comp.lang.misc Subject: Profiling (was Re: Inheritance & limited private types) Message-ID: <31185@news.Think.COM> Date: 27 Oct 89 22:32:33 GMT References: <48695@ricerca.UUCP> <6845@hubcap.clemson.edu> <126675@sun.Eng.Sun.COM> <31018@news.Think.COM> <800@philmtl.philips.ca> <4697@bd.sei.cmu.edu> Sender: news@Think.COM Reply-To: barmar@kulla.UUCP (Barry Margolin) Followup-To: comp.lang.misc Organization: Thinking Machines Corporation, Cambridge MA, USA List-Id: [Note that I've directed followups to comp.lang.misc, as this no longer seems to be about Ada.] In article <4697@bd.sei.cmu.edu> firth@sei.cmu.edu (Robert Firth) writes: >In article <800@philmtl.philips.ca> pedersen@philmtl.philips.ca (Paul Pedersen) writes: >>The conclusion I came to was that it is not possible to do profiling >>using UNIX on a fast processor, short of using a logic analyzer and a >>lot of interpreting software (far from sure that this is even feasable). >>I would be *very* interested in hearing from anybody who has solved this >>problem (I gave up) :-) >Gee, I implemented profiling on this Unix machine in an afternoon. >Admittedly, I was helped by the existence of a system call 'profil', >which does all the real work. > >The purpose of profiling is to find out where the program is spending >a lot of its time. Now, the profiling command samples the program >counter 100 times a second, so in a one-minute run that is 6000 >samples. Any subprogram body that consumes more than 1% of the mill >will therefore generate on average more than 60 hits, which is surely >a meaningful number. This is called "statistical program counter metering" on the system I use (Symbolics Lisp Machines); until last year it was the only metering facility provided by Symbolics. They implemented it using microcode microtasks (Symbolics 36xx machines can run up to 5 concurrent microtasks) rather than interrupts, so the overhead is virtually nil and it samples very frequently. To be most useful, statistical PC metering should permit you to specify the frequency, particularly if your application contains loops (how many significant applications don't?). This is because the period of the loop might be close to the period of the PC sampling, and you would get distorted data. A way to get more precise metering is to make use of a trap-on-call/return facility. This can be implemented in hardware (as on the Lispm) or in software (the subroutine calling sequence could check a flag), or in the compiler (an option to the compiler tells it to generate metering code). Whenever a function call is made the trap handler records the time, and when it returns the elapsed time can be recorded. To get more precise timings, of course, you need a more precise clock; what you need is an independent high-frequency clock chip that can be read, rather than a clock that simply interrupts the processor every Nth of a second. Symbolics machines have a 60th-of-a-second interrupting clock to drive the scheduler and time-of-day clock, and a separate microsecond clock that can be read on demand (there's also a third clock, called the calendar clock, running in the front end processor, for use when Lisp is shut down). Another way of metering is to just count the number of times particular functions are called. This can be done using the same mechanisms as the above, but it doesn't require the high-frequency clock. Instead of reading the clock, the trap handler just increments a counter for the function being called. This is often useful for determining where the likely hot spots will be. Barry Margolin, Thinking Machines Corp. barmar@think.com {uunet,harvard}!think!barmar