objective-c – 有一个Instruments API吗?

objective-c – 有一个Instruments API吗?,第1张

概述是否可以从我的代码中以编程方式设置仪器?例如,我想构建我的代码,其中startTrace可能为当前线程设置特定探测并开始录制,而stopTrace将停止录制.我将使用作为此问题主题的Instruments API编写这些例程的内容. -(void)myInterestingMethod{ [self startTrace]; // do something interestin 是否可以从我的代码中以编程方式设置仪器?例如,我想构建我的代码,其中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.

总结

以上是内存溢出为你收集整理的objective-c – 有一个Instruments API吗?全部内容,希望文章能够帮你解决objective-c – 有一个Instruments API吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1001138.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存