llvm.org GIT mirror llvm / d4998ec
[llvm-cov] Add support for loading coverage from multiple objects Differential Revision: https://reviews.llvm.org/D25086 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@285088 91177308-0d34-0410-b5e6-96231b3b80d8 Vedant Kumar 4 years ago
4 changed file(s) with 54 addition(s) and 29 deletion(s). Raw diff Collapse all Expand all
166166 SYNOPSIS
167167 ^^^^^^^^
168168
169 :program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*SOURCES*]
170
171 DESCRIPTION
172 ^^^^^^^^^^^
173
174 The :program:`llvm-cov show` command shows line by line coverage of a binary
175 *BIN* using the profile data *PROFILE*. It can optionally be filtered to only
176 show the coverage for the files listed in *SOURCES*.
169 :program:`llvm-cov show` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
170
171 DESCRIPTION
172 ^^^^^^^^^^^
173
174 The :program:`llvm-cov show` command shows line by line coverage of the
175 binaries *BIN*,... using the profile data *PROFILE*. It can optionally be
176 filtered to only show the coverage for the files listed in *SOURCES*.
177177
178178 To use :program:`llvm-cov show`, you need a program that is compiled with
179179 instrumentation to emit profile and coverage data. To build such a program with
182182 to the link stage to make sure the necessary runtime libraries are linked in.
183183
184184 The coverage information is stored in the built executable or library itself,
185 and this is what you should pass to :program:`llvm-cov show` as the *BIN*
185 and this is what you should pass to :program:`llvm-cov show` as a *BIN*
186186 argument. The profile data is generated by running this instrumented program
187187 normally. When the program exits it will write out a raw profile file,
188188 typically called ``default.profraw``, which can be converted to a format that
291291 SYNOPSIS
292292 ^^^^^^^^
293293
294 :program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*SOURCES*]
295
296 DESCRIPTION
297 ^^^^^^^^^^^
298
299 The :program:`llvm-cov report` command displays a summary of the coverage of a
300 binary *BIN* using the profile data *PROFILE*. It can optionally be filtered to
301 only show the coverage for the files listed in *SOURCES*.
294 :program:`llvm-cov report` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]] [*SOURCES*]
295
296 DESCRIPTION
297 ^^^^^^^^^^^
298
299 The :program:`llvm-cov report` command displays a summary of the coverage of
300 the binaries *BIN*,... using the profile data *PROFILE*. It can optionally be
301 filtered to only show the coverage for the files listed in *SOURCES*.
302302
303303 If no source files are provided, a summary line is printed for each file in the
304304 coverage data. If any files are provided, summaries are shown for each function
331331 SYNOPSIS
332332 ^^^^^^^^
333333
334 :program:`llvm-cov export` [*options*] -instr-profile *PROFILE* *BIN*
334 :program:`llvm-cov export` [*options*] -instr-profile *PROFILE* *BIN* [*-object BIN,...*] [[*-object BIN*]]
335335
336336 DESCRIPTION
337337 ^^^^^^^^^^^
338338
339339 The :program:`llvm-cov export` command exports regions, functions, expansions,
340 and summaries of the coverage of a binary *BIN* using the profile data
340 and summaries of the coverage of the binaries *BIN*,... using the profile data
341341 *PROFILE* as JSON.
342342
343343 For information on compiling programs for coverage and generating profile data,
0 // RUN: llvm-profdata merge %S/Inputs/multiple-files.proftext %S/Inputs/highlightedRanges.profdata -o %t.profdata
1
2 // RUN: llvm-cov report -object %S/Inputs/multiple-files.covmapping -instr-profile %t.profdata | FileCheck %s -check-prefix=OBJ1
3
4 // RUN: llvm-cov report %S/Inputs/multiple-files.covmapping -object %S/Inputs/highlightedRanges.covmapping -instr-profile %t.profdata | FileCheck %s -check-prefixes=OBJ1,OBJ2
5
6 // OBJ2: showHighlightedRanges.cpp
7 // OBJ1: f2.c
8 // OBJ1: f4.c
9 // OBJ1: f3.c
10 // OBJ1: f1.c
1111 // WRONG-ARCH: Failed to load coverage
1212
1313 // RUN: not llvm-cov report -instr-profile %t.profdata 2>&1 | FileCheck --check-prefix=MISSING-BINARY %s
14 // MISSING-BINARY: 1 positional argument: See:
14 // MISSING-BINARY: No filenames specified!
115115 int export_(int argc, const char **argv,
116116 CommandLineParserType commandLineParser);
117117
118 std::string ObjectFilename;
118 std::vector ObjectFilenames;
119119 CoverageViewOptions ViewOpts;
120120 CoverageFiltersMatchAll Filters;
121121
324324 }
325325
326326 std::unique_ptr CodeCoverageTool::load() {
327 if (modifiedTimeGT(ObjectFilename, PGOFilename))
328 warning("profile data may be out of date - object is newer",
329 ObjectFilename);
327 for (StringRef ObjectFilename : ObjectFilenames)
328 if (modifiedTimeGT(ObjectFilename, PGOFilename))
329 warning("profile data may be out of date - object is newer",
330 ObjectFilename);
330331 auto CoverageOrErr =
331 CoverageMapping::load(ObjectFilename, PGOFilename, CoverageArch);
332 CoverageMapping::load(ObjectFilenames, PGOFilename, CoverageArch);
332333 if (Error E = CoverageOrErr.takeError()) {
333 error("Failed to load coverage: " + toString(std::move(E)), ObjectFilename);
334 error("Failed to load coverage: " + toString(std::move(E)),
335 join(ObjectFilenames.begin(), ObjectFilenames.end(), ", "));
334336 return nullptr;
335337 }
336338 auto Coverage = std::move(CoverageOrErr.get());
483485 }
484486
485487 int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
486 cl::opt ObjectFilename(
487 cl::Positional, cl::Required, cl::location(this->ObjectFilename),
488 cl::desc("Covered executable or object file."));
488 cl::opt CovFilename(
489 cl::Positional, cl::desc("Covered executable or object file."));
490
491 cl::list CovFilenames(
492 "object", cl::desc("Coverage executable or object file"), cl::ZeroOrMore,
493 cl::CommaSeparated);
489494
490495 cl::list InputSourceFiles(
491496 cl::Positional, cl::desc(""), cl::ZeroOrMore);
566571 cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
567572 ViewOpts.Debug = DebugDump;
568573 CompareFilenamesOnly = FilenameEquivalence;
574
575 if (!CovFilename.empty())
576 ObjectFilenames.emplace_back(CovFilename);
577 for (const std::string &Filename : CovFilenames)
578 ObjectFilenames.emplace_back(Filename);
579 if (ObjectFilenames.empty()) {
580 error("No filenames specified!");
581 ::exit(1);
582 }
569583
570584 ViewOpts.Format = Format;
571585 switch (ViewOpts.Format) {