2
votes

I've been trying to profile some C++ with gprof 2.25.2 (under Cygwin) and it is reporting that 10% of the time is being spent in a function which I know is not being called. (I put a print statement into the relevant function to verify this.) It also seems to think that this function is calling itself recursively (number of calls is 500+16636500), which it definitely isn't.

It's a large enough program that I don't have an easy way of producing a minimal working example I can post here, but if anyone has any ideas about what might be causing this, I would be grateful to know.

Edit: building with CMake + g++. CMAKE_BUILD_TYPE=RELWITHDEBINFO.

1
Maybe change RELWITHDEBINFO to DEBUG - texasflood
@texasflood That does get rid of the error, but I'm no longer convinced the profiling results are representative of the program as it would run in a real environment. - Mohan
This is a fundamentally unavoidable issue in general. If you want to profile code, it can't be optimised much, otherwise the link between the source code you write and the actual object files becomes very complex (functions and variables may be added and removed for example). Of course, when you want to run code in a real environment, you want it to be fully optimised, which may invalidate conclusions drawn from profiling. There is no easy answer to this - texasflood
If you want speed, do not "analyze performance". Do find the speed bugs. See here. The point is, if the reason you're profiling is to find ways you can speed up the code, it does not need to be compiler-optimized, in fact it's better not. (In spite of what lots of people will tell you.) When you've finished with it, then turn on the optimizer. - Mike Dunlavey

1 Answers

0
votes

I'll assume you're using gcc/g++...

This sounds like a case of the debug symbols being out-of-date with respect to your source code or executable. Try cleaning your build space, recompiling (with -g or -ggdb3, of course). If you're compiling with optimizations and you can afford to turn them off (i.e. -O0 instead of -O1, -O2 or -O3), do so for this run. If that works, try -O1 or -O2 and see what happens.