Adding Probes to Application Code

After you define your probes in a .d file, you then augment your source code to indicate the locations that should trigger your probes. For example:

void
main_look(void)
{
        ...
        query = wait_for_new_query();
        process_query(query)
        ...
}

To add a probe site, add a reference to the DTRACE_PROBE() macro defined in <sys/sdt.h> as shown in the following example:

...
void
main_look(void)
{
        ...
        query = wait_for_new_query();
        DTRACE_PROBE2(myserv, query__receive, query->clientname, query->msg);
        process_query(query)
        ...
}

The suffix 2 in the macro name DTRACE_PROBE2 refers to the number of arguments that are passed to the probe. The first two arguments to the probe macro are the provider name and probe name and must correspond to your D provider and probe definitions. The remaining macro arguments are the arguments assigned to the DTrace arg0..9 variables (or the args[] array) when the probes fire. The application source code can contain multiple references to the same provider and probe name. If multiple references to the same probe are present in the source code, any of the macro references will cause the probe to fire.