gprof

How to profile multi-threaded C++ application on Linux?

自古美人都是妖i 提交于 2019-11-27 17:10:12
I used to do all my Linux profiling with gprof . However, with my multi-threaded application, it's output appears to be inconsistent. Now, I dug this up: http://sam.zoy.org/writings/programming/gprof.html However, it's from a long time ago and in my gprof output, it appears my gprof is listing functions used by non-main threads. So, my questions are: 1) In 2010, can I easily use gprof to profile multi-threaded Linux C++ applications? ( Ubuntu 9.10 ) 2) What other tools should I look into for profiling? Laurynas Biveinis Edit: added another answer on poor man's profiler, which IMHO is better

gprof reports no time accumulated

心不动则不痛 提交于 2019-11-27 14:58:12
I'm trying to profile a C++ application with gprof on a machine running OSX 10.5.7. I compile with g++ in the usual way, but using -pg flags, run the application and try to view the call graph with gprof. Unfortunately my call graph contains all zeroes for all time columns. The values in the "called" columns have reasonable values so it looks like something was profiled but I'm mystified about the lack of other data. All my source files are compiled in a similar way: g++ -pg -O2 -DNDEBUG -I./ -ansi -c -o ScenarioLoader.o ScenarioLoader.cpp I then run 'ar' to bundle all the object files into a

How does gcc's -pg flag work?

爱⌒轻易说出口 提交于 2019-11-27 05:25:24
问题 I'm trying to understand how the -pg (or -p ) flag works when compiling C code with gcc . The official gcc documentation only states: -pg Generate extra code to write profile information suitable for the analysis program gprof. You must use this option when compiling the source files you want data about, and you must also use it when linking. This really interests me, as I'm doing a small research on profilers - trying to pick the best tool for the job. 回答1: Compiling with -pg instruments

How to profile multi-threaded C++ application on Linux?

一个人想着一个人 提交于 2019-11-26 18:50:55
问题 I used to do all my Linux profiling with gprof. However, with my multi-threaded application, it's output appears to be inconsistent. Now, I dug this up: http://sam.zoy.org/writings/programming/gprof.html However, it's from a long time ago and in my gprof output, it appears my gprof is listing functions used by non-main threads. So, my questions are: 1) In 2010, can I easily use gprof to profile multi-threaded Linux C++ applications? (Ubuntu 9.10) 2) What other tools should I look into for

C++的性能优化实践【转】

痞子三分冷 提交于 2019-11-26 18:31:30
原文: http://www.cnblogs.com/me115/archive/2013/06/05/3117967.html 1. 二八法则:在任何一组东西中,最重要的只占其中一小部分,约20%,其余80%的尽管是多数,却是次要的;在优化实践中,我们将精力集中在优化那20%最耗时的代码上,整体性能将有显著的提升;这个很好理解。函数A虽然代码量大,但在一次正常执行流程中,只调用了一次。而另一个函数B代码量比A小很多,但被调用了1000次。显然,我们更应关注B的优化。 2. 编完代码,再优化;编码的时候总是考虑最佳性能未必总是好的;在强调最佳性能的编码方式的同时,可能就损失了代码的可读性和开发效率; 工具: 1 Gprof 工欲善其事,必先利其器。对于Linux平台下C++的优化,我们使用gprof工具。gprof是GNU profile工具,可以运行于linux、AIX、Sun等操作系统进行C、C++、Pascal、Fortran程序的性能分析,用于程序的性能优化以及程序瓶颈问题的查找和解决。通过分析应用程序运行时产生的“flat profile”,可以得到每个函数的调用次数,消耗的CPU时间(只统计CPU时间,对IO瓶颈无能为力),也可以得到函数的“调用关系图”,包括函数调用的层次关系,每个函数调用花费了多少时间。 2. gprof使用步骤 1) 用gcc、g++

gprof reports no time accumulated

╄→尐↘猪︶ㄣ 提交于 2019-11-26 16:58:10
问题 I'm trying to profile a C++ application with gprof on a machine running OSX 10.5.7. I compile with g++ in the usual way, but using -pg flags, run the application and try to view the call graph with gprof. Unfortunately my call graph contains all zeroes for all time columns. The values in the "called" columns have reasonable values so it looks like something was profiled but I'm mystified about the lack of other data. All my source files are compiled in a similar way: g++ -pg -O2 -DNDEBUG -I./

How exactly does gprof work?

落花浮王杯 提交于 2019-11-26 14:08:05
问题 This is something of a bloated question, so I apologize ahead of time. I'm curious about how gprof works on a low technical level. I understand it's done by timers, but then why does the executable need to be specially compiled to be profiled? Does the compilation cause space to be allocated for statistics? Also, how is the timing done exactly? 回答1: Well, this gives a good explanation. Also this explains statistical profiling Essentially gprof will change the executable of your program (this

Capturing function exit time with __gnu_mcount_nc

≡放荡痞女 提交于 2019-11-25 23:42:11
问题 I\'m trying to do some performance profiling on a poorly supported prototype embedded platform. I note that GCC\'s -pg flag causes thunks to __gnu_mcount_nc to be inserted on entry to every function. No implementation of __gnu_mcount_nc is available (and the vendor is not interested in assisting), however as it is trivial to write one that simply records the stack frame and current cycle count, I have done so; this works fine and is yielding useful results in terms of caller/callee graphs and