是否可以从我的代码中以编程方式设置仪器?例如,我想构建我的代码,其中startTrace可能为当前线程设置特定探测并开始录制,而stopTrace将停止录制.我将使用作为此问题主题的Instruments API编写这些例程的内容.
-(void)myInterestingMethod { [self startTrace]; // do something interesting and performance critical [self stopTrace]; }
如果上述代码不可用,那么设置我自己的DTrace探针是否可行?
解决方法
看起来没有任何直接的东西,但有一个仪器命令行工具.这是一些快速脏代码,它将调用它并为调用进程提供CPU使用率示例
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 }
调用后,名为instrumentscli0.trace的文件将位于您的主目录中.
更新:Instruments 4.0在DTPerformanceSession for iOS应用程序中提供了DTSendSignalFlag.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。