如何从Mac OS X上的命令行个人资料? [英] How to profile from the command line on Mac OS X?

查看:135
本文介绍了如何从Mac OS X上的命令行个人资料?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用命令行工具来分析C / C ++ code Mac OS X上,我使用 -pg 选项海湾合作委员会运行 gprof的在Linux上,但我似乎无法找到 gprof的在Mac上,即使我在这个页面的描述:<一href=\"https://developer.apple.com/library/ios/documentation/Performance/Conceptual/PerformanceOverview/PerformanceTools/PerformanceTools.html\"相对=nofollow>其他命令行工具(IOS)或<一个href=\"https://developer.apple.com/library/mac/documentation/Performance/Conceptual/PerformanceOverview/PerformanceTools/PerformanceTools.html\"相对=nofollow>其他命令行工具(MAC)。

I'm trying to profile C/C++ code on Mac OS X using command line tools, I use -pg option with gcc to run gprof on Linux, but I can't seem to find the gprof on Mac even though I have a description in this page: Additional Command-Line Tools (iOS) or Additional Command-Line Tools (mac).

gprof:Produces execution profiles based on an execution analysis of a program.

我安装的命令行工具,所以其他的命令行工具,如 otool ATOS 可用。我用Google搜索找到这个网页(<一个href=\"http://apple.stackexchange.com/questions/154289/installing-gprof-on-mac\">http://apple.stackexchange.com/questions/154289/installing-gprof-on-mac)上面写着 gprof的是不支持的,但我不知道,当我有一个苹果的文档描述工具;反正,我试图用 BREW 下载 gprof的,但没有奏效。

I installed command line tools, so other command line tools such as otool and atos are available. I googled to find this page (http://apple.stackexchange.com/questions/154289/installing-gprof-on-mac) that says gprof is not supported, but I'm not sure when I have an Apple doc describing the tool; anyway, I tried to use brew to download gprof, but it didn't work.

我发现试图在Mac ,但我有仪器无输出-t 。我还发现剖析C ++ Mac OS X上,但我不希望打开仪器,因为我想一些自动化的流程,并尽量保持跨平台系统。

I found Attempting to use gprof with C++ code on a Mac, but I have no output with instruments -t. I also found Profiling c++ on mac os x, but I don't want to open Instruments, as I would like to automate some of the processes and try to keep cross platform system.


  • 如何在Mac OS X上使用gprof的?我使用的OS X 10.10。

  • 如何在命令行轮廓,带或不带 gprof的

  • How to use gprof on Mac OS X? I use OS X 10.10.
  • How can I profile from the command line, with or without gprof?

推荐答案

奇怪的是听说有针对OSX没有 gprof的分析器。 OSX认证UNIX和UNIX的探查器 gprof的(基于 PROFIL 系统调用/库函数有:<一个href=\"https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/profil.2.html\" rel=\"nofollow\">https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/profil.2.html).

It is strange to hear that there is no gprof profiler for OSX. OSX is certified unix and the profiler of unix is gprof (based on profil syscall/library function which is there: https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man2/profil.2.html).

有根据<一个与GNU gprof的问题(的binutils的一部分) href=\"http://apple.stackexchange.com/questions/154289/installing-gprof-on-mac\">http://apple.stackexchange.com/questions/154289/installing-gprof-on-mac (2014年,由于Sreekanth Nagareddy用户 - 删除的答案),酿造安装-v的binutils ***此配置中不支持以下子目录:.. LD气gprof的 OSX没有在GNU gprof的自述文件中列出:的http:// $我认为应该;在支持的平台(仅OSF / 1,在SunOS,Solaris和HP-UX上市的C $ c.metager.de /来源/外部参照/ GNU / src目录/ gprof的/ README (2012)在赫德的工作和作品的Linux版本)。

There are problems with GNU gprof (part of binutils) according to http://apple.stackexchange.com/questions/154289/installing-gprof-on-mac (2014; thanks to Sreekanth Nagareddy user - deleted answer), brew install -v binutils "*** This configuration is not supported in the following subdirectories: .. ld gas gprof"; OSX is not listed in GNU gprof readme: http://code.metager.de/source/xref/gnu/src/gprof/README (2012) in "Supported Platforms" (only OSF/1, SunOS, Solaris, HP-UX listed; I think it should work on Hurd and works on Linuxes).

但也有BSD实现gprof的的(检查 https://en.wikipedia.org/wiki/ gprof的对历史和参考)。没有试图去得到它运行OSX(没有OSX也被咬的苹果新比1995年台式机和放大器;笔记本电脑)。

But there is also BSD implementation of gprof (check https://en.wikipedia.org/wiki/gprof for history and references). Didn't try to get it running on OSX (have no OSX nor bitten apples newer than 1995 desktop&notebook).

有BSD gprof的不同来源,例如,FreeBSD的版本(<一个href=\"https://github.com/freebsd/freebsd/tree/af3e10e5a78d3af8cef6088748978c6c612757f0/usr.bin/gprof\" rel=\"nofollow\">https://github.com/freebsd/freebsd/tree/af3e10e5a78d3af8cef6088748978c6c612757f0/usr.bin/gprof)或者是古代的4.3BSD原 http://www.retro11.de/ouxr / 43bsd / usr / src目录/ UCB / gprof的/ 。这两个变种没有支持OSX使用的Mach-O格式。

There are different sources of BSD gprof, for example, FreeBSD's version (https://github.com/freebsd/freebsd/tree/af3e10e5a78d3af8cef6088748978c6c612757f0/usr.bin/gprof) or ancient 4.3BSD original http://www.retro11.de/ouxr/43bsd/usr/src/ucb/gprof/. Both variants have no support of Mach-O format used in OSX.

有甚至在达尔文的cctools苹果自己gprof的(基于NetBSD的/ OpenBSD的BSD gprof的)(Darwin是UNIX的部分内核和OSX的用户空间;它是/是/将开放源码):<一HREF =htt​​ps://github.com/LeoTestard/Darwin/tree/master/cct​​ools/gprof相对=nofollow> https://github.com/LeoTestard/Darwin/tree/master/cct​​ools/gprof / https://github.com/darwin-在臂/达尔文-SDK /树/主/ cctools / gprof的 /的 http://src.gnu-darwin.org/src/usr.bin/gprof/gprof.c.html (FreeBSD的code和GNU疯狂的想法的一些老搭配自由的)。

There is even Apple's own gprof (based on BSD gprof from NetBSD/OpenBSD) in cctools of Darwin (Darwin is UNIX part both kernel and user-space of OSX; it is/was/will open-source): https://github.com/LeoTestard/Darwin/tree/master/cctools/gprof / https://github.com/darwin-on-arm/darwin-sdk/tree/master/cctools/gprof / http://src.gnu-darwin.org/src/usr.bin/gprof/gprof.c.html (some older mix of FreeBSD code and GNU crazy ideas of freedom).

gprof的的可用性可能取决于确切的OSX版本或X code版/包;有GPROF为10.6.1,根据 http://louise.hu/poet/gprof-上OSX / 或从2012年,版本 - https://开头rachelbythebay .COM / W / 2012/09/14 / MAC / 或即使在2001年的 http://lists.apple.com/archives/darwin-development/2001/Apr/msg00617.html

The availability of gprof may depend on exact OSX version or Xcode version/packages; there were gprof for 10.6.1, according to http://louise.hu/poet/gprof-on-osx/ or on some version from 2012 - https://rachelbythebay.com/w/2012/09/14/mac/ or even in 2001: http://lists.apple.com/archives/darwin-development/2001/Apr/msg00617.html

有是一个使用仪器变种(X code工具的一部分?)的命令行,不知道究竟怎么了,但知道是乐器现代化的,功能丰富的分析工具。

There is variant of using instruments (part of Xcode Tools?) in command-line, don't know how exactly, but know that instruments is modern and feature-rich profiler.

还有 iprofiler 命令行界面来收集配置文件 Instruments.app <​​/ code>,刚刚提到的手册页它<一个href=\"https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/iprofiler.1.html\" rel=\"nofollow\">https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/iprofiler.1.html (第X code Tools版本5.0的一部分;从现场遗留的部分联机帮助页)。

There is also iprofiler command-line interface to collect profiles for Instruments.app, just noted man page of it https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/iprofiler.1.html (part of Xcode Tools version 5.0; manpage from legacy part of site).

有第三方廓线仪,宣布支持OSX。我知道他们两个:Valgrind的和gperftools(谷歌perftools)

There are third-party profilers, declared to support OSX. I know two of them: valgrind and gperftools (google-perftools).

Valgrind是不是一个分析器;这是一个(慢)动态检测平台内置在它上面的很多工具。它包括两个工具,能够分析的: callgrind cachegrind 。 Valgrind的和这两种工具都没有原生探查,他们这样做,因为它会在现实生活中真正的CPU运行没有配置文件应用程序。相反,Valgrind的虚拟机和callgrind / cachegrind工具机code与计数器上执行的程序。

valgrind is not a profiler; it is a (slow) dynamic instrumentation platform with many tools built on top of it. It includes two tools, capable of profiling: callgrind and cachegrind. Valgrind and both tools are not native profiler, they do not profile application as it will run on real cpu in real life. Instead, valgrind executes program on the virtual machine and callgrind/cachegrind instruments machine code with counters.

callgrind( http://valgrind.org/docs/manual/cl-manual。 HTML )使用每个指令线性块计数器计数每个指令多少次执行(IR事件,用于获取配置文件 - 所用时间的百分比排序功能);它也记录来电/返回到调用图构建。 IR事件计数是正确的得到执行指令数(也可能效仿分支prediction);但它不能被用来估计实际运行时间。真正的CPU(高性能的CPU被称为超标量,乱序CPU是超标量太)能够执行每个CPU时钟周期多个指令;并且还常常不能执行任何指令,因为他们可能希望有的数据将被启动(从远缓存或从存储器或从系统调用或从其它高延迟指令的数据;或CPU误predicted分支导向指令地址没有读/德codeD)。最先进的CPU甚至可能无法执行某些命令(有些可以执行多达8 NOP 每个周期S,几个英特尔Sandy /常春藤桥和更新将不会花费任何时间 XOR EAX,EAX 写零到寄存器,它们只是重新映射下一个寄存器使用情况,以零物理寄存器)。 callgrind有分析运行相比,在硬件上CPU实际运行典型的10-20放缓。

callgrind (http://valgrind.org/docs/manual/cl-manual.html) uses counter per linear block of instructions to count "how many times every instruction will be executed" ("Ir" event, used to get profile - sort functions by percent of time used); it also records calls/returns to build callgraph. "Ir" event count is correct to get instruction execution counts (it may also emulate branch prediction); but it can't be used to estimate real running time. Real cpu (high performance cpus called superscalar; out-of-order cpus are superscalar too) able to execute more than one instruction per cpu clock cycle; and it is also often incapable of executing any instruction because they may want some data to be started (data from far cache or from memory or from syscall or from other high-latency instruction; or cpu mispredicted branch leads to instruction address not yet read/decoded). Most progressive cpus may even not execute some commands (some can execute up to 8 "nop"s per cycle, several Intel's Sandy/Ivy Bridges and newer will not spend any time on "xor eax,eax" to write zero into register; they just remap next register usage to zeroed physical register). callgrind has typical 10-20 slowdown on profiling run compared to real run on hardware CPU.

Cachegrind实现相同的仪器如callgrind(IR,分支),但是也可以模拟高速缓存层次(高速缓冲存储器的加载/存储/射门事件)。它比callgrind慢。

Cachegrind implements same instrumentation as callgrind ("Ir", branches), but also can emulate cache hierarchy (cache loads/stores/misses events). And it is slower than callgrind.

这callgrind和cachegrind输出可以用GUI工具KCacheGrind调试( http://kcachegrind.sourceforge.net/,它可能会在OS),或在命令行工具 callgrind_annotate

Output from callgrind and cachegrind can be viewed with GUI tool kcachegrind (http://kcachegrind.sourceforge.net/, it may work in OS) or in command-line tool callgrind_annotate.

其他的工具是gperftools(谷歌perftools, https://github.com/gperftools/gperftools ),其运行于真实的CPU的程序。要使用它,用自制软件安装,然后用libprofiler链接程序(添加 -Lpath_to_installed_gperftools -lprofiler )和 CPUPROFILE 环境变量设置为某个文件名( CPUPROFILE = profile01 ./the_program)。它将使用间隔定时器( setitimer函数)和输出分析数据的文件名,在 CPUPROFILE 的环境变量定义的配置方案。然后,你可以在命令行或SVG / Web浏览器使用 pprof perl脚本从gperftools查看配置文件数据( pprof ./the_program profile01`)

Other tool is gperftools (google-perftools, https://github.com/gperftools/gperftools), which run the program on real CPU. To use it, install it with homebrew, then link the program with libprofiler (add -Lpath_to_installed_gperftools -lprofiler) and run with CPUPROFILE environment variable set to some filename (CPUPROFILE=profile01 ./the_program). It will profile the program using interval timer (setitimer) and output profiling data to the filename, defined inCPUPROFILEenv var. Then you can view profile data in command-line or with svg/web browser usingpprofperl script from gperftools (pprof ./the_program profile01`).

这篇关于如何从Mac OS X上的命令行个人资料?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆