13

I would like to use gcc's gprof line-by-line profiling. But after compiling my program, running it and executing gprof -l binary_name I get messages like:

gprof: somebody miscounted: ltab.len=9403 instead of 9391

gprof binary_name runs without error but I have not been able to run with the -l option. I was not able to find documentation on this. Google autocomplete indicates I am not the first to get this error but I could not find any threads on it. I have tried g++-9 g++-10 and g++-11. I have tried compiling with -g and -ggdb. I considered that maybe gprof did not like my program being multithreaded but even removing the OpenMP dependency and telling libtorch to use 1 thread I get the same behavior.

I have the suspicion that this error was not meant to be seen by the end user as it gives no hints on resolution and mentions ltab.len which is most likely a variable in gcc code no user would be familiar with.

Agade
  • 505
  • 6
  • 18
  • I'm having the same issue. This is not an answer, but as an alternative, I did manage to get `gperftools` and `pprof` to give me a line-by-line profile instead. – Matt Messersmith Dec 02 '22 at 18:04

1 Answers1

1

I don't know if this is a general solution, but for me I realized this error occurs when you enable optimizations. If I compile with:

g++ -g -pg -O3 main.cpp # gprof: somebody miscounted: ltab.len=1034 instead of 1027
g++ -g -pg -O2 main.cpp # gprof: somebody miscounted: ltab.len=775 instead of 768
g++ -g -pg -O1 main.cpp # gprof: somebody miscounted: ltab.len=640 instead of 633
g++ -g -pg -O0 main.cpp # this works

I guess after compiler optimizations, gprof cannot map profiler output to the lines.

F. Eser
  • 125
  • 9