File: dtrace.md

package info (click to toggle)
firefox 143.0.3-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 4,617,328 kB
  • sloc: cpp: 7,478,492; javascript: 6,417,157; ansic: 3,720,058; python: 1,396,372; xml: 627,523; asm: 438,677; java: 186,156; sh: 63,477; makefile: 19,171; objc: 13,059; perl: 12,983; yacc: 4,583; cs: 3,846; pascal: 3,405; lex: 1,720; ruby: 1,003; exp: 762; php: 436; lisp: 258; awk: 247; sql: 66; sed: 53; csh: 10
file content (49 lines) | stat: -rw-r--r-- 1,752 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# dtrace

`dtrace` is a powerful Mac OS X kernel instrumentation system that can
be used to profile wakeups. This article provides a light introduction
to it.

:::{note}
The [power profiling overview](power_profiling_overview.md) is
worth reading at this point if you haven't already. It may make parts
of this document easier to understand.
:::

## Invocation

`dtrace` must be invoked as the super-user. A good starting command for
profiling wakeups is the following.

```
sudo dtrace -n 'mach_kernel::wakeup { @[ustack()] = count(); }' -p $FIREFOX_PID > $OUTPUT_FILE
```

Let's break that down further.

-   The` -n` option combined with the `mach_kernel::wakeup` selects a
    *probe point*. `mach_kernel` is the *module name* and `wakeup` is
    the *probe name*. You can see a complete list of probes by running
    `sudo dtrace -l`.
-   The code between the braces is run when the probe point is hit. The
    above code counts unique stack traces when wakeups occur; `ustack`
    is short for \"user stack\", i.e. the stack of the userspace program
    executing.

Run that command for a few seconds and then hit [Ctrl]{.kbd} + [C]{.kbd}
to interrupt it. `dtrace` will then print to the output file a number of
stack traces, along with a wakeup count for each one. The ordering of
the stack traces can be non-obvious, so look at them carefully.

Sometimes the stack trace has less information than one would like.
It's unclear how to improve upon this.

## See also

dtrace is *very* powerful, and you can learn more about it by consulting
the following resources:

-   [The DTrace one-liner
    tutorial](https://wiki.freebsd.org/DTrace/Tutorial) from FreeBSD.
-   [DTrace tools](http://www.brendangregg.com/dtrace.html), by Brendan
    Gregg.