objective-c - 在 DTrace 输出中显示 Objective-C 类

标签 objective-c macos 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
...

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

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

其中 classX 是正确的类。

输出应该仍然是缩进的,并且只包含 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);
}

关于objective-c - 在 DTrace 输出中显示 Objective-C 类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16238845/

相关文章:

c - dtracing 一个短暂的应用程序

ios - .xib 文件名在创建包时更改为 ~iphone.nib

php - iOS 使用 http post/get 从 tableView 远程删除行

objective-c - 如何使用 Parse 中的查询检查值是否存在于 2 个不同的字段中?

python - 如何在Python3.6上使用virtualenv在mac上安装psycopg2?

ios - 编译项目时出现 Xcode 错误

macos - 加密失败跨平台

swift - Abysmal Metal 渲染速度

macos - Mac OSX : Using dtruss?