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 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 pointmach_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 + 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:

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据

词条统计

浏览:99 次

字数:2268

最后编辑:6 年前

编辑次数:0 次

    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文