1

I need to profile my C++ code, and valgrind --tool=callgrind is a phenomenal tool for that. I was wondering, however, if I should be profiling my code with -g -pg -O1 or -g -pg -O3 (GCC 4.4.7)? The latter gives a more accurate depiction of my program's performance, but I worry that -O3 will confuse the profiler and obfuscate what source functions are the actual bottlenecks. Perhaps I am just scared of old wive's tales, but I figured I should ask to be sure before running a potentially several hour test.

Suedocode
  • 2,414
  • 3
  • 18
  • 38
  • Always use the same options as the one used to create production binaries. So I guess (hope) O3 for you. Valgrind is smart enough to deal with that. – quantdev Aug 12 '14 at 15:09
  • Try both... One might make things more obvious to you than the other, but it is not necessarily obvious which. – Marc Glisse Aug 12 '14 at 15:32
  • @MarcGlisse Ideally this would be interesting to compare, but alas the program is too computationally expensive for me to run redundant tests on my own. – Suedocode Aug 12 '14 at 15:39
  • There is no point profiling unoptimized code and when profiling optimized code results will be a bit off because it is difficult to impossible to discern which line of code corresponds to which instructions. The best you can do is profile whole functions that do not get inlined. – nwp Aug 12 '14 at 15:48

1 Answers1

2

This thread in another stackoverflow may clear your mind: optimization flags when profiling

The problem is not profiling with optimization, but debugging with optimization (-g -pg).

As quantdev said, you should "always use the same options as the one used to create production binaries", and you are ont going to create a production binary with debug information.

If the thread is not enough, let us know.

Community
  • 1
  • 1
Juanjo Martin
  • 121
  • 1
  • 4