Focus Of Energy

The atoms bouncing in my head
Friday Sep 07, 2007

A simple DTrace USDT example

When I started out trying to make a USDT for MPI I found I had to go around and look at several snippits and poke my eye with a stick several times before I got something at a basic level to work.  So, I've decided to post a simple example of making a USDT that shows the code, compilation lines, D script and how to execute.

I have a simple C program that will call a routine in a separate object. This object has a probe in it that I want to attach to later.  The probe will take a string.  The resulting code follows:

 ---------main.c------------

void main() {
   dprintf();
}

---------debug.c------------

void
dprintf()
{

  DTRACE_PROBE1(mpi__test, DEBUG_MESSAGE, "hi");
}
--------usdt.d-------------
provider mpi__test {
        probe DEBUG_MESSAGE(string);
};

To compile the program, separate object and provider you do the following in this order:

 

  1.  cc -c debug.c
  2. dtrace -G -32 -s usdt.d debug.o
  3. cc -o main main.c usdt.o debug.o

 To use the probe:

% dtrace -c main -n 'mpi__test$target::: { printf("here"); }'
dtrace: description 'mpi__test$target::: ' matched 1 probe
dtrace: pid 180 has exited
CPU     ID                    FUNCTION:NAME
  0    433            dprintf:DEBUG_MESSAGE here

 

Now to see the argument passed into the probe by the program:

% dtrace -c main -n 'mpi__test$target::: { printf("%s", copyinstr(arg0)); }'
dtrace: description 'mpi__test$target::: ' matched 1 probe
dtrace: pid 186 has exited
CPU     ID                    FUNCTION:NAME
  2    433            dprintf:DEBUG_MESSAGE hi

 


Comments:

Post a Comment:
  • HTML Syntax: NOT allowed

Archives
General Links
ClusterTools Team Members
blogs.sun.com Links
Referrers