我是 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[])
最佳答案
来自 perf在 info:perf至 Perf 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/