我能够通过llvm-cov以json格式导出代码覆盖率数据,但是内容对我来说似乎很神秘。 segments
部分中的每个数字是什么意思?
{
"filename":"file.m",
"segments":[
[
11,
22,
23,
1,
1
],
[
12,
11,
23,
1,
1
],
...
],
"expansions":[
],
"summary":{
...
}
}
答案 0 :(得分:0)
按照https://clang.llvm.org/docs/SourceBasedCodeCoverage.html进行操作,JSON格式在源代码中进行了解释,我在https://github.com/llvm-mirror/llvm/tree/master/tools/llvm-cov上找到了源代码。
source code包含以下描述:
The json code coverage export follows the following format
Root: dict => Root Element containing metadata
-- Data: array => Homogeneous array of one or more export objects
-- Export: dict => Json representation of one CoverageMapping
-- Files: array => List of objects describing coverage for files
-- File: dict => Coverage for a single file
-- Segments: array => List of Segments contained in the file
-- Segment: dict => Describes a segment of the file with a counter
-- Expansions: array => List of expansion records
-- Expansion: dict => Object that descibes a single expansion
-- CountedRegion: dict => The region to be expanded
-- TargetRegions: array => List of Regions in the expansion
-- CountedRegion: dict => Single Region in the expansion
-- Summary: dict => Object summarizing the coverage for this file
-- LineCoverage: dict => Object summarizing line coverage
-- FunctionCoverage: dict => Object summarizing function coverage
-- RegionCoverage: dict => Object summarizing region coverage
-- Functions: array => List of objects describing coverage for functions
-- Function: dict => Coverage info for a single function
-- Filenames: array => List of filenames that the function relates to
-- Summary: dict => Object summarizing the coverage for the entire binary
-- LineCoverage: dict => Object summarizing line coverage
-- FunctionCoverage: dict => Object summarizing function coverage
-- InstantiationCoverage: dict => Object summarizing inst. coverage
-- RegionCoverage: dict => Object summarizing region coverage
遗憾的是,这仍然不是关于段是什么或其结构的解释。
仔细看一下代码,我们发现以下两个片段:
json::Array renderSegment(const coverage::CoverageSegment &Segment) {
return json::Array({Segment.Line, Segment.Col, int64_t(Segment.Count),
Segment.HasCount, Segment.IsRegionEntry});
}
json::Array renderRegion(const coverage::CountedRegion &Region) {
return json::Array({Region.LineStart, Region.ColumnStart, Region.LineEnd,
Region.ColumnEnd, int64_t(Region.ExecutionCount),
Region.FileID, Region.ExpandedFileID,
int64_t(Region.Kind)});
}
哪个应该让您更好地了解条目的含义。
文件ID似乎索引到扩展名中提供的文件名中。
答案 1 :(得分:0)
除了先前的答案,我还发现此页面非常有用:page。它有助于解释segment
中的每个概念,例如line
,column
。