I use - O3 when compiling the code, and now I need to profile it. There are two main options for profiling that I have chosen: valgrind --tool = callgrind and gprof .
Valgrind (callgrind) docs:
As with Cachegrind, you probably want to compile debugging information (the -g option) and enable optimization.
However, in Agner Fog’s C ++ Optimization Book , I read the following:
Many optimization options are not compatible with debugging. The debugger can encode one line at a time and show the values of all variables. Obviously, this is not possible when parts of the code have been reordered, embedded, or optimized. Usually make two versions of the executable program: the debug version with full debugging support that is used during the development of the program, and the release version with all the relevant optimization parameters are included. Most IDEs (Integrated Development Environments) have tools for creating a debug version and version versions of object files and executable files. Be sure to distinguish between the two versions and disable debugging and profiling support in the optimized version of the executable file.
, callgrind -g. :
-ggdb -DFULLDEBUG
-O3? , .
-O3 optimize, , :
-pg
- valgrind?
,
-ggdb -DFULLDEBUG -O0
? - , , , .
, ?