现场对 Cocoa 应用程序进行 CPU 分析
我有一个用户抱怨我的应用程序在应该空闲的时候却占用了大量的 CPU 时间。这是 Mac OS Leopard 上的 Cocoa 应用程序。我想做的是让后台线程定期抓取主线程的堆栈跟踪并记录它们。或者,如果我可以让他运行一个命令行程序来获取所有线程的堆栈(或者更好的是,带有 CPU 分析信息的调用图),他可以这样做并将结果发送给我。我知道 XCode 中内置了 CPU 分析功能,但这个问题只能在用户的计算机上重现,因此 XCode 不是一个选项(我不想要求他安装它)。
我找不到可以在 OSX 上转储堆栈跟踪的命令行工具,也找不到用于访问其他线程堆栈的 API。我猜 GDB 可以做到,但这真的很难向用户解释。
I have a user complaining that my app is taking a lot of CPU time when it should be idle. This is a Cocoa app on Mac OS Leopard. What I would love to do is have a background thread periodically grab stack traces of the main thread and log them. Alternatively, if I could have him run a command line program to grab all the threads' stacks (or better yet, a call graph with CPU profiling info), he could do that and send me the results. I know there's CPU profiling built into XCode, but this problem is only reproducible on the user's machine, so XCode is not an option (I don't want to ask him to install it).
I can't find a command line tool that would dump stack traces on OSX, nor can I find an API for accessing other threads' stacks. I guess GDB could do it, but that would be really hard to explain to a user.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
告诉您的用户启动活动监视器(在/Applications/Utilities 中)。在“活动监视器”中,您的用户可以选择与您的应用程序对应的行,然后按工具栏中的“示例”按钮。这将对您的应用程序进行 10 秒的采样。然后他可以将其保存到磁盘并通过电子邮件将文件发送给您。
编辑:如果您想要命令行版本,请查看 /usr/bin/sample。它有效地完成了同样的事情,尽管活动监视器对于最终用户来说应该更容易使用。
Tell your user to launch Activity Monitor (in /Applications/Utilities). In Activity Monitor, your user can select the row corresponding to your application and press the "Sample" button in the toolbar. This will take a 10-second sample of your app. He can then save this to disk and email the file to you.
Edit: If you want a command-line version of this, look at /usr/bin/sample. It does effectively the same thing, though Activity Monitor should be a lot easier for an end-user to use.