3

I am Ubuntu 16.04 user. For profiling c++ program I use perf tool. 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[])
Kenenbek Arzymatov
  • 8,439
  • 19
  • 58
  • 109

2 Answers2

4

Going from over info:perf to Perf Wiki, and finally to 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.

So compiling (and maybe linking?) with option -ggdb should do the trick.

Then you can use perf record to collect runtime information, and later analyze this with perf annotate.


I just found this answer to Alternatives to gprof [closed]. It recommends using gcc's option -fno-omit-frame-pointer, if you want to get call graph information. So, depending on what you want to achieve and your optimization level, you might need to add this option too.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
2

I would also recommend using 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 ). Read about instrumentation options of GCC.

Basile Starynkevitch
  • 223,805
  • 18
  • 296
  • 547