11

I'm using Perf to perform some profiling experiments.

However, I would like to know results for a specific code region and for this case seeing the results (percentages) for each line of source code (C/C++ in this case) would ease the task.

perf annotate has a view where it displays ASM+Source Code and also has the option to turn off showing source code. I would like to know how to accomplish the other end of this option, that is, showing only Source Code + its percentages of events per line and hide ASM output. Is this possible with perf?

Suggestion of other tool to do that? I'm also using Vtune however the analysis I want to do not is working. Valgrind is out of question, too slow.

I'm on an x64 running Ubuntu 13.04.

tshepang
  • 10,772
  • 21
  • 84
  • 127
JohnTortugo
  • 5,435
  • 7
  • 33
  • 63
  • Grab the free 30 day evaluation of Zoom from http://rotateright.com/zoom - it does exactly what you are looking for in a very elegant way. – Paul R Sep 02 '13 at 15:50
  • 2
    Try oprofile http://oprofile.sourceforge.net/examples/ – vinay hunachyal Sep 02 '13 at 16:03
  • I've used Oprofile a long time ago but stopped, I don't remember exactly why but I guess was because it is slow, any way it seems to do what I want. I'll give it a try. I'll also experiment with Zoom. – JohnTortugo Sep 02 '13 at 16:34
  • vinay hunachyal: As I ended using Oprofile and get the same results I obtained with Perf, you can make that a answer and I'll accept it. – JohnTortugo Sep 02 '13 at 21:28
  • @JohnTortugo, how did you manage to get perf annotate to display source? I only get the disassembly. I know it's because we don't compile with the -g option because it is a release binary and we want it to run fast. So question, is compiling with -g the only way to get perf annotate to display source? – Krishna Apr 30 '20 at 18:52

1 Answers1

1

Unfortunately perf-annotate uses objdump under the hood which doesn't seem to be able to show only source (-S implies -d).

If you know the way to make objdump behave, see symbol__annotate() at tools/perf/util/annotate.c.

snprintf(command, sizeof(command),
         "%s %s%s --start-address=0x%016" PRIx64
         " --stop-address=0x%016" PRIx64
         " -d %s %s -C %s|grep -v %s|expand",
         objdump_path ? objdump_path : "objdump",
         disassembler_style ? "-M " : "",
         disassembler_style ? disassembler_style : "",
         map__rip_2objdump(map, sym->start),
         map__rip_2objdump(map, sym->end+1),
         symbol_conf.annotate_asm_raw ? "" : "--no-show-raw",
         symbol_conf.annotate_src ? "-S" : "",
         symfs_filename, filename);
adobriyan
  • 2,424
  • 13
  • 8