Re: hi-res profiling

From: Andres Kroonmaa <andre@dont-contact.us>
Date: Wed, 2 Oct 2002 11:00:40 +0300

On 2 Oct 2002, at 10:23, Robert Collins <robertc@squid-cache.org> wrote:

> On Tue, 2002-10-01 at 02:21, Andres Kroonmaa wrote:
> >
> > Of course. Its meant exactly for that ;)
> > I'm currently very busy so I can't really do it myself, but if you update
> > it to HEAD, I'd be only thankful.
>
> Ok, done. Did you setup select profiling, or just poll? (The poll code
> has move to another file, and I didn't see any handling of PROF_* in the
> remaining select code.

 just poll. I made it to look at real cache in prod mode. We don't use select.

> If you could give the branch a once-over, now I've updated it, that
> would be cool.

 I'll try to find some time.

> > All else happens automagically. You need to keep in mind that started probe
> > must always be stopped, or it won't show up in cachemgr output.
>
> Can probes reenter?
> Ie. does the follow 'do the right thing'
> foo (int n)
> {
> PROF_START (foo);
> if (n)
> foo (--n):
> else
> {}
> PROF_STOP (foo);
> }

 Its safe to reenter, but it will lead to not what you want.
 Internally, each probe has both start and end timestamps. Code
 doesn't care if you start same probe in a row. Stop also doesn't
 care. But time delta is snapshot only at Stop, and relative to
 lastly updated Start time. So, in such reentrant code you'll end
 up measuring N (reentry) times how much time it takes to _return_
 from lastly entered foo().
 look at lib/Profile.c, its embarrasingly small and simple..

 foo (int n)
 {
   PROF_START (foo);
   if (n)
+ PROF_STOP (foo);
      foo (--n):
   else
     {}
   PROF_STOP (foo);
 }

 This would more probably show you what you want. Or if you want
 to measure total exec time of foo no matter how much recursion,
 wrap or enclose foo() between start/stop outside foo itself.

 btw, is there a way in C to cause any func to exec specified
 code reliably at both func enter and func exit? There are often
 funcs that have many exit points and its pain to place all needed
 prof stops everywhere, but I've found no way around that.

 PS. Profiler is NOT threadsafe. Although its almost safe, no
 thread can ever share probe with any other thread.
 Even though it won't crash probably, it will show beans mostly.

------------------------------------
 Andres Kroonmaa <andre@online.ee>
 CTO, Microlink Online
 Tel: 6501 731, Fax: 6501 725
 Pärnu mnt. 158, Tallinn,
 11317 Estonia
Received on Wed Oct 02 2002 - 02:09:49 MDT

This archive was generated by hypermail pre-2.1.9 : Tue Dec 09 2003 - 16:16:51 MST