问题描述
在Xcode的仪器中,有一个名为 Counters Counters 公开CPU提供的低级计数器信息,例如执行的指令数或高速缓存未命中数:
In Xcode's Instruments, there is a tool called Counters that exposes low-level counter information provided by the CPU, such as the number of instructions executed or number of cache misses:
这类似于Linux 2.6中引入的Linux系统调用 perf_event_open
. 32.在Linux上,我可以使用perf_event_open
然后在我感兴趣的代码部分周围进行启动/停止分析.我想在OS X上记录相同类型的统计信息:计算与一定的代码量,并以自动化的方式获得结果. (我不想使用Instruments GUI来分析数据.)
This is similar to the Linux syscall perf_event_open
introduced in Linux 2.6.32. On Linux, I can use perf_event_open
then start/stop profiling around the section of my code I'm interested in. I'd like to record the same type of stats on OS X: counting the instructions (etc.) that a certain piece of code takes, and getting the result in an automated fashion. (I don't want to use the Instruments GUI to analyze the data.)
是否有任何API允许这样做(例如:使用dtrace或类似的工具)?通过一些搜索,听起来好像私有的AppleProfileFamily.framework可能具有必要的钩子,但是尚不清楚如何链接或使用它.
Are there any APIs that allow this (ex: using dtrace or similar)? From some searching it sounds like the private AppleProfileFamily.framework might have the necessary hooks, but it's unclear how to go about linking to or using it.
推荐答案
在GNU/Linux中,我使用Intel的PCM来监视CPU利用率.我不确定这在OSX上是否能正常工作,但据我所知,源代码中包括MacMSRDriver目录.我没有任何OSX设备,无论如何都不要对其进行测试.
In GNU/Linux I use Intel's PCM to monitor CPU utilization. I'm not sure if this works fine on OSX, but as far as I know the source-code is including the MacMSRDriver directory. I have no any OSX device, never test it anyway.
如果此源文件已在您的设备上编译,请运行:
In case this source compiled on your device, Just run:
pcm.x -r -- your_program your_program_parameter
,或者如果您想进行高级分析,请改用pcm-core.x
,或者您可以基于pcm-core.cpp
or if you want advanced profiling, use pcm-core.x
instead or you can build your own code based on pcm-core.cpp
这篇关于在没有仪器的情况下,在OS X上记录性能监视器计数器(PM事件)的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!