问题描述
我正在尝试使用命令行工具在Mac OS X上配置C/C ++代码,我在Linux上使用gcc gcc将-pg选项使用,但我似乎找不到gcc C2>在此页面上我有一个描述,即使在Mac上:附加命令行工具(ios)或附加命令行工具(Mac).
gprof:Produces execution profiles based on an execution analysis of a program.
我安装了命令行工具,因此可以使用其他命令行工具,例如otool和atos.我谷歌搜索以找到此页面( -gprof-on-mac )就是不支持gprof,但是我不确定何时有一个苹果文档描述该工具;无论如何,我尝试使用brew下载gprof,但它不起作用.
我找到了尝试在Mac上使用C ++代码使用GPROF ,但是我没有instruments -t的输出.我还找到了 mac os X 为了打开仪器,我想自动化一些过程并尝试保持跨平台系统.
- 如何在Mac OS X上使用GPROF?我使用OS X 10.10.
- 我如何从命令行中进行介绍,无论有没有gprof?
推荐答案
听到OSX没有gprof profiler,这很奇怪. OSX经认证的UNIX,UNIX的profiler为gprof(基于profil SYSCALL/LIBLIST函数,该功能: https://developer.apple.com/lebibacy/library/documentation/darwin/darwin/reference/reference/manpages/manpages/man2/profil.2.html ).
根据 https:https:https://苹果,Gnu Gprof(Binutils的一部分)存在问题. stackexchange.com/questions/154289/installing-gprof-on-mac (2014;感谢Sreekanth nagareddy用户 - 删除答案),brew install -v binutils" *** ***此配置在以下子目录中不支持此配置: . OSX未在Gnu Gprof readme中列出: .在Linuxes上).
但也有BSD实现Gprof(check /gprof 用于历史和参考).没有试图在OSX上运行它(没有OSX也没有比1995年桌面和笔记本的新苹果).
有不同来源的BSD Gprof来源,例如FreeBSD的版本( https://github.com/freebsd/freebsd/tree/af3e10e5a78d3af8cef608748748748978c61275757f0/usr.bin/gprof )/usr/src/ucb/gprof/" rel =" nofollow noreferrer"> http://www.retro11.de/ouxr/43bsd/43bsd/usr/src/src/ucb/gprof/.这两个变体都不支持OSX中使用的MACHO格式.
甚至还有苹果自己的gprof(基于netbsd/openBSD的BSD Gprof),darwin的cctools(darwin是unix part of osx of osx;它是/ward will open-will open-source): https://github.com/leotestard.com/leotestard/leotestard/darwin/darwin/tree/tree/master/master/cctools/gprof / https://github.com/darwin-on-arm/darwin-sdk/tree/master/cctools/gprof / http://louise.hu/poet/poet/gprof -on -osx/或在2012年以来的某些版本上 - https:https:///rachelbythebay.com/w/2012/09/14/mac/ 甚至在2001年: https://develoverer.apple.com/legacy/library/documentation/darwin/darwin/reference/reference/reference/manpages/manpages/man1/iprofiler.1/iprofiler.1.html (Xcode工具版本5.0的一部分;来自网站的传统部分的manpage).
有第三方剖道师,宣布支持OSX.我知道其中两个:Valgrind和Gperftools(Google-Perftools).
valgrind不是探查者;这是一个(缓慢的)动态仪器平台,其顶部构建了许多工具.它包括两个能够分析的工具:callgrind和cachegrind. Valgrind和这两个工具都不是本地剖面,它们不介绍应用程序,因为它将在现实生活中运行在Real CPU上.取而代之的是,Valgrind在虚拟机上执行程序,并带有计数器的CallGrind/Cachegrind Instruments机器代码.
cachegrind与Callgrind(" IR",分支)实现相同的仪器,但也可以模拟高速缓存层次结构(CACHE LOADS/Store/Misses Events).它比CallGrind慢.
Output from callgrind and cachegrind can be viewed with GUI tool kcachegrind (http://kcachegrind.sourceforge.net/,它可以在OS中使用)或命令行工具callgrind_annotate.
其他推荐答案
在我的sperate问题(Crazypython)上,我能够在@OSGX的帮助下使用Gperftools(pprof). 在这里是问题,在这里是脚本的Github Gist.为了方便起见,这是脚本内联:
#!/usr/bin/env bash # Licensed under the Unlicense. Full text at (http://unlicense.org/) - CrazyPython g++ -std=c++11 $1 -o ./.executables/profiler/$(basename $1 .cpp) -g -O -lprofiler echo "Finished compiling + linking" CPUPROFILE=$1.out ./.executables/profiler/$(basename $1 .cpp) ./.executables/profiler/$(basename $1 .cpp) pprof ./.executables/profiler/$(basename $1 .cpp) $1.out
警告:我试图将其清理一点.它可能包含许多不必要的选项.