如何为使用Clang LLVM编译的C++代码生成图形代码配置文件报告?
我可以完全控制C++源代码和Makefile。
它必须是LLVM clang++(对我来说,GNU g++不是一个选择)。 Xcode也不是我的选择。
最佳答案
Clang支持几种不同的代码覆盖率实现(也输出行执行的频率),例如Source-Based Code Coverage和与gcov兼容的实现。总体而言,开源工具似乎对gcov输出提供了更好的支持,因此,我建议使用该路由。
What command-line options to I pass to clang++ to instruct it to gather profiling data when the code is executed?
根据llvm-cov,用于收集概要分析数据的正确标志是编译时的
-fprofile-instr-generate -fcoverage-mapping
和链接时的-fprofile-instr-generate
。 -fprofile-arcs -ftest-coverage
Into which file(s) is the gathered profiling data stored?
运行程序编译并与上面的标志链接后,覆盖范围数据将存储在当前工作目录中的
default.profraw
中。可以通过使用-fprofile-instr-generate=filename
重新编译或通过在运行可执行文件之前设置环境变量LLVM_PROFILE_FILE
来更改分析数据文件名。 *.gcda
和*.gcno
文件。 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
.profraw
文件索引为.profdata
文件:llvm-profdata merge -o default.profdata -sparse=true default.profraw
llvm-cov show --instr-profile default.profdata ./your_program
来查看终端中的覆盖范围,要么使用llvm-cov export ./your_program --instr-profile default.profdata > out.json
将您的概要分析数据转换为JSON并查找/创建一个程序来为您生成报告。 lcov
或gcovr
生成HTML输出。这使您可以轻松查看每个文件的行和分支覆盖率。我倾向于使用gcovr,因为如果您没有安装它,它就只是一个简单的pip install gcovr
。则用法为gcovr --gcov-executable "llvm-cov gcov" -r . --html --html-details -o out.html
。 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)?
对于此类信息,我将尝试看看Callgrind和KCacheGrind。在
*.profdata
或*.gcda
文件的情况下,我还没有找到可以生成此类信息的工具。
关于c++ - 如何为使用Clang LLVM编译的C++代码生成图形代码配置文件报告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60840386/