2021年4月13日星期二

Generate function call-graph by valgrind

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>


2021年4月12日星期一

Use lcov to view the coverage

Assume main.c and x.c are the source files.

1) Add CFLAGS / CPPFLAG -fprofile-arcs -ftest-coverage when build the project, .gcno is generated

2) Execute the program    #.gcda are generarted

3) gcov main.c    #main.c.gcov is generated (Optional)

4) gcov x.c    #x.c.gcov is generated (Optional)

5) Gen html report

lcov -c --directory . --output-file main_coverage.info
genhtml main_coverage.info --output-directory out