Using the following DTrace script, I can get an output that is close to what I want:
$ 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
...
I would like the output to include the class called, so it would like something like this:
dtrace: script 'script.d' matched 105896 probes
CPU FUNCTION
0 -> +[classX load]
0 <- +[classX load]
...
where classX
is the correct class.
The output should still be indentend and only include Objective-C messages and not C function calls.
I made a script, which does exactly what I want:
#!/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);
}
#!/usr/sbin/dtrace -s
#pragma D option flowindent
objc$target:::entry,
objc$target:::return
{
trace(probemod);
}
From Colin Wheeler's Debugging Cocoa with DTrace.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With