[dtrace-discuss] Timespent by a function body

michael schuster
Fri, 31 Aug 2007 05:36:52 -0000

Ajit Bansode wrote:
> Hi,
> I want to know the time spent by a function.
> I am using vtimestamp for that but with my script i''m getting
something like this :-
>          func1 ->
>                       func2 ->
>                       func2 <-   56624
>          func1 <-                57899
>
> I want to know the time spent only by func1().
> What can I do for that?

something like

func1:entry
{
	self->s1 = timestamp;
}

func2:entry
{
	self->s2 = timestamp;
}

func2:return
{
	self->d2 = timestamp - self->s2;
}

func1:return
{
	self->d = (timestamp - self->s1) - self->d2;
}

you''ll have to put in proper predicates and zero out the temporary
variables, but I guess you get the idea. For nested funcN, N > 2, this
gets a bit trickier, but we''ll leave that as an exercise to the reader
;-)

(I haven''t tested this, btw ... makes things much more fun, right?)

HTH
Michael

--
Michael Schuster	Sun Microsystems, Inc.
recursion, n: see ''recursion''