Is it possible to setup an Instruments run programmatically from my code? For instance, I'd like to structure my code something like this where startTrace
might setup a specific probe for the current thread and start recording while stopTrace
would stop recording. I would be writing the content of those routines using the Instruments API that is the subject of this question.
-(void)myInterestingMethod
{
[self startTrace];
// do something interesting and performance critical
[self stopTrace];
}
If the above isn't available, is setting up my own DTrace probe a viable alternative?
API instrumentation identifies the time that elapsed during application activities. It is used for applications and products that use the IBM Spectrum Protect API. By default, instrumentation data is automatically collected by the API during backup or restore processing.
Instrumentation refers to the selection or development and the later use of tools to make observations about variables in a research study. The observations are collected, recorded, and used as primary data.
Doesn't look like there's anything straight-forward, but there is an instruments
command-line tool. Here's some quick+dirty code that will invoke it and sample CPU usage for the calling process
static void sampleMe() {
// instruments -t '/Developer/Applications/Instruments.app/Contents/Resources/templates/CPU Sampler.tracetemplate' -p 26838 -l 5000
NSTask *task = [[NSTask alloc] init];
[task setLaunchPath:@"/usr/bin/instruments"];
[task setArguments:[NSArray arrayWithObjects:
@"-t",
@"/Developer/Applications/Instruments.app/Contents/Resources/templates/CPU Sampler.tracetemplate",
@"-p",
[NSString stringWithFormat:@"%ld", getpid()],
@"-l",
@"5000",
nil]];
[task setCurrentDirectoryPath:NSHomeDirectory()];
[task setStandardInput:[NSPipe pipe]];
[task setStandardOutput:[NSPipe pipe]];
[task setStandardError:[NSPipe pipe]];
[task launch];
// purposely leak everything since I can't be bothered to figure out lifetimes
}
After invocation a file named instrumentscli0.trace
will be in your home directory.
Update: Instruments 4.0 offers DTSendSignalFlag in the DTPerformanceSession for iOS apps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With