Here's a quick DTrace script to average out the time spent in each routine called by a given function:
#!/usr/sbin/dtrace -s
pid$target:a.out:$1:entry
{
self->trace = 1;
}
pid$target:a.out::entry
/self->trace/
{
self->ts[probefunc] = timestamp;
}
pid$target:a.out::return
/self->ts[probefunc] != 0/
{
@[probefunc] = avg(timestamp - self->ts[probefunc]);
self->ts[probefunc] = 0;
}
pid$target:a.out:$1:return
/self->trace/
{
self->trace = 0;
exit(0);
}
Here's a sample output:
# dtrace -s ./avg_time.d -c ./foo main
This little program has main() calling foo(), which invokes bar() a number of times. The output above shows the two first routines are taking most of the time, as expected.C
PU ID FUNCTION:NAME
7 67401 main:return
bar 10085098
foo 1009412287
main 1009420500
No comments:
Post a Comment