Friday, April 17, 2020

Profile c++ code


To profile an executable and get a nice visual of it (you need the expected flags when compiled of course):

First you need to compile with argument ''-pg'', so that gcc inserts its code all everywhere to time your function calls.

Once you run the project, it will generate a big file named ''gmon.out''. This is mostly unreadable per se. And ''gprof'' hardly makes it more readable.

Here comes ''gprof2dot.py'' and ''dot'', which generate very readable graphs:
''
gprof exe/router.exe | gprof2dot.py -s | dot -Tpng -o profiler.png && gwenview profiler.png
''

Note that ''gprof'' must be given the executable name. It will not run it in anyway, but it needs the symbol table to give you proper names.


No comments:

Post a Comment