首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何读取llvm-cov json格式?

如何读取llvm-cov json格式?
EN

Stack Overflow用户
提问于 2019-05-07 08:18:38
回答 2查看 1.1K关注 0票数 1

我可以通过llvm-cov以json格式导出代码覆盖率数据,但其内容对我来说似乎很神秘。segments部分中的每个数字是什么意思?

代码语言:javascript
复制
{
   "filename":"file.m",
   "segments":[
      [
         11,
         22,
         23,
         1,
         1
      ],
      [
         12,
         11,
         23,
         1,
         1
      ],
      ...
   ],
   "expansions":[

   ],
   "summary":{
      ...
   }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-06-27 21:30:56

通过https://clang.llvm.org/docs/SourceBasedCodeCoverage.html,我在https://github.com/llvm/llvm-project/tree/main/llvm/tools/llvm-cov上找到的源代码中解释了JSON格式。

source code包含以下描述:

代码语言:javascript
复制
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
        -- Branches: array => List of Branches in the file
          -- Branch: dict => Describes a branch of the file with counters
        -- 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
            -- Branches: array => List of Branches in the expansion
              -- Branch: dict => Describes a branch in expansion and counters
        -- 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
          -- BranchCoverage: dict => Object summarizing branch 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
    -- BranchCoverage: dict => Object summarizing branch coverage

遗憾的是,关于段是什么,或者它是如何构造的,这仍然不是很好的解释。

仔细查看代码,我们会发现以下两个代码片段:

代码语言:javascript
复制
json::Array renderSegment(const coverage::CoverageSegment &Segment) {
  return json::Array({Segment.Line, Segment.Col, int64_t(Segment.Count),
                      Segment.HasCount, Segment.IsRegionEntry});
}
代码语言:javascript
复制
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
EN

Stack Overflow用户

发布于 2020-08-05 03:02:01

除了前面的答案,我还发现这个页面非常有用:page。它有助于解释segment中的每个概念,如linecolumn

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56013927

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档