1

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

Community
  • 1
  • 1
woodtluk
  • 935
  • 8
  • 20
  • How does your script look like? Which provider/probe do you try to use. Note that dtrace scripts are not in all case portable between Solaris, OS X and FreeBSD. – Hardy Feb 04 '16 at 22:11
  • You wrote that you get an error with `-S`, but you didn't actually write which error you get. – hmijail Aug 04 '16 at 07:48

0 Answers0