3

使用以下 DTrace 脚本,我可以获得接近我想要的输出:

$ cat script.d
objc$target:::entry {}
objc$target:::return {}
$ sudo dtrace -F -s script.d -c /Applications/TextEdit.app/Contents/MacOS/TextEdit
dtrace: script 'script.d' matched 105896 probes
CPU FUNCTION
  0  -> +load
  0  <- +load
  0  -> +load
  0  <- +load
  0  -> +load
  0  <- +load
  0  -> +load
  0  <- +load
  0  -> +initialize
  0  <- +initialize
  0  -> +alloc
  0    -> +allocWithZone:
  0      -> +self
  0      <- +self
  0      -> +initialize
  0      <- +initialize
  0      -> +initialize
  0      <- +initialize
  0      -> +initialize
  0      <- +initialize
  0      -> +__new:::
  0      <- +__new:::
  0      -> +immutablePlaceholder
  0      <- +immutablePlaceholder
  0    <- +allocWithZone:
  0    -> -initWithObjects:count:
  0      -> +__new:::
  0      <- +__new:::
  0      -> +initialize
  0      <- +initialize
  0      -> +new
  0        -> +alloc
...

我希望输出包含调用的类,所以它会像这样:

dtrace: script 'script.d' matched 105896 probes
CPU FUNCTION
  0  -> +[classX load]
  0  <- +[classX load]
...

classX正确的班级在哪里。

输出仍然应该是缩进的,并且只包含 Objective-C 消息而不是 C 函数调用。

4

2 回答 2

6

我做了一个脚本,它正是我想要的:

#!/usr/bin/env dtrace -s
#pragma D option quiet

unsigned long long indention;

objc$target:::entry
{
    method = (string)&probefunc[1];
    type = probefunc[0];
    class = probemod;
    printf("%*s%s %c[%s %s]\n", indention, "", "->", type, class, method);
    indention++;
}
objc$target:::return
{
    indention--;
    method = (string)&probefunc[1];
    type = probefunc[0];
    class = probemod;
    printf("%*s%s %c[%s %s]\n", indention, "", "<-", type, class, method);
}
于 2013-04-26T18:15:40.940 回答
2
#!/usr/sbin/dtrace -s
#pragma D option flowindent
objc$target:::entry,
objc$target:::return
{
    trace(probemod);
}

来自Colin WheelerDebugging Cocoa with DTrace

于 2013-07-10T16:43:45.027 回答