[llvm] r285088 - [llvm-cov] Add support for loading coverage from multiple objects

Vedant Kumar via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 25 10:40:55 PDT 2016


Author: vedantk
Date: Tue Oct 25 12:40:55 2016
New Revision: 285088

URL: http://llvm.org/viewvc/llvm-project?rev=285088&view=rev
Log:
[llvm-cov] Add support for loading coverage from multiple objects

Differential Revision: https://reviews.llvm.org/D25086

Added:
    llvm/trunk/test/tools/llvm-cov/load-multiple-objects.test
Modified:
    llvm/trunk/docs/CommandGuide/llvm-cov.rst
    llvm/trunk/test/tools/llvm-cov/universal-binary.c
    llvm/trunk/tools/llvm-cov/CodeCoverage.cpp

Modified: llvm/trunk/docs/CommandGuide/llvm-cov.rst
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/docs/CommandGuide/llvm-cov.rst?rev=285088&r1=285087&r2=285088&view=diff
==============================================================================
--- llvm/trunk/docs/CommandGuide/llvm-cov.rst (original)
+++ llvm/trunk/docs/CommandGuide/llvm-cov.rst Tue Oct 25 12:40:55 2016
@@ -167,14 +167,14 @@ SHOW COMMAND
 SYNOPSIS
 ^^^^^^^^
 
-:program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*SOURCES*]
+:program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
 
 DESCRIPTION
 ^^^^^^^^^^^
 
-The :program:`llvm-cov show` command shows line by line coverage of a binary
-*BIN* using the profile data *PROFILE*. It can optionally be filtered to only
-show the coverage for the files listed in *SOURCES*.
+The :program:`llvm-cov show` command shows line by line coverage of the
+binaries *BIN*,...  using the profile data *PROFILE*. It can optionally be
+filtered to only show the coverage for the files listed in *SOURCES*.
 
 To use :program:`llvm-cov show`, you need a program that is compiled with
 instrumentation to emit profile and coverage data. To build such a program with
@@ -183,7 +183,7 @@ flags. If linking with the ``clang`` dri
 to the link stage to make sure the necessary runtime libraries are linked in.
 
 The coverage information is stored in the built executable or library itself,
-and this is what you should pass to :program:`llvm-cov show` as the *BIN*
+and this is what you should pass to :program:`llvm-cov show` as a *BIN*
 argument. The profile data is generated by running this instrumented program
 normally. When the program exits it will write out a raw profile file,
 typically called ``default.profraw``, which can be converted to a format that
@@ -292,14 +292,14 @@ REPORT COMMAND
 SYNOPSIS
 ^^^^^^^^
 
-:program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*SOURCES*]
+:program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
 
 DESCRIPTION
 ^^^^^^^^^^^
 
-The :program:`llvm-cov report` command displays a summary of the coverage of a
-binary *BIN* using the profile data *PROFILE*. It can optionally be filtered to
-only show the coverage for the files listed in *SOURCES*.
+The :program:`llvm-cov report` command displays a summary of the coverage of
+the binaries *BIN*,... using the profile data *PROFILE*. It can optionally be
+filtered to only show the coverage for the files listed in *SOURCES*.
 
 If no source files are provided, a summary line is printed for each file in the
 coverage data. If any files are provided, summaries are shown for each function
@@ -332,13 +332,13 @@ EXPORT COMMAND
 SYNOPSIS
 ^^^^^^^^
 
-:program:`llvm-cov export` [*options*] -instr-profile *PROFILE* *BIN*
+:program:`llvm-cov export` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]]
 
 DESCRIPTION
 ^^^^^^^^^^^
 
 The :program:`llvm-cov export` command exports regions, functions, expansions,
-and summaries of the coverage of a binary *BIN* using the profile data
+and summaries of the coverage of the binaries *BIN*,... using the profile data
 *PROFILE* as JSON.
 
 For information on compiling programs for coverage and generating profile data,

Added: llvm/trunk/test/tools/llvm-cov/load-multiple-objects.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/load-multiple-objects.test?rev=285088&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/load-multiple-objects.test (added)
+++ llvm/trunk/test/tools/llvm-cov/load-multiple-objects.test Tue Oct 25 12:40:55 2016
@@ -0,0 +1,11 @@
+// RUN: llvm-profdata merge %S/Inputs/multiple-files.proftext %S/Inputs/highlightedRanges.profdata -o %t.profdata
+
+// RUN: llvm-cov report -object %S/Inputs/multiple-files.covmapping -instr-profile %t.profdata | FileCheck %s -check-prefix=OBJ1
+
+// RUN: llvm-cov report %S/Inputs/multiple-files.covmapping -object %S/Inputs/highlightedRanges.covmapping -instr-profile %t.profdata | FileCheck %s -check-prefixes=OBJ1,OBJ2
+
+// OBJ2: showHighlightedRanges.cpp
+// OBJ1: f2.c
+// OBJ1: f4.c
+// OBJ1: f3.c
+// OBJ1: f1.c

Modified: llvm/trunk/test/tools/llvm-cov/universal-binary.c
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-cov/universal-binary.c?rev=285088&r1=285087&r2=285088&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-cov/universal-binary.c (original)
+++ llvm/trunk/test/tools/llvm-cov/universal-binary.c Tue Oct 25 12:40:55 2016
@@ -12,4 +12,4 @@ int main(int argc, const char *argv[]) {
 // WRONG-ARCH: Failed to load coverage
 
 // RUN: not llvm-cov report -instr-profile %t.profdata 2>&1 | FileCheck --check-prefix=MISSING-BINARY %s
-// MISSING-BINARY: 1 positional argument: See:
+// MISSING-BINARY: No filenames specified!

Modified: llvm/trunk/tools/llvm-cov/CodeCoverage.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-cov/CodeCoverage.cpp?rev=285088&r1=285087&r2=285088&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-cov/CodeCoverage.cpp (original)
+++ llvm/trunk/tools/llvm-cov/CodeCoverage.cpp Tue Oct 25 12:40:55 2016
@@ -116,7 +116,7 @@ private:
   int export_(int argc, const char **argv,
               CommandLineParserType commandLineParser);
 
-  std::string ObjectFilename;
+  std::vector<StringRef> ObjectFilenames;
   CoverageViewOptions ViewOpts;
   CoverageFiltersMatchAll Filters;
 
@@ -325,13 +325,15 @@ static bool modifiedTimeGT(StringRef LHS
 }
 
 std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
-  if (modifiedTimeGT(ObjectFilename, PGOFilename))
-    warning("profile data may be out of date - object is newer",
-            ObjectFilename);
+  for (StringRef ObjectFilename : ObjectFilenames)
+    if (modifiedTimeGT(ObjectFilename, PGOFilename))
+      warning("profile data may be out of date - object is newer",
+              ObjectFilename);
   auto CoverageOrErr =
-      CoverageMapping::load(ObjectFilename, PGOFilename, CoverageArch);
+      CoverageMapping::load(ObjectFilenames, PGOFilename, CoverageArch);
   if (Error E = CoverageOrErr.takeError()) {
-    error("Failed to load coverage: " + toString(std::move(E)), ObjectFilename);
+    error("Failed to load coverage: " + toString(std::move(E)),
+          join(ObjectFilenames.begin(), ObjectFilenames.end(), ", "));
     return nullptr;
   }
   auto Coverage = std::move(CoverageOrErr.get());
@@ -484,9 +486,12 @@ void CodeCoverageTool::writeSourceFileVi
 }
 
 int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
-  cl::opt<std::string, true> ObjectFilename(
-      cl::Positional, cl::Required, cl::location(this->ObjectFilename),
-      cl::desc("Covered executable or object file."));
+  cl::opt<std::string> CovFilename(
+      cl::Positional, cl::desc("Covered executable or object file."));
+
+  cl::list<std::string> CovFilenames(
+      "object", cl::desc("Coverage executable or object file"), cl::ZeroOrMore,
+      cl::CommaSeparated);
 
   cl::list<std::string> InputSourceFiles(
       cl::Positional, cl::desc("<Source files>"), cl::ZeroOrMore);
@@ -568,6 +573,15 @@ int CodeCoverageTool::run(Command Cmd, i
     ViewOpts.Debug = DebugDump;
     CompareFilenamesOnly = FilenameEquivalence;
 
+    if (!CovFilename.empty())
+      ObjectFilenames.emplace_back(CovFilename);
+    for (const std::string &Filename : CovFilenames)
+      ObjectFilenames.emplace_back(Filename);
+    if (ObjectFilenames.empty()) {
+      error("No filenames specified!");
+      ::exit(1);
+    }
+
     ViewOpts.Format = Format;
     switch (ViewOpts.Format) {
     case CoverageViewOptions::OutputFormat::Text:




More information about the llvm-commits mailing list