[英]Profile c++ program in perf
I am Ubuntu 16.04 user. 我是Ubuntu 16.04用户。 For profiling c++
program I use perf
tool. 对于配置c++
程序,我使用perf
工具。 So I run: 所以我跑:
perf record ./myprogram myprogram_args
perf report
Now as output I have: 现在作为输出,我有:
14,52% CSim2Sim libsimgrid.so.3.13.90 [.] lmm_solve
4,40% CSim2Sim libsimgrid.so.3.13.90 [.] lmm_update_modified_set_rec
4,05% CSim2Sim libc-2.23.so [.] _int_malloc
3,30% CSim2Sim libsimgrid.so.3.13.90 [.] simgrid::surf::Model::next_occuring_event_lazy
2,19% CSim2Sim libc-2.23.so [.] _int_free
........................................................................
I see only "depth" and library calls from my program. 我只能从程序中看到“深度”和库调用。 How can I get report from perf similar to this template? 如何从类似于此模板的性能报告中获取报告? (something like this): (类似这样):
4,52% CSim2Sim my_function1(int argc, char* argv[])
3,52% CSim2Sim my_function2(int argc, char* argv[])
3,52% CSim2Sim my_function3(int argc, char* argv[])
1,52% CSim2Sim my_function4(int argc, char* argv[])
Going from perf over info:perf to Perf Wiki , and finally to Tutorial - Perf Wiki 从perf到info:perf到Perf Wiki ,最后到Tutorial-Perf Wiki
Source level analysis with perf annotate 使用perf注释的源代码级别分析
... ...
perf annotate can generate sourcecode level information if the application is compiled with -ggdb . 如果使用-ggdb编译应用程序,则perf注释可以生成源代码级别的信息。 The following snippet shows the much more informative output for the same execution of noploop when compiled with this debugging information. 下面的代码片段显示了使用此调试信息进行编译时,对于相同执行noploop的更多信息输出。
So compiling (and maybe linking?) with option -ggdb
should do the trick. 因此,使用选项-ggdb
编译(也许链接?)应该可以解决问题。
Then you can use perf record
to collect runtime information, and later analyze this with perf annotate
. 然后,您可以使用perf record
来收集运行时信息,然后使用perf annotate
进行分析。
I just found this answer to Alternatives to gprof [closed] . 我刚刚找到了gprof替代方法的答案。 It recommends using gcc's option -fno-omit-frame-pointer
, if you want to get call graph information. 如果要获取调用图信息,建议使用gcc的选项-fno-omit-frame-pointer
。 So, depending on what you want to achieve and your optimization level, you might need to add this option too. 因此,根据您要实现的目标和优化级别,您可能还需要添加此选项。
I would also recommend using gprof(1) . 我也建议使用gprof(1) 。 You'll compile your C (or C++) program by passing -pg
(probably also with -O
....) to gcc
and/or g++
(perhaps change some CFLAGS
or CXXFLAGS
in your Makefile
). 您可以通过将-pg
(可能还带有-O
....)传递给gcc
和/或g++
(也许在您的Makefile
更改某些CFLAGS
或CXXFLAGS
)来编译C(或C ++)程序。 Read about instrumentation options of GCC. 阅读有关GCC的检测选项的信息。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.