Using Dtrace for Performance Evaluation
Alexander Leidinger
Alexander at Leidinger.net
Fri May 6 09:04:55 UTC 2011
Quoting David Christensen <davidch at broadcom.com> (from Thu, 5 May 2011
13:08:56 -0700):
> I was looking at using dtrace to help characterize performance
> for the new bxe(4) driver but I'm having problems with the very
> simple task of capturing time spent in a function. The D script
> I'm using looks like the following:
>
> #pragma D option quiet
>
> fbt:if_bxe::entry
> {
> self->in = timestamp;
> }
>
> fbt:if_bxe::return
> {
>
> @callouts[((struct callout *)arg0)->c_func] = sum(timestamp -
> self->in);
> }
>
> tick-10sec
> {
> printa("%40a %10 at d\n", @callouts);
> clear(@callouts);
> printf("\n");
> }
>
> BEGIN
> {
> printf("%40s | %s\n", "function", "nanoseconds per second");
> }
I think there is a more easy way of doing this. I have a script which
wants to do some statistics too (depends upon local changes, but it's
about the D code, not the providers used), it does this:
---snip---
#pragma D option dynvarsize=32m
linuxulator*:::entry
{
self->time[probefunc] = vtimestamp;
@calls[probeprov, execname, probefunc] = count();
}
linuxulator*:::return
/self->time[probefunc] != 0/
{
this->timediff = self->time[probefunc] - vtimestamp;
@stats[probeprov, execname, probefunc] = quantize(this->timediff);
@longest[probeprov, probefunc] = max(this->timediff);
self->time[probefunc] = 0;
}
END
{
printf("Number of calls per provider/application/kernel function:");
printa(@calls);
printf("CPU-timing statistics per provider/application/kernel
function (in ns):");
printa(@stats);
printf("Longest running (CPU-time!) functions per provider (in ns):");
printa(@longest);
}
---snip---
In your case you can forget about probeprov, but the probefunc should
be more convenient to use than the casting and dereferencing you do.
The constraint for the return is there to prevent problems in case one
starts the tracing when a CPU is inbetween entry and return.
Bye,
Alexander.
--
There is a multi-legged creature crawling on your shoulder.
-- Spock, "A Taste of Armageddon", stardate 3193.9
http://www.Leidinger.net Alexander @ Leidinger.net: PGP ID = B0063FE7
http://www.FreeBSD.org netchild @ FreeBSD.org : PGP ID = 72077137
More information about the freebsd-current
mailing list