dtrace OS X线程名称

时间:2016-02-02 23:05:45

标签: macos dtrace

我试图在OS X上的dtrace脚本中获取线程名称。

脚本应记录我的应用程序中线程的上下文切换。

#!/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); 
}

但我收到错误:

dtrace: failed to compile script dtrace_test.d: line 20: td_name is not a member of struct thread

如何获取主题的名称?

或分析我也尝试为我的dtrace脚本(-S)获取生成的中间代码。

sudo dtrace -s ./dtrace_test.d

但是我得到了同样的错误:

dtrace: failed to compile script dtrace_test.d: line 20: td_name is not a member of struct thread

我也无法在thread struct这里找到名称:http://www.opensource.apple.com/source/xnu/xnu-2050.9.2/osfmk/kern/thread.h

THX

0 个答案:

没有答案