I've create a profiling profile in Instruments.app from the blank template, and I'd like to use it to profile a command line program. The problem is that the program exits rather quickly (in a matter of seconds), which means I can't simply select it in the Instruments process dropdown to attach to it while it's running.
Is there a way to use an existing Instruments profile while launching a command line application, and start collecting data immediately, instead of attaching to a running process?
I do not have an Xcode project, or even the source code. I simply want to attach to an existing application right after it starts up. If it is relevant I'm using Instruments 6.1 on OS X Yosemite.
If there was a way to somehow start the profiling directly from the command line, and not from the Instruments GUI, that would be even better, but I'm not sure if such thing is possible.
Build a command line executable with debug symbols enabled:
gcc -Wall -g -O3 profile_me.c -o profile_me
Launch Instruments, select Time Profiler
.
Choose target...
from the hierarchical menu to the right.Choose target
dialog, navigate to your executable and select it. Also set any command line options, environment variables, and the working directory, if needed.Choose
button to save the target options and dismiss the Choose target
dialog - you should now see the target name to the right of your machine name in the top left corner of the Time Profiler window: