如何读取llvm-cov json格式?

问题描述 投票:0回答:3

我可以通过 llvm-cov 以 json 格式导出代码覆盖率数据,但内容对我来说似乎很神秘。

segments
部分中的每个数字代表什么意思?

{
   "filename":"file.m",
   "segments":[
      [
         11,
         22,
         23,
         1,
         1
      ],
      [
         12,
         11,
         23,
         1,
         1
      ],
      ...
   ],
   "expansions":[

   ],
   "summary":{
      ...
   }
}
llvm code-coverage llvm-cov
3个回答
2
投票

通过 https://clang.llvm.org/docs/SourceBasedCodeCoverage.html,JSON 格式在源代码中进行了解释,我在 https://github.com/llvm/llvm-project/ 找到了它树/主/llvm/工具/llvm-cov

源代码包含以下描述:

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

遗憾的是,这仍然不能很好地解释什么是段,或者它的结构。

更详细地查看代码,我们发现以下两个片段:

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 似乎索引到扩展中给出的文件名中。


0
投票

除了之前的答案,我还发现这个页面非常有用:page。它有助于解释

segment
中的每个概念,例如
line
column


0
投票

您好,我可以看看您的脚本是什么样子吗?我在将 cov 报告转换为 json 文件时遇到问题,它只能作为 html 或 txt 使用?你只有

--format=json
吗?

© www.soinside.com 2019 - 2024. All rights reserved.