blob: 515d2bdc8e69434d74aff878ff50a15ef62b33c5 [file] [log] [blame]
Alex Lorenze82d89c2014-08-22 22:56:03 +00001//===- CodeCoverage.cpp - Coverage tool based on profiling instrumentation-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
10// The 'CodeCoverageTool' class implements a command line tool to analyze and
11// report coverage information using the profiling instrumentation and code
12// coverage mapping.
13//
14//===----------------------------------------------------------------------===//
15
Alex Lorenze82d89c2014-08-22 22:56:03 +000016#include "RenderingSupport.h"
17#include "CoverageViewOptions.h"
18#include "CoverageFilters.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000019#include "SourceCoverageView.h"
20#include "CoverageSummary.h"
21#include "CoverageReport.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/ADT/SmallString.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000024#include "llvm/ProfileData/InstrProfReader.h"
25#include "llvm/ProfileData/CoverageMapping.h"
26#include "llvm/ProfileData/CoverageMappingReader.h"
27#include "llvm/Support/CommandLine.h"
28#include "llvm/Support/FileSystem.h"
29#include "llvm/Support/ManagedStatic.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000030#include "llvm/Support/Format.h"
31#include "llvm/Support/Path.h"
32#include "llvm/Support/Signals.h"
33#include "llvm/Support/PrettyStackTrace.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000034#include <functional>
Justin Bognere53be062014-09-09 05:32:18 +000035#include <system_error>
Alex Lorenze82d89c2014-08-22 22:56:03 +000036
37using namespace llvm;
38using namespace coverage;
39
40namespace {
Alex Lorenze82d89c2014-08-22 22:56:03 +000041/// \brief The implementation of the coverage tool.
42class CodeCoverageTool {
43public:
44 enum Command {
45 /// \brief The show command.
46 Show,
47 /// \brief The report command.
48 Report
49 };
50
51 /// \brief Print the error message to the error output stream.
52 void error(const Twine &Message, StringRef Whence = "");
53
54 /// \brief Return a memory buffer for the given source file.
55 ErrorOr<const MemoryBuffer &> getSourceFile(StringRef SourceFile);
56
Justin Bogner953e2402014-09-20 15:31:56 +000057 /// \brief Create source views for the expansions of the view.
58 void attachExpansionSubViews(SourceCoverageView &View,
59 ArrayRef<ExpansionRecord> Expansions,
60 CoverageMapping &Coverage);
Alex Lorenze82d89c2014-08-22 22:56:03 +000061
Justin Bogner953e2402014-09-20 15:31:56 +000062 /// \brief Create the source view of a particular function.
Justin Bogner5a6edad2014-09-19 19:07:17 +000063 std::unique_ptr<SourceCoverageView>
Justin Bogner953e2402014-09-20 15:31:56 +000064 createFunctionView(const FunctionRecord &Function, CoverageMapping &Coverage);
Alex Lorenze82d89c2014-08-22 22:56:03 +000065
66 /// \brief Create the main source view of a particular source file.
Justin Bogner5a6edad2014-09-19 19:07:17 +000067 std::unique_ptr<SourceCoverageView>
Justin Bogner953e2402014-09-20 15:31:56 +000068 createSourceFileView(StringRef SourceFile, CoverageMapping &Coverage);
Alex Lorenze82d89c2014-08-22 22:56:03 +000069
70 /// \brief Load the coverage mapping data. Return true if an error occured.
Justin Bogner953e2402014-09-20 15:31:56 +000071 std::unique_ptr<CoverageMapping> load();
Alex Lorenze82d89c2014-08-22 22:56:03 +000072
73 int run(Command Cmd, int argc, const char **argv);
74
75 typedef std::function<int(int, const char **)> CommandLineParserType;
76
77 int show(int argc, const char **argv,
78 CommandLineParserType commandLineParser);
79
80 int report(int argc, const char **argv,
81 CommandLineParserType commandLineParser);
82
Justin Bognerf6c50552014-10-30 20:51:24 +000083 std::string ObjectFilename;
Alex Lorenze82d89c2014-08-22 22:56:03 +000084 CoverageViewOptions ViewOpts;
Justin Bogner953e2402014-09-20 15:31:56 +000085 std::string PGOFilename;
Alex Lorenze82d89c2014-08-22 22:56:03 +000086 CoverageFiltersMatchAll Filters;
87 std::vector<std::string> SourceFiles;
88 std::vector<std::pair<std::string, std::unique_ptr<MemoryBuffer>>>
89 LoadedSourceFiles;
Alex Lorenze82d89c2014-08-22 22:56:03 +000090 bool CompareFilenamesOnly;
Justin Bogner116c1662014-09-19 08:13:12 +000091 StringMap<std::string> RemappedFilenames;
Alex Lorenze82d89c2014-08-22 22:56:03 +000092};
93}
94
95void CodeCoverageTool::error(const Twine &Message, StringRef Whence) {
96 errs() << "error: ";
97 if (!Whence.empty())
98 errs() << Whence << ": ";
99 errs() << Message << "\n";
100}
101
102ErrorOr<const MemoryBuffer &>
103CodeCoverageTool::getSourceFile(StringRef SourceFile) {
Justin Bogner116c1662014-09-19 08:13:12 +0000104 // If we've remapped filenames, look up the real location for this file.
105 if (!RemappedFilenames.empty()) {
106 auto Loc = RemappedFilenames.find(SourceFile);
107 if (Loc != RemappedFilenames.end())
108 SourceFile = Loc->second;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000109 }
Justin Bogner116c1662014-09-19 08:13:12 +0000110 for (const auto &Files : LoadedSourceFiles)
111 if (sys::fs::equivalent(SourceFile, Files.first))
112 return *Files.second;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000113 auto Buffer = MemoryBuffer::getFile(SourceFile);
114 if (auto EC = Buffer.getError()) {
115 error(EC.message(), SourceFile);
116 return EC;
117 }
Justin Bogner116c1662014-09-19 08:13:12 +0000118 LoadedSourceFiles.push_back(
119 std::make_pair(SourceFile, std::move(Buffer.get())));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000120 return *LoadedSourceFiles.back().second;
121}
122
Justin Bogner953e2402014-09-20 15:31:56 +0000123void
124CodeCoverageTool::attachExpansionSubViews(SourceCoverageView &View,
125 ArrayRef<ExpansionRecord> Expansions,
126 CoverageMapping &Coverage) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000127 if (!ViewOpts.ShowExpandedRegions)
128 return;
Justin Bogner953e2402014-09-20 15:31:56 +0000129 for (const auto &Expansion : Expansions) {
130 auto ExpansionCoverage = Coverage.getCoverageForExpansion(Expansion);
131 if (ExpansionCoverage.empty())
Alex Lorenze82d89c2014-08-22 22:56:03 +0000132 continue;
Justin Bogner953e2402014-09-20 15:31:56 +0000133 auto SourceBuffer = getSourceFile(ExpansionCoverage.getFilename());
134 if (!SourceBuffer)
Alex Lorenze82d89c2014-08-22 22:56:03 +0000135 continue;
Justin Bogner953e2402014-09-20 15:31:56 +0000136
137 auto SubViewExpansions = ExpansionCoverage.getExpansions();
138 auto SubView = llvm::make_unique<SourceCoverageView>(
139 SourceBuffer.get(), ViewOpts, std::move(ExpansionCoverage));
140 attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
141 View.addExpansion(Expansion.Region, std::move(SubView));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000142 }
143}
144
Justin Bogner5a6edad2014-09-19 19:07:17 +0000145std::unique_ptr<SourceCoverageView>
Justin Bogner953e2402014-09-20 15:31:56 +0000146CodeCoverageTool::createFunctionView(const FunctionRecord &Function,
147 CoverageMapping &Coverage) {
148 auto FunctionCoverage = Coverage.getCoverageForFunction(Function);
149 if (FunctionCoverage.empty())
Justin Bogner5a6edad2014-09-19 19:07:17 +0000150 return nullptr;
Justin Bogner953e2402014-09-20 15:31:56 +0000151 auto SourceBuffer = getSourceFile(FunctionCoverage.getFilename());
Justin Bogner5a6edad2014-09-19 19:07:17 +0000152 if (!SourceBuffer)
153 return nullptr;
Justin Bogner953e2402014-09-20 15:31:56 +0000154
155 auto Expansions = FunctionCoverage.getExpansions();
156 auto View = llvm::make_unique<SourceCoverageView>(
157 SourceBuffer.get(), ViewOpts, std::move(FunctionCoverage));
158 attachExpansionSubViews(*View, Expansions, Coverage);
159
160 return View;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000161}
162
Justin Bogner953e2402014-09-20 15:31:56 +0000163std::unique_ptr<SourceCoverageView>
164CodeCoverageTool::createSourceFileView(StringRef SourceFile,
165 CoverageMapping &Coverage) {
Justin Bogner5a6edad2014-09-19 19:07:17 +0000166 auto SourceBuffer = getSourceFile(SourceFile);
167 if (!SourceBuffer)
168 return nullptr;
Justin Bogner953e2402014-09-20 15:31:56 +0000169 auto FileCoverage = Coverage.getCoverageForFile(SourceFile);
170 if (FileCoverage.empty())
Justin Bogner5a6edad2014-09-19 19:07:17 +0000171 return nullptr;
Justin Bogner953e2402014-09-20 15:31:56 +0000172
173 auto Expansions = FileCoverage.getExpansions();
174 auto View = llvm::make_unique<SourceCoverageView>(
175 SourceBuffer.get(), ViewOpts, std::move(FileCoverage));
176 attachExpansionSubViews(*View, Expansions, Coverage);
177
178 for (auto Function : Coverage.getInstantiations(SourceFile)) {
179 auto SubViewCoverage = Coverage.getCoverageForFunction(*Function);
180 auto SubViewExpansions = SubViewCoverage.getExpansions();
181 auto SubView = llvm::make_unique<SourceCoverageView>(
182 SourceBuffer.get(), ViewOpts, std::move(SubViewCoverage));
183 attachExpansionSubViews(*SubView, SubViewExpansions, Coverage);
184
185 if (SubView) {
Justin Bogner5e1400a2014-09-17 05:33:20 +0000186 unsigned FileID = Function->CountedRegions.front().FileID;
187 unsigned Line = 0;
188 for (const auto &CR : Function->CountedRegions)
189 if (CR.FileID == FileID)
190 Line = std::max(CR.LineEnd, Line);
Justin Bogner953e2402014-09-20 15:31:56 +0000191 View->addInstantiation(Function->Name, Line, std::move(SubView));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000192 }
193 }
Justin Bogner5a6edad2014-09-19 19:07:17 +0000194 return View;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000195}
196
Justin Bogner953e2402014-09-20 15:31:56 +0000197std::unique_ptr<CoverageMapping> CodeCoverageTool::load() {
Justin Bogner19a93ba2014-09-20 17:19:52 +0000198 auto CoverageOrErr = CoverageMapping::load(ObjectFilename, PGOFilename);
Justin Bogner953e2402014-09-20 15:31:56 +0000199 if (std::error_code EC = CoverageOrErr.getError()) {
200 colored_ostream(errs(), raw_ostream::RED)
201 << "error: Failed to load coverage: " << EC.message();
202 errs() << "\n";
203 return nullptr;
204 }
205 auto Coverage = std::move(CoverageOrErr.get());
206 unsigned Mismatched = Coverage->getMismatchedCount();
207 if (Mismatched) {
208 colored_ostream(errs(), raw_ostream::RED)
209 << "warning: " << Mismatched << " functions have mismatched data. ";
210 errs() << "\n";
Alex Lorenze82d89c2014-08-22 22:56:03 +0000211 }
Justin Bogner116c1662014-09-19 08:13:12 +0000212
213 if (CompareFilenamesOnly) {
Justin Bogner953e2402014-09-20 15:31:56 +0000214 auto CoveredFiles = Coverage.get()->getUniqueSourceFiles();
Justin Bogner116c1662014-09-19 08:13:12 +0000215 for (auto &SF : SourceFiles) {
216 StringRef SFBase = sys::path::filename(SF);
217 for (const auto &CF : CoveredFiles)
218 if (SFBase == sys::path::filename(CF)) {
219 RemappedFilenames[CF] = SF;
220 SF = CF;
221 break;
222 }
223 }
224 }
225
Justin Bogner953e2402014-09-20 15:31:56 +0000226 return Coverage;
Alex Lorenze82d89c2014-08-22 22:56:03 +0000227}
228
229int CodeCoverageTool::run(Command Cmd, int argc, const char **argv) {
230 // Print a stack trace if we signal out.
231 sys::PrintStackTraceOnErrorSignal();
232 PrettyStackTraceProgram X(argc, argv);
233 llvm_shutdown_obj Y; // Call llvm_shutdown() on exit.
234
Justin Bognerf6c50552014-10-30 20:51:24 +0000235 cl::opt<std::string, true> ObjectFilename(
236 cl::Positional, cl::Required, cl::location(this->ObjectFilename),
237 cl::desc("Covered executable or object file."));
238
Alex Lorenze82d89c2014-08-22 22:56:03 +0000239 cl::list<std::string> InputSourceFiles(
240 cl::Positional, cl::desc("<Source files>"), cl::ZeroOrMore);
241
Justin Bogner953e2402014-09-20 15:31:56 +0000242 cl::opt<std::string, true> PGOFilename(
243 "instr-profile", cl::Required, cl::location(this->PGOFilename),
Alex Lorenze82d89c2014-08-22 22:56:03 +0000244 cl::desc(
245 "File with the profile data obtained after an instrumented run"));
246
247 cl::opt<bool> DebugDump("dump", cl::Optional,
248 cl::desc("Show internal debug dump"));
249
250 cl::opt<bool> FilenameEquivalence(
251 "filename-equivalence", cl::Optional,
Justin Bogner116c1662014-09-19 08:13:12 +0000252 cl::desc("Treat source files as equivalent to paths in the coverage data "
253 "when the file names match, even if the full paths do not"));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000254
255 cl::OptionCategory FilteringCategory("Function filtering options");
256
257 cl::list<std::string> NameFilters(
258 "name", cl::Optional,
259 cl::desc("Show code coverage only for functions with the given name"),
260 cl::ZeroOrMore, cl::cat(FilteringCategory));
261
262 cl::list<std::string> NameRegexFilters(
263 "name-regex", cl::Optional,
264 cl::desc("Show code coverage only for functions that match the given "
265 "regular expression"),
266 cl::ZeroOrMore, cl::cat(FilteringCategory));
267
268 cl::opt<double> RegionCoverageLtFilter(
269 "region-coverage-lt", cl::Optional,
270 cl::desc("Show code coverage only for functions with region coverage "
271 "less than the given threshold"),
272 cl::cat(FilteringCategory));
273
274 cl::opt<double> RegionCoverageGtFilter(
275 "region-coverage-gt", cl::Optional,
276 cl::desc("Show code coverage only for functions with region coverage "
277 "greater than the given threshold"),
278 cl::cat(FilteringCategory));
279
280 cl::opt<double> LineCoverageLtFilter(
281 "line-coverage-lt", cl::Optional,
282 cl::desc("Show code coverage only for functions with line coverage less "
283 "than the given threshold"),
284 cl::cat(FilteringCategory));
285
286 cl::opt<double> LineCoverageGtFilter(
287 "line-coverage-gt", cl::Optional,
288 cl::desc("Show code coverage only for functions with line coverage "
289 "greater than the given threshold"),
290 cl::cat(FilteringCategory));
291
292 auto commandLineParser = [&, this](int argc, const char **argv) -> int {
293 cl::ParseCommandLineOptions(argc, argv, "LLVM code coverage tool\n");
294 ViewOpts.Debug = DebugDump;
295 CompareFilenamesOnly = FilenameEquivalence;
296
Alex Lorenze82d89c2014-08-22 22:56:03 +0000297 // Create the function filters
298 if (!NameFilters.empty() || !NameRegexFilters.empty()) {
299 auto NameFilterer = new CoverageFilters;
300 for (const auto &Name : NameFilters)
301 NameFilterer->push_back(llvm::make_unique<NameCoverageFilter>(Name));
302 for (const auto &Regex : NameRegexFilters)
303 NameFilterer->push_back(
304 llvm::make_unique<NameRegexCoverageFilter>(Regex));
305 Filters.push_back(std::unique_ptr<CoverageFilter>(NameFilterer));
306 }
307 if (RegionCoverageLtFilter.getNumOccurrences() ||
308 RegionCoverageGtFilter.getNumOccurrences() ||
309 LineCoverageLtFilter.getNumOccurrences() ||
310 LineCoverageGtFilter.getNumOccurrences()) {
311 auto StatFilterer = new CoverageFilters;
312 if (RegionCoverageLtFilter.getNumOccurrences())
313 StatFilterer->push_back(llvm::make_unique<RegionCoverageFilter>(
314 RegionCoverageFilter::LessThan, RegionCoverageLtFilter));
315 if (RegionCoverageGtFilter.getNumOccurrences())
316 StatFilterer->push_back(llvm::make_unique<RegionCoverageFilter>(
317 RegionCoverageFilter::GreaterThan, RegionCoverageGtFilter));
318 if (LineCoverageLtFilter.getNumOccurrences())
319 StatFilterer->push_back(llvm::make_unique<LineCoverageFilter>(
320 LineCoverageFilter::LessThan, LineCoverageLtFilter));
321 if (LineCoverageGtFilter.getNumOccurrences())
322 StatFilterer->push_back(llvm::make_unique<LineCoverageFilter>(
323 RegionCoverageFilter::GreaterThan, LineCoverageGtFilter));
324 Filters.push_back(std::unique_ptr<CoverageFilter>(StatFilterer));
325 }
326
Justin Bogner116c1662014-09-19 08:13:12 +0000327 for (const auto &File : InputSourceFiles) {
328 SmallString<128> Path(File);
329 if (std::error_code EC = sys::fs::make_absolute(Path)) {
330 errs() << "error: " << File << ": " << EC.message();
331 return 1;
332 }
333 SourceFiles.push_back(Path.str());
334 }
Alex Lorenze82d89c2014-08-22 22:56:03 +0000335 return 0;
336 };
337
Alex Lorenze82d89c2014-08-22 22:56:03 +0000338 switch (Cmd) {
339 case Show:
340 return show(argc, argv, commandLineParser);
341 case Report:
342 return report(argc, argv, commandLineParser);
343 }
344 return 0;
345}
346
347int CodeCoverageTool::show(int argc, const char **argv,
348 CommandLineParserType commandLineParser) {
349
350 cl::OptionCategory ViewCategory("Viewing options");
351
352 cl::opt<bool> ShowLineExecutionCounts(
353 "show-line-counts", cl::Optional,
354 cl::desc("Show the execution counts for each line"), cl::init(true),
355 cl::cat(ViewCategory));
356
357 cl::opt<bool> ShowRegions(
358 "show-regions", cl::Optional,
359 cl::desc("Show the execution counts for each region"),
360 cl::cat(ViewCategory));
361
362 cl::opt<bool> ShowBestLineRegionsCounts(
363 "show-line-counts-or-regions", cl::Optional,
364 cl::desc("Show the execution counts for each line, or the execution "
365 "counts for each region on lines that have multiple regions"),
366 cl::cat(ViewCategory));
367
368 cl::opt<bool> ShowExpansions("show-expansions", cl::Optional,
369 cl::desc("Show expanded source regions"),
370 cl::cat(ViewCategory));
371
372 cl::opt<bool> ShowInstantiations("show-instantiations", cl::Optional,
373 cl::desc("Show function instantiations"),
374 cl::cat(ViewCategory));
375
376 cl::opt<bool> NoColors("no-colors", cl::Optional,
377 cl::desc("Don't show text colors"), cl::init(false),
378 cl::cat(ViewCategory));
379
380 auto Err = commandLineParser(argc, argv);
381 if (Err)
382 return Err;
383
384 ViewOpts.Colors = !NoColors;
385 ViewOpts.ShowLineNumbers = true;
386 ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 ||
387 !ShowRegions || ShowBestLineRegionsCounts;
388 ViewOpts.ShowRegionMarkers = ShowRegions || ShowBestLineRegionsCounts;
389 ViewOpts.ShowLineStatsOrRegionMarkers = ShowBestLineRegionsCounts;
390 ViewOpts.ShowExpandedRegions = ShowExpansions;
391 ViewOpts.ShowFunctionInstantiations = ShowInstantiations;
392
Justin Bogner953e2402014-09-20 15:31:56 +0000393 auto Coverage = load();
394 if (!Coverage)
Alex Lorenze82d89c2014-08-22 22:56:03 +0000395 return 1;
396
397 if (!Filters.empty()) {
398 // Show functions
Justin Bogner953e2402014-09-20 15:31:56 +0000399 for (const auto &Function : Coverage->getCoveredFunctions()) {
400 if (!Filters.matches(Function))
Alex Lorenze82d89c2014-08-22 22:56:03 +0000401 continue;
Justin Bogner953e2402014-09-20 15:31:56 +0000402
403 auto mainView = createFunctionView(Function, *Coverage);
Justin Bogner5a6edad2014-09-19 19:07:17 +0000404 if (!mainView) {
405 ViewOpts.colored_ostream(outs(), raw_ostream::RED)
Justin Bogner953e2402014-09-20 15:31:56 +0000406 << "warning: Could not read coverage for '" << Function.Name;
Justin Bogner5a6edad2014-09-19 19:07:17 +0000407 outs() << "\n";
408 continue;
409 }
Justin Bogner953e2402014-09-20 15:31:56 +0000410 ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) << Function.Name
411 << ":";
Alex Lorenze82d89c2014-08-22 22:56:03 +0000412 outs() << "\n";
Justin Bogner5a6edad2014-09-19 19:07:17 +0000413 mainView->render(outs(), /*WholeFile=*/false);
Justin Bogner953e2402014-09-20 15:31:56 +0000414 outs() << "\n";
Alex Lorenze82d89c2014-08-22 22:56:03 +0000415 }
416 return 0;
417 }
418
419 // Show files
420 bool ShowFilenames = SourceFiles.size() != 1;
421
Justin Bogner116c1662014-09-19 08:13:12 +0000422 if (SourceFiles.empty())
Alex Lorenze82d89c2014-08-22 22:56:03 +0000423 // Get the source files from the function coverage mapping
Justin Bogner953e2402014-09-20 15:31:56 +0000424 for (StringRef Filename : Coverage->getUniqueSourceFiles())
Alex Lorenze82d89c2014-08-22 22:56:03 +0000425 SourceFiles.push_back(Filename);
Alex Lorenze82d89c2014-08-22 22:56:03 +0000426
427 for (const auto &SourceFile : SourceFiles) {
Justin Bogner953e2402014-09-20 15:31:56 +0000428 auto mainView = createSourceFileView(SourceFile, *Coverage);
Justin Bogner5a6edad2014-09-19 19:07:17 +0000429 if (!mainView) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000430 ViewOpts.colored_ostream(outs(), raw_ostream::RED)
431 << "warning: The file '" << SourceFile << "' isn't covered.";
432 outs() << "\n";
433 continue;
434 }
435
436 if (ShowFilenames) {
437 ViewOpts.colored_ostream(outs(), raw_ostream::CYAN) << SourceFile << ":";
438 outs() << "\n";
439 }
Justin Bogner5a6edad2014-09-19 19:07:17 +0000440 mainView->render(outs(), /*Wholefile=*/true);
Alex Lorenze82d89c2014-08-22 22:56:03 +0000441 if (SourceFiles.size() > 1)
442 outs() << "\n";
443 }
444
445 return 0;
446}
447
448int CodeCoverageTool::report(int argc, const char **argv,
449 CommandLineParserType commandLineParser) {
450 cl::opt<bool> NoColors("no-colors", cl::Optional,
451 cl::desc("Don't show text colors"), cl::init(false));
452
453 auto Err = commandLineParser(argc, argv);
454 if (Err)
455 return Err;
456
457 ViewOpts.Colors = !NoColors;
458
Justin Bogner953e2402014-09-20 15:31:56 +0000459 auto Coverage = load();
460 if (!Coverage)
Alex Lorenze82d89c2014-08-22 22:56:03 +0000461 return 1;
462
463 CoverageSummary Summarizer;
Justin Bognerd5fca922014-11-14 01:50:32 +0000464 Summarizer.createSummaries(*Coverage);
Alex Lorenze82d89c2014-08-22 22:56:03 +0000465 CoverageReport Report(ViewOpts, Summarizer);
466 if (SourceFiles.empty() && Filters.empty()) {
467 Report.renderFileReports(llvm::outs());
468 return 0;
469 }
470
471 Report.renderFunctionReports(llvm::outs());
472 return 0;
473}
474
Justin Bognerd249a3b2014-10-30 20:57:49 +0000475int showMain(int argc, const char *argv[]) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000476 CodeCoverageTool Tool;
477 return Tool.run(CodeCoverageTool::Show, argc, argv);
478}
479
Justin Bognerd249a3b2014-10-30 20:57:49 +0000480int reportMain(int argc, const char *argv[]) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000481 CodeCoverageTool Tool;
482 return Tool.run(CodeCoverageTool::Report, argc, argv);
483}