Tyi*_*ilo 3 macos objective-c dtrace
使用以下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
...
Run Code Online (Sandbox Code Playgroud)
我希望输出包含所调用的类,所以它想要这样的东西:
dtrace: script 'script.d' matched 105896 probes
CPU FUNCTION
0 -> +[classX load]
0 <- +[classX load]
...
Run Code Online (Sandbox Code Playgroud)
哪里classX是正确的班级.
输出仍然应该是indentend并且只包含Objective-C消息而不包括C函数调用.
我制作了一个脚本,它完全符合我的要求:
#!/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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1410 次 |
| 最近记录: |