I'm trying to get the thread name in a dtrace script on OS X.
The script should record the context switches of threads in my application.
#!/usr/sbin/dtrace -s
#pragma D option quiet
BEGIN
{
printf("Start dtrace script: time %ul\n\n", walltimestamp);
}
proc:::exec-success
/ execname == "MyApplication" /
{
trace(execname);
}
sched:::off-cpu
/ execname == "MyApplication" /
{
printf("tid: %ul (%s), off-cpu at: %ul\n", tid, curthread->td_name, walltimestamp);
}
sched:::on-cpu
/ execname == "MyApplication" /
{
printf("tid: %ul, on-cpu at: %ul\n", tid, walltimestamp);
}
But I get the error:
dtrace: failed to compile script dtrace_test.d: line 20: td_name is not a member of struct thread
How can I get the name of the thread?
or analysis I also tried to get the generated intermediate code for my dtrace script (with -S
).
sudo dtrace -s ./dtrace_test.d
But I get the same error:
dtrace: failed to compile script dtrace_test.d: line 20: td_name is not a member of struct thread
I also couldn't find the name in the thread struct
here: http://www.opensource.apple.com/source/xnu/xnu-2050.9.2/osfmk/kern/thread.h
Thx