Basant Kukreja
How dtrace have no impact on performance when probes are not in use.
#include <stdio.h>
#include <unistd.h>
#include <sys/sdt.h>
void func()
{
DTRACE_PROBE(firsttestapp, query__func);
}
int main()
{
int i = 0;
for(i = 0; i < 100; ++i)
{
func();
sleep(2);
printf("returned from func call\n");
fflush(stdout);
}
}
And a small provider (mytestapp.d):
provider firsttestapp {
probe query__func();
};
In this test application func will be called every 2 seconds. func has a dtrace
probe which doesn't do anything. I compiled my dtrace program using following
steps :
$ cc -c -xarch=generic -g testapp.c
$ dtrace -G -32 -s mytestapp.d testapp.o
$ cc -xarch=generic -g mytestapp.o testapp.o -o testapp
$ dbx ./testapp
(dbx) dis func
0x00011410: func : save %sp, -96, %sp
0x00011414: func+0x0004: nop
0x00011418: func+0x0008: nop
0x0001141c: func+0x000c: ret
Notice that function "func" doesn't have any instruction. It has two nop
instructions. Let us run the application and run a dtrace program from other
terminal which uses this probe and see what happens to the application during
runtime.
bash-3.00# dtrace -l | grep testapp
61026 firsttestapp26498 testapp func query-func
# dtrace -n 'firsttestapp*::func:query-func { @[probefunc] = count(); }'
dtrace: description 'firsttestapp*::func:query-func ' matched 1 probe
(dbx) dis func
0x00011410: func : save %sp, -96, %sp
0x00011414: func+0x0004: nop
0x00011418: func+0x0008: ta %icc,0x00000038
0x0001141c: func+0x000c: ret
0x00011420: func+0x0010: restore
Notice that 1 of the nop is now replaced with trap instruction "ta %icc,". So
when probes are used "nop" instruction is replaced with a trap instruction.
When probes are not in use, it is simply a nop instruction. This is the reason
that probes have no runtime impact on performance of applications when they are
not in use.
Posted at
05:51PM Jul 30, 2008
by Basant Kukreja in technical |
Comments[2]
Wednesday Jul 30, 2008
So is it thread safe? and how?
I mean changing the nops for ta %icc,0x00000038.
Posted by CarlOS on October 12, 2008 at 11:55 AM PDT #
Yes, dtrace probes are thread safe.
Posted by Basant on November 07, 2008 at 07:07 PM PST #