在Mac OS X上分析C ++ [英] Profiling c++ on mac os x
问题描述
我正在尝试在Mac(OS X Lion)上分析一些c ++代码,但找不到任何有用的东西.我正在寻找一个探查器,该探查器将告诉我哪些功能占用了我的CPU时间(类似于matlab探查器).
I'm attempting to profile some c++ code on my mac (os x Lion) and I haven't been able to find anything useful. I'm looking for a profiler that will tell me what functions are taking up my cpu time (similar to the matlab profiler).
这是我尝试过的
- gprof.这就是我在linux机器上使用的,但是它只是在Mac上给了我空的输出(显然是一个已知问题)
- 仪器.我一辈子都无法弄清楚如何在已编译的二进制文件中分析任何内容.我也找不到任何有用的教程.
- (其他搜索显示Shark(不再可用)和Valgrind(用于存储)).
真的很感谢您的帮助!
推荐答案
Instruments是要使用的工具.关于Instruments的完整说明不在此答案的范围内,但是这里有一个快速入门指南:
Instruments is the tool to use. A full explanation of Instruments is outside the scope of this answer, but here's a quick start guide:
- 打开工具. 1
- 选择时间分析器"模板.
- 在目标"(Target)下拉菜单中选择您的应用程序. 2
- 点击红色圆圈(记录")按钮开始运行您的应用程序.
- 如果适用,在您的应用程序中做一些您需要分析的事情.
- 再次点击录制按钮以停止录制.
- 使用Instruments中的工具分析您的结果.
- Open Instruments.1
- Select the "Time Profiler" template.
- Select your application in the "Target" dropdown menu.2
- Hit the red circle ("record") button to start your application running.
- If applicable, do some stuff in your application that you need to profile.
- Hit the record button again to stop recording.
- Use the tools in Instruments to analyze your results.
在可用工具中,最常用的工具是:
Of the tools available, the ones that will be most frequently useful are:
- 使用公开箭头扩展呼叫树
- 单击函数名称上带圆圈的箭头以使其聚焦
- 双击一个函数以查看关联的源
- 左侧的反转通话树"复选框
您还可以启动instruments on the command line, ex
仪器-l 30000 -t Time \ Profiler -p 5773`的调用,请参见
You can also start an invocation of instruments on the command line, ex
instruments -l 30000 -t Time\ Profiler -p 5773` see instructions.
1 打开乐器的一种简单方法是使用Spotlight:只需单击任务栏右上角的放大镜(时钟旁边),然后键入乐器" .
1 One easy way to open Instruments is to use Spotlight: Just click on the magnifying glass in the upper right corner of the taskbar (next to the clock) and type "Instruments".
2 单击选择目标..."并导航到可执行文件的路径.
2 Click "Choose Target..." and navigate to the path of your executable.
这篇关于在Mac OS X上分析C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!