Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 06 May 2011 11:04:36 +0200
From:      Alexander Leidinger <Alexander@Leidinger.net>
To:        David Christensen <davidch@broadcom.com>
Cc:        "freebsd-current@freebsd.org" <freebsd-current@freebsd.org>
Subject:   Re: Using Dtrace for Performance Evaluation
Message-ID:  <20110506110436.167568wcm6sjlt44@webmail.leidinger.net>
In-Reply-To: <5D267A3F22FD854F8F48B3D2B523819360D799A42B@IRVEXCHCCR01.corp.ad.broadcom.com>
References:  <5D267A3F22FD854F8F48B3D2B523819360D799A42B@IRVEXCHCCR01.corp.ad.broadcom.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Quoting David Christensen <davidch@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@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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110506110436.167568wcm6sjlt44>