Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC gprof line-by-line error "somebody miscounted"

Tags:

gcc

g++

gprof

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.

like image 595
Agade Avatar asked Jan 29 '26 19:01

Agade


2 Answers

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.

like image 71
F. Eser Avatar answered Feb 01 '26 08:02

F. Eser


I was able to get g++ -pg -g with -02 optimizations to work by removing the -l from gprof command. So first compile and run the program. Then move gmon.out and the binary compiled with debug options into the same directory. Then run sudo gprof binary_name gmon.out binary_name > output.txt

like image 44
Brian McCullough Avatar answered Feb 01 '26 09:02

Brian McCullough



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!