Clang supports a couple of different code coverage implementations (which also output how often a line has been executed) such as Source-Based Code Coverage and a gcov-compatible one. Open source tools seems to have better support for gcov output in general, so I would recommend that route.
What command-line options to I pass to clang++ to instruct it to gather profiling data when the code is executed?
- For Source-Based Code Coverage:
According to llvm-cov, the correct flags for gathering profiling data when is
-fprofile-instr-generate -fcoverage-mapping
when compiling and -fprofile-instr-generate
when linking.
- For the gcov compatible output:
-fprofile-arcs -ftest-coverage
Into which file(s) is the gathered profiling data stored?
- For Source-Based Code Coverage:
After you run the program compile and linked with the flags above, the coverage data is stored in
default.profraw
in your current working directory. The profiling data file name can be changed by recompiling with -fprofile-instr-generate=filename
or by setting the environment variable LLVM_PROFILE_FILE
before running the executable.
- For gcov compatible output: After you run the program you will get
*.gcda
and *.gcno
files.
What are the post-processing steps to convert the collected profile data into a graphical report that shows how often each function is called, what percentage of time is spent in each function
and from which functions each function is called (similar to https://s3-us-west-2.amazonaws.com/brunorijsman-public/example-rift-python-code-profile.png)?
For this type of information I would try to have a look at Callgrind and KCacheGrind. I have not found any tool which can generate this type of information given *.profdata
or *.gcda
files.