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 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.

Run that command for a few seconds and then hit Ctrl + C 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: