tags:

views:

9

answers:

1

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.

A: 

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.

Kevin Ballard
That's perfect. Thanks, Kevin!
George