c++ - 在 perf 中分析 c++ 程序

标签 c++ profiling profiler perf

我是 Ubuntu 16.04 用户。 为了分析 c++ 程序,我使用了 perf 工具。所以我跑:

perf record ./myprogram myprogram_args
perf report 

现在作为输出我有:

  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
........................................................................

我只看到程序中的“深度”和库调用。如何从类似于此模板的性能报告中获取报告? (像这样):

  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[])

最佳答案

来自 info:perfPerf Wiki , 最后到 Tutorial - Perf Wiki

Source level analysis with perf annotate
...
perf annotate can generate sourcecode level information if the application is compiled with -ggdb. The following snippet shows the much more informative output for the same execution of noploop when compiled with this debugging information.

所以使用选项 -ggdb 编译(也许链接?)应该可以解决问题。

然后你可以使用perf record收集运行时信息,然后使用 perf annotate 对其进行分析。


我刚刚找到了 Alternatives to gprof [closed] 的答案.如果您想获取调用图信息,它建议使用 gcc 的选项 -fno-omit-frame-pointer。因此,根据您想要实现的目标和您的优化级别,您可能还需要添加此选项。

关于c++ - 在 perf 中分析 c++ 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40323919/

相关文章:

C gperftools - 分析 C 代码

c++ - 执行我的简单函数需要多少 CPU 周期?

c++ - 为什么 vector 在一个测试中比 map 快,而在另一个测试中不是?

java - 您使用哪种 Java Profiling 工具,您认为哪种工具最好?

java - Oracle Solaris Studio 性能分析器 12.3 的使用

c++ - "Adding"功能共享对象?

c++ - RInside 段错误和链接问题

c++ - 为什么我们不能在构造函数初始化列表中初始化静态变量,但我们可以在构造函数体中

c++ - 将结构化数据类型从 Fortran 传递到 C++

java - 内存分析器