static user probes

Stan Cox scox@redhat.com
Thu Oct 2 21:33:00 GMT 2008


Here is an example of dtrace static defined tracing probes and a stap 
mockup doing something similar using uprobes.

Makefile:
CC=/usr/sfw/bin/gcc
DTRACE=/usr/sbin/dtrace
hello: helloprobes.o hello.o
         $(CC) -o hello helloprobes.o hello.o
helloprobes.o: hello.o
         $(DTRACE) -G -s helloprobes.d hello.o
         dis hello.o > hello.2.dis
hello.o:
         $(CC) -c hello.c
         dis hello.o > hello.1.dis

helloprobes.d:
provider hello {
    probe printDemo(char*);
};

hellotest_.d:
BEGIN {
    self->ts = walltimestamp;
}
demo$target:::printDemo
{
    @[arg1]=count();
}
END {
    self->ts = walltimestamp - self->ts;
    printf ("Total time used is (us): %d", (self->ts)/1000);
}

hello.c:
void printDemo(char *);
void printD(char *x)
{
    DTRACE_PROBE1(hello, printDemo, x);
}
int
main (void)
{
    long long x = 0;
    long long count = 187;
    for (x = 0; x < count; x++)
       {
        printD("Hello World");
       }
    printf("done %lld iterations\n", x);
}

The dtrace -G step gives you:
-    printD+0xc:          e8 fc ff ff ff     call   -0x4     <printD+0xd>
+    printD+0xc:          90                 nop
+    printD+0xd:          90                 nop
+    printD+0xe:          90                 nop
+    printD+0xf:          90                 nop
+    printD+0x10:         90                 nop

Now run it with probing turned on:
/usr/sbin/dtrace -Zqs ./hellotest_.d -c ./hello
done 187 iterations
Total time used is (us): 1020200


stap mockup:
all: tstlabel.x
stap-probes-tstlabel.c: tstlabel.d tstlabel.c
         python stap-probes.py $^
stap-probes-tstlabel.o: stap-probes-tstlabel.c
         $(CC) $^ -c -g
tstlabel.x: tstlabel.o stap-probes.o stap-probes-tstlabel.o
             $(CC) $^ -o $@
tstlabel.o: tstlabel.c stap-probes.h
             $(CC) tstlabel.c -c
stap-probes.o: stap-probes.c
             $(CC) $^ -c

tstlabel.d:
provider tstlabel {
    probe label1();
    probe label2();
    probe label3(int, char*);
};

tstlabel.c:
foo ()
{
   STAP_PROBE(tstlabel,label1);
}
bar ()
{
   STAP_PROBE(tstlabel,label2);
}
baz ()
{
   STAP_PROBE(tstlabel,label3);
}
main ()
{
   foo();
   bar();
   baz();

stap-probes.py generates tstlabel.c:
_stap_probe_label1 ()
{}
_stap_probe_label2 ()
{}
_stap_probe_label3 (int a, char* b)
{}

tstlabel.stp:
probe process.mark("label1")
{
printf("In label1 probe\n")
}
probe process.mark("label2")
{
printf("In label2 probe\n")
}
probe process.mark("label3")
{
printf("In label3 probe, but there are no args here\n")
}

stap -c /home/scox/stap/1918/tstlabel.x tstlabel.stp
In label1 probe
In label2 probe
In label3 probe, but there are no args here



More information about the Systemtap mailing list