Is there an API?

Is it possible to programmatically run a program from my code? For example, I would like to structure my code in a way where startTrace can configure a specific probe for the current stream and start recording, and stopTrace stop recording. I would write the contents of these routines using the Instruments API, which is the subject of this question.

 -(void)myInterestingMethod { [self startTrace]; // do something interesting and performance critical [self stopTrace]; } 

If the above is not available, does my own DTrace probe set up a viable alternative?

+4
source share
1 answer

It doesn't look like something straightforward, but there is an instrument command line tool. Here is some quick + dirty code that will call it and an example of 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 the call, a file named instrumentscli0.trace will be located in your home directory.

Update: Tools 4.0 offer DTSendSignalFlag in DTPerformanceSession apps for iOS.

+4
source

Source: https://habr.com/ru/post/1332711/


All Articles