Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 22 Jan 2013 19:03:16 -0500
From:      Ryan Stone <rysto32@gmail.com>
To:        Yuri <yuri@rawbw.com>
Cc:        FreeBSD Hackers <hackers@freebsd.org>
Subject:   Re: Why DTrace sensor is listed but not called?
Message-ID:  <CAFMmRNxvLU4WA7uV3TkixEz6vh8NDc%2BARM_b2d8igHAMXKy-EQ@mail.gmail.com>
In-Reply-To: <50FEEB6C.7090303@rawbw.com>
References:  <50FEEB6C.7090303@rawbw.com>

next in thread | previous in thread | raw e-mail | index | archive | help
On Tue, Jan 22, 2013 at 2:41 PM, Yuri <yuri@rawbw.com> wrote:

> I tried to create my own DTrace sensors (for debugging purposes) through
> adding of the simple function like this:
> static u_int
> xxx_my_trace(int arg) {
>   return 1;
> }
>
> It is listed in dtrace -l with its entry and return sensors.
>  8143        fbt            kernel                 xxx_my_trace entry
>  8144        fbt            kernel                 xxx_my_trace return
> This function is called, I know for sure because it is called from another
> procedure which does get traced by DTrace.
> However, these sensors are never triggered when run through dtrace(1M)
> #!/usr/sbin/dtrace -s
> ::xxx_my_trace:entry
> {
>   printf("xxx_my_trace");
> }
> It does print the following, but nothing else:
> dtrace: script './dt.d' matched 1 probe
>
> Adding __attribute__((noinline)) doesn't help.
>
> What is the problem? Why dtrace sensors aren't invoked?
>

Offhand, I can't of why this isn't working.  However there is already a way
to add new DTrace probes to the kernel, and it's quite simple, so you could
try it:

/* The headers that you need to include. */
#include "opt_kdtrace.h"
#include <sys/kernel.h>
#include <sys/sdt.h>

/* Declare a DTrace provider */
SDT_PROVIDER_DEFINE(your_provider);

/*
 * Declare the DTrace probe
your_provider:your_module:your_function:your_probe.  You may
 * leave your_module or your_function blank.  Most Solaris probes do, like
sched:::dequeue.
 * We declare this probe to take 1 argument (DEFINE1) of type int.
 *
 * probe_uniquifier can be chosen arbitrarily if you like, but convention
is to make it the same
 * as your_probe.  The exception is if your-probe contains a character that
is not valid in a C
 * (like a -, as in sched:::on-cpu).  In that case the invalid character is
usually replaced with an
 * underscore.
*/
SDT_PROBE_DEFINE1(your_provider, your_module, your_function,
probe_uniquifier, your_probe, "int");


To call a probe:

SDT_PROBE1(your_provider, your_module, your_function, probe_uniquifier,
my_int_arg);

(There is a wiki page on this, but it is out of date.  I will clean it up).

Your D script would look like:
#!/usr/sbin/dtrace -s
your_provider:your_module:your_function:your_probe
{
  printf("xxx_my_trace");
}



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?CAFMmRNxvLU4WA7uV3TkixEz6vh8NDc%2BARM_b2d8igHAMXKy-EQ>