diff options
author | Vedant Kumar <vsk@apple.com> | 2016-07-26 22:50:58 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2016-07-26 22:50:58 +0000 |
commit | 7101d73c71ec9dd53b092ed354357ac5a2e1d34c (patch) | |
tree | 4f88f6e828ff7d8c27f4916cf4cf7cc1f4712f30 /llvm/tools/llvm-cov/CodeCoverage.cpp | |
parent | a333db87a7190408cf3f6ab5cc769a19ebe40e33 (diff) | |
download | llvm-7101d73c71ec9dd53b092ed354357ac5a2e1d34c.zip llvm-7101d73c71ec9dd53b092ed354357ac5a2e1d34c.tar.gz llvm-7101d73c71ec9dd53b092ed354357ac5a2e1d34c.tar.bz2 |
Retry: [llvm-cov] Add support for exporting coverage data to JSON
This enables users to export coverage information as portable JSON for use by
analysis tools and storage in document based databases.
The export sub-command is invoked just like the others:
llvm-cov export -instr-profile path/to/foo.profdata path/to/foo.binary
The resulting JSON contains a list of files and functions. Every file object
contains a list of segments, expansions, and a summary of the file's region,
function, and line coverage. Every function object contains the function's name
and regions. There is also a total summary for the entire object file.
Changes since the initial commit (r276813):
- Fixed the regexes in the tests to handle Windows filepaths.
Patch by Eddie Hurtig!
Differential Revision: https://reviews.llvm.org/D22651
llvm-svn: 276818
Diffstat (limited to 'llvm/tools/llvm-cov/CodeCoverage.cpp')
-rw-r--r-- | llvm/tools/llvm-cov/CodeCoverage.cpp | 36 |
1 files changed, 35 insertions, 1 deletions
diff --git a/llvm/tools/llvm-cov/CodeCoverage.cpp b/llvm/tools/llvm-cov/CodeCoverage.cpp index e274483..494912e 100644 --- a/llvm/tools/llvm-cov/CodeCoverage.cpp +++ b/llvm/tools/llvm-cov/CodeCoverage.cpp @@ -38,6 +38,10 @@ using namespace llvm; using namespace coverage; +void exportCoverageDataToJson(StringRef ObjectFilename, + const coverage::CoverageMapping &CoverageMapping, + raw_ostream &OS); + namespace { /// \brief The implementation of the coverage tool. class CodeCoverageTool { @@ -46,7 +50,9 @@ public: /// \brief The show command. Show, /// \brief The report command. - Report + Report, + /// \brief The export command. + Export }; /// \brief Print the error message to the error output stream. @@ -94,6 +100,9 @@ public: int report(int argc, const char **argv, CommandLineParserType commandLineParser); + int export_(int argc, const char **argv, + CommandLineParserType commandLineParser); + std::string ObjectFilename; CoverageViewOptions ViewOpts; std::string PGOFilename; @@ -534,6 +543,8 @@ int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) { return show(argc, argv, commandLineParser); case Report: return report(argc, argv, commandLineParser); + case Export: + return export_(argc, argv, commandLineParser); } return 0; } @@ -694,6 +705,24 @@ int CodeCoverageTool::report(int argc, const char **argv, return 0; } +int CodeCoverageTool::export_(int argc, const char **argv, + CommandLineParserType commandLineParser) { + + auto Err = commandLineParser(argc, argv); + if (Err) + return Err; + + auto Coverage = load(); + if (!Coverage) { + error("Could not load coverage information"); + return 1; + } + + exportCoverageDataToJson(ObjectFilename, *Coverage.get(), outs()); + + return 0; +} + int showMain(int argc, const char *argv[]) { CodeCoverageTool Tool; return Tool.run(CodeCoverageTool::Show, argc, argv); @@ -703,3 +732,8 @@ int reportMain(int argc, const char *argv[]) { CodeCoverageTool Tool; return Tool.run(CodeCoverageTool::Report, argc, argv); } + +int exportMain(int argc, const char *argv[]) { + CodeCoverageTool Tool; + return Tool.run(CodeCoverageTool::Export, argc, argv); +} |