sudo apt install kcachegrind valgrind
Build compiler flags:
CFLAGS / CPPFLAGS: -g (or -ggdb3 -O0)
# Generate a callgrind.out.<PID> file.
valgrind --tool=callgrind ./main
# Generate the callgrind.out.<PID> files per thread.
valgrind --tool=callgrind --separate-threads=yes ./main
# Open a GUI tool to visualize call graph
kcachegrind callgrind.out.<PID>