On Tue, Jan 22, 2013 at 2:41 PM, Yuri <y...@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");
}
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscr...@freebsd.org"

Reply via email to