blob: aafdc433775d190778a6b41adcfa17d151f0c5cf [file] [log] [blame]
Alex Lorenze82d89c2014-08-22 22:56:03 +00001//===- CoverageReport.cpp - Code coverage report -------------------------===//
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// This class implements rendering of a code coverage report.
11//
12//===----------------------------------------------------------------------===//
13
14#include "CoverageReport.h"
Alex Lorenze82d89c2014-08-22 22:56:03 +000015#include "RenderingSupport.h"
Vedant Kumar016111f2016-09-19 00:38:23 +000016#include "llvm/ADT/DenseMap.h"
Chandler Carruthd9903882015-01-14 11:23:27 +000017#include "llvm/Support/Format.h"
Vedant Kumard938dfb2016-09-09 17:37:11 +000018#include "llvm/Support/Path.h"
Max Morozcc254ba2018-01-05 16:15:07 +000019#include "llvm/Support/ThreadPool.h"
20#include "llvm/Support/Threading.h"
Vedant Kumar702bb9d2016-09-06 22:45:57 +000021#include <numeric>
Alex Lorenze82d89c2014-08-22 22:56:03 +000022
23using namespace llvm;
Vedant Kumar702bb9d2016-09-06 22:45:57 +000024
Alex Lorenze82d89c2014-08-22 22:56:03 +000025namespace {
Vedant Kumar702bb9d2016-09-06 22:45:57 +000026
Alex Lorenze82d89c2014-08-22 22:56:03 +000027/// \brief Helper struct which prints trimmed and aligned columns.
28struct Column {
Vedant Kumar702bb9d2016-09-06 22:45:57 +000029 enum TrimKind { NoTrim, WidthTrim, RightTrim };
Alex Lorenze82d89c2014-08-22 22:56:03 +000030
31 enum AlignmentKind { LeftAlignment, RightAlignment };
32
33 StringRef Str;
34 unsigned Width;
35 TrimKind Trim;
36 AlignmentKind Alignment;
37
38 Column(StringRef Str, unsigned Width)
Vedant Kumarc3c39e72015-09-14 23:26:36 +000039 : Str(Str), Width(Width), Trim(WidthTrim), Alignment(LeftAlignment) {}
Alex Lorenze82d89c2014-08-22 22:56:03 +000040
41 Column &set(TrimKind Value) {
42 Trim = Value;
43 return *this;
44 }
45
46 Column &set(AlignmentKind Value) {
47 Alignment = Value;
48 return *this;
49 }
50
Vedant Kumar702bb9d2016-09-06 22:45:57 +000051 void render(raw_ostream &OS) const {
52 if (Str.size() <= Width) {
53 if (Alignment == RightAlignment) {
54 OS.indent(Width - Str.size());
55 OS << Str;
56 return;
57 }
58 OS << Str;
59 OS.indent(Width - Str.size());
60 return;
61 }
62
63 switch (Trim) {
64 case NoTrim:
65 OS << Str;
66 break;
67 case WidthTrim:
68 OS << Str.substr(0, Width);
69 break;
70 case RightTrim:
71 OS << Str.substr(0, Width - 3) << "...";
72 break;
73 }
74 }
Alex Lorenze82d89c2014-08-22 22:56:03 +000075};
Vedant Kumarc3c39e72015-09-14 23:26:36 +000076
Alex Lorenze82d89c2014-08-22 22:56:03 +000077raw_ostream &operator<<(raw_ostream &OS, const Column &Value) {
78 Value.render(OS);
79 return OS;
80}
Alex Lorenze82d89c2014-08-22 22:56:03 +000081
Vedant Kumar702bb9d2016-09-06 22:45:57 +000082Column column(StringRef Str, unsigned Width) { return Column(Str, Width); }
Alex Lorenze82d89c2014-08-22 22:56:03 +000083
84template <typename T>
Vedant Kumar702bb9d2016-09-06 22:45:57 +000085Column column(StringRef Str, unsigned Width, const T &Value) {
Alex Lorenze82d89c2014-08-22 22:56:03 +000086 return Column(Str, Width).set(Value);
87}
88
Ying Yie59ee432016-07-22 12:46:13 +000089// Specify the default column widths.
Vedant Kumar016111f2016-09-19 00:38:23 +000090size_t FileReportColumns[] = {25, 12, 18, 10, 12, 18, 10,
91 16, 16, 10, 12, 18, 10};
Vedant Kumar702bb9d2016-09-06 22:45:57 +000092size_t FunctionReportColumns[] = {25, 10, 8, 8, 10, 8, 8};
Alex Lorenze82d89c2014-08-22 22:56:03 +000093
Vedant Kumar702bb9d2016-09-06 22:45:57 +000094/// \brief Adjust column widths to fit long file paths and function names.
Vedant Kumardab0ec12016-09-19 00:38:16 +000095void adjustColumnWidths(ArrayRef<StringRef> Files,
96 ArrayRef<StringRef> Functions) {
97 for (StringRef Filename : Files)
Vedant Kumaraaead332015-10-21 16:03:32 +000098 FileReportColumns[0] = std::max(FileReportColumns[0], Filename.size());
Vedant Kumardab0ec12016-09-19 00:38:16 +000099 for (StringRef Funcname : Functions)
100 FunctionReportColumns[0] =
101 std::max(FunctionReportColumns[0], Funcname.size());
Vedant Kumaraaead332015-10-21 16:03:32 +0000102}
103
Vedant Kumar702bb9d2016-09-06 22:45:57 +0000104/// \brief Prints a horizontal divider long enough to cover the given column
105/// widths.
106void renderDivider(ArrayRef<size_t> ColumnWidths, raw_ostream &OS) {
107 size_t Length = std::accumulate(ColumnWidths.begin(), ColumnWidths.end(), 0);
108 for (size_t I = 0; I < Length; ++I)
Alex Lorenze82d89c2014-08-22 22:56:03 +0000109 OS << '-';
110}
111
Vedant Kumar5053b112016-09-06 22:46:00 +0000112/// \brief Return the color which correponds to the coverage percentage of a
113/// certain metric.
Alex Lorenze82d89c2014-08-22 22:56:03 +0000114template <typename T>
Vedant Kumar702bb9d2016-09-06 22:45:57 +0000115raw_ostream::Colors determineCoveragePercentageColor(const T &Info) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000116 if (Info.isFullyCovered())
117 return raw_ostream::GREEN;
118 return Info.getPercentCovered() >= 80.0 ? raw_ostream::YELLOW
119 : raw_ostream::RED;
120}
121
Vedant Kumar11813282017-02-23 22:20:32 +0000122/// \brief Get the number of redundant path components in each path in \p Paths.
123unsigned getNumRedundantPathComponents(ArrayRef<std::string> Paths) {
124 // To start, set the number of redundant path components to the maximum
125 // possible value.
126 SmallVector<StringRef, 8> FirstPathComponents{sys::path::begin(Paths[0]),
127 sys::path::end(Paths[0])};
128 unsigned NumRedundant = FirstPathComponents.size();
129
130 for (unsigned I = 1, E = Paths.size(); NumRedundant > 0 && I < E; ++I) {
131 StringRef Path = Paths[I];
132 for (const auto &Component :
133 enumerate(make_range(sys::path::begin(Path), sys::path::end(Path)))) {
134 // Do not increase the number of redundant components: that would remove
135 // useful parts of already-visited paths.
Zachary Turner368c3fa2017-03-13 16:32:08 +0000136 if (Component.index() >= NumRedundant)
Vedant Kumar5cd496b2016-09-26 17:57:13 +0000137 break;
Vedant Kumar11813282017-02-23 22:20:32 +0000138
139 // Lower the number of redundant components when there's a mismatch
140 // between the first path, and the path under consideration.
Zachary Turner368c3fa2017-03-13 16:32:08 +0000141 if (FirstPathComponents[Component.index()] != Component.value()) {
142 NumRedundant = Component.index();
Vedant Kumar11813282017-02-23 22:20:32 +0000143 break;
144 }
145 }
Vedant Kumarfa754372016-09-08 00:56:43 +0000146 }
Vedant Kumar11813282017-02-23 22:20:32 +0000147
148 return NumRedundant;
149}
150
151/// \brief Determine the length of the longest redundant prefix of the paths in
152/// \p Paths.
153unsigned getRedundantPrefixLen(ArrayRef<std::string> Paths) {
154 // If there's at most one path, no path components are redundant.
155 if (Paths.size() <= 1)
156 return 0;
157
158 unsigned PrefixLen = 0;
159 unsigned NumRedundant = getNumRedundantPathComponents(Paths);
160 auto Component = sys::path::begin(Paths[0]);
161 for (unsigned I = 0; I < NumRedundant; ++I) {
162 auto LastComponent = Component;
163 ++Component;
164 PrefixLen += Component - LastComponent;
165 }
166 return PrefixLen;
Vedant Kumarfa754372016-09-08 00:56:43 +0000167}
168
Vedant Kumar702bb9d2016-09-06 22:45:57 +0000169} // end anonymous namespace
170
171namespace llvm {
172
Vedant Kumar627887b62016-09-09 01:32:49 +0000173void CoverageReport::render(const FileCoverageSummary &File,
174 raw_ostream &OS) const {
Vedant Kumar5053b112016-09-06 22:46:00 +0000175 auto FileCoverageColor =
176 determineCoveragePercentageColor(File.RegionCoverage);
177 auto FuncCoverageColor =
178 determineCoveragePercentageColor(File.FunctionCoverage);
Vedant Kumar016111f2016-09-19 00:38:23 +0000179 auto InstantiationCoverageColor =
180 determineCoveragePercentageColor(File.InstantiationCoverage);
Vedant Kumar5053b112016-09-06 22:46:00 +0000181 auto LineCoverageColor = determineCoveragePercentageColor(File.LineCoverage);
Vedant Kumard938dfb2016-09-09 17:37:11 +0000182 SmallString<256> FileName = File.Name;
183 sys::path::remove_dots(FileName, /*remove_dot_dots=*/true);
184 sys::path::native(FileName);
Eli Friedman50479f62017-09-11 22:56:20 +0000185 OS << column(FileName, FileReportColumns[0], Column::NoTrim);
186
187 if (Options.ShowRegionSummary) {
188 OS << format("%*u", FileReportColumns[1],
Vedant Kumarc445e652017-09-15 23:00:01 +0000189 (unsigned)File.RegionCoverage.getNumRegions());
190 Options.colored_ostream(OS, FileCoverageColor)
191 << format("%*u", FileReportColumns[2],
192 (unsigned)(File.RegionCoverage.getNumRegions() -
193 File.RegionCoverage.getCovered()));
194 if (File.RegionCoverage.getNumRegions())
Eli Friedman50479f62017-09-11 22:56:20 +0000195 Options.colored_ostream(OS, FileCoverageColor)
196 << format("%*.2f", FileReportColumns[3] - 1,
197 File.RegionCoverage.getPercentCovered())
198 << '%';
199 else
200 OS << column("-", FileReportColumns[3], Column::RightAlignment);
201 }
202
NAKAMURA Takumi46d2e0e2014-10-01 00:29:26 +0000203 OS << format("%*u", FileReportColumns[4],
Vedant Kumarc445e652017-09-15 23:00:01 +0000204 (unsigned)File.FunctionCoverage.getNumFunctions());
Ying Yie59ee432016-07-22 12:46:13 +0000205 OS << format("%*u", FileReportColumns[5],
Vedant Kumarc445e652017-09-15 23:00:01 +0000206 (unsigned)(File.FunctionCoverage.getNumFunctions() -
207 File.FunctionCoverage.getExecuted()));
208 if (File.FunctionCoverage.getNumFunctions())
Alex Lorenz35369c12016-11-21 14:00:04 +0000209 Options.colored_ostream(OS, FuncCoverageColor)
210 << format("%*.2f", FileReportColumns[6] - 1,
211 File.FunctionCoverage.getPercentCovered())
212 << '%';
213 else
214 OS << column("-", FileReportColumns[6], Column::RightAlignment);
Eli Friedman50479f62017-09-11 22:56:20 +0000215
216 if (Options.ShowInstantiationSummary) {
217 OS << format("%*u", FileReportColumns[7],
Vedant Kumarc445e652017-09-15 23:00:01 +0000218 (unsigned)File.InstantiationCoverage.getNumFunctions());
Eli Friedman50479f62017-09-11 22:56:20 +0000219 OS << format("%*u", FileReportColumns[8],
Vedant Kumarc445e652017-09-15 23:00:01 +0000220 (unsigned)(File.InstantiationCoverage.getNumFunctions() -
221 File.InstantiationCoverage.getExecuted()));
222 if (File.InstantiationCoverage.getNumFunctions())
Eli Friedman50479f62017-09-11 22:56:20 +0000223 Options.colored_ostream(OS, InstantiationCoverageColor)
224 << format("%*.2f", FileReportColumns[9] - 1,
225 File.InstantiationCoverage.getPercentCovered())
226 << '%';
227 else
228 OS << column("-", FileReportColumns[9], Column::RightAlignment);
229 }
230
Vedant Kumar016111f2016-09-19 00:38:23 +0000231 OS << format("%*u", FileReportColumns[10],
Vedant Kumarc445e652017-09-15 23:00:01 +0000232 (unsigned)File.LineCoverage.getNumLines());
Vedant Kumar5053b112016-09-06 22:46:00 +0000233 Options.colored_ostream(OS, LineCoverageColor) << format(
Vedant Kumarc445e652017-09-15 23:00:01 +0000234 "%*u", FileReportColumns[11], (unsigned)(File.LineCoverage.getNumLines() -
235 File.LineCoverage.getCovered()));
236 if (File.LineCoverage.getNumLines())
Alex Lorenz35369c12016-11-21 14:00:04 +0000237 Options.colored_ostream(OS, LineCoverageColor)
238 << format("%*.2f", FileReportColumns[12] - 1,
239 File.LineCoverage.getPercentCovered())
240 << '%';
241 else
242 OS << column("-", FileReportColumns[12], Column::RightAlignment);
Alex Lorenze82d89c2014-08-22 22:56:03 +0000243 OS << "\n";
244}
245
246void CoverageReport::render(const FunctionCoverageSummary &Function,
Vedant Kumarf2b067c2017-02-05 20:11:03 +0000247 const DemangleCache &DC,
Vedant Kumar627887b62016-09-09 01:32:49 +0000248 raw_ostream &OS) const {
Vedant Kumar5053b112016-09-06 22:46:00 +0000249 auto FuncCoverageColor =
250 determineCoveragePercentageColor(Function.RegionCoverage);
251 auto LineCoverageColor =
252 determineCoveragePercentageColor(Function.LineCoverage);
Vedant Kumarf2b067c2017-02-05 20:11:03 +0000253 OS << column(DC.demangle(Function.Name), FunctionReportColumns[0],
254 Column::RightTrim)
NAKAMURA Takumi46d2e0e2014-10-01 00:29:26 +0000255 << format("%*u", FunctionReportColumns[1],
Vedant Kumarc445e652017-09-15 23:00:01 +0000256 (unsigned)Function.RegionCoverage.getNumRegions());
Vedant Kumar5053b112016-09-06 22:46:00 +0000257 Options.colored_ostream(OS, FuncCoverageColor)
NAKAMURA Takumi46d2e0e2014-10-01 00:29:26 +0000258 << format("%*u", FunctionReportColumns[2],
Vedant Kumarc445e652017-09-15 23:00:01 +0000259 (unsigned)(Function.RegionCoverage.getNumRegions() -
260 Function.RegionCoverage.getCovered()));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000261 Options.colored_ostream(
262 OS, determineCoveragePercentageColor(Function.RegionCoverage))
263 << format("%*.2f", FunctionReportColumns[3] - 1,
Vedant Kumar5053b112016-09-06 22:46:00 +0000264 Function.RegionCoverage.getPercentCovered())
265 << '%';
NAKAMURA Takumi46d2e0e2014-10-01 00:29:26 +0000266 OS << format("%*u", FunctionReportColumns[4],
Vedant Kumarc445e652017-09-15 23:00:01 +0000267 (unsigned)Function.LineCoverage.getNumLines());
Vedant Kumar5053b112016-09-06 22:46:00 +0000268 Options.colored_ostream(OS, LineCoverageColor)
NAKAMURA Takumi46d2e0e2014-10-01 00:29:26 +0000269 << format("%*u", FunctionReportColumns[5],
Vedant Kumarc445e652017-09-15 23:00:01 +0000270 (unsigned)(Function.LineCoverage.getNumLines() -
271 Function.LineCoverage.getCovered()));
Alex Lorenze82d89c2014-08-22 22:56:03 +0000272 Options.colored_ostream(
273 OS, determineCoveragePercentageColor(Function.LineCoverage))
274 << format("%*.2f", FunctionReportColumns[6] - 1,
Vedant Kumar5053b112016-09-06 22:46:00 +0000275 Function.LineCoverage.getPercentCovered())
276 << '%';
Alex Lorenze82d89c2014-08-22 22:56:03 +0000277 OS << "\n";
278}
279
Vedant Kumarbc647982016-09-23 18:57:32 +0000280void CoverageReport::renderFunctionReports(ArrayRef<std::string> Files,
Vedant Kumarf2b067c2017-02-05 20:11:03 +0000281 const DemangleCache &DC,
Justin Bogner0ef7a2a2015-02-14 02:05:05 +0000282 raw_ostream &OS) {
Alex Lorenze82d89c2014-08-22 22:56:03 +0000283 bool isFirst = true;
Justin Bogner0ef7a2a2015-02-14 02:05:05 +0000284 for (StringRef Filename : Files) {
Vedant Kumardab0ec12016-09-19 00:38:16 +0000285 auto Functions = Coverage.getCoveredFunctions(Filename);
286
Alex Lorenze82d89c2014-08-22 22:56:03 +0000287 if (isFirst)
288 isFirst = false;
289 else
290 OS << "\n";
Vedant Kumardab0ec12016-09-19 00:38:16 +0000291
292 std::vector<StringRef> Funcnames;
293 for (const auto &F : Functions)
Vedant Kumarf2b067c2017-02-05 20:11:03 +0000294 Funcnames.emplace_back(DC.demangle(F.Name));
Vedant Kumardab0ec12016-09-19 00:38:16 +0000295 adjustColumnWidths({}, Funcnames);
296
Justin Bognerf91bc6c2015-02-14 02:01:24 +0000297 OS << "File '" << Filename << "':\n";
Alex Lorenze82d89c2014-08-22 22:56:03 +0000298 OS << column("Name", FunctionReportColumns[0])
299 << column("Regions", FunctionReportColumns[1], Column::RightAlignment)
300 << column("Miss", FunctionReportColumns[2], Column::RightAlignment)
301 << column("Cover", FunctionReportColumns[3], Column::RightAlignment)
302 << column("Lines", FunctionReportColumns[4], Column::RightAlignment)
303 << column("Miss", FunctionReportColumns[5], Column::RightAlignment)
304 << column("Cover", FunctionReportColumns[6], Column::RightAlignment);
305 OS << "\n";
306 renderDivider(FunctionReportColumns, OS);
307 OS << "\n";
Justin Bognerf91bc6c2015-02-14 02:01:24 +0000308 FunctionCoverageSummary Totals("TOTAL");
Vedant Kumardab0ec12016-09-19 00:38:16 +0000309 for (const auto &F : Functions) {
Vedant Kumarb7fdaf22017-09-19 02:00:12 +0000310 auto Function = FunctionCoverageSummary::get(Coverage, F);
Justin Bognerf91bc6c2015-02-14 02:01:24 +0000311 ++Totals.ExecutionCount;
312 Totals.RegionCoverage += Function.RegionCoverage;
313 Totals.LineCoverage += Function.LineCoverage;
Vedant Kumarf2b067c2017-02-05 20:11:03 +0000314 render(Function, DC, OS);
Justin Bognerf91bc6c2015-02-14 02:01:24 +0000315 }
316 if (Totals.ExecutionCount) {
317 renderDivider(FunctionReportColumns, OS);
318 OS << "\n";
Vedant Kumarf2b067c2017-02-05 20:11:03 +0000319 render(Totals, DC, OS);
Justin Bognerf91bc6c2015-02-14 02:01:24 +0000320 }
Alex Lorenze82d89c2014-08-22 22:56:03 +0000321 }
322}
323
Max Morozcc254ba2018-01-05 16:15:07 +0000324void CoverageReport::prepareSingleFileReport(const StringRef Filename,
325 const coverage::CoverageMapping *Coverage,
326 const CoverageViewOptions &Options, const unsigned LCP,
327 FileCoverageSummary *FileReport, const CoverageFilter *Filters) {
328 for (const auto &Group : Coverage->getInstantiationGroups(Filename)) {
329 std::vector<FunctionCoverageSummary> InstantiationSummaries;
330 for (const coverage::FunctionRecord *F : Group.getInstantiations()) {
331 if (!Filters->matches(*Coverage, *F))
332 continue;
333 auto InstantiationSummary = FunctionCoverageSummary::get(*Coverage, *F);
334 FileReport->addInstantiation(InstantiationSummary);
335 InstantiationSummaries.push_back(InstantiationSummary);
336 }
337 if (InstantiationSummaries.empty())
338 continue;
339
340 auto GroupSummary =
341 FunctionCoverageSummary::get(Group, InstantiationSummaries);
342
343 if (Options.Debug)
344 outs() << "InstantiationGroup: " << GroupSummary.Name << " with "
345 << "size = " << Group.size() << "\n";
346
347 FileReport->addFunction(GroupSummary);
348 }
349}
350
Vedant Kumar72c3a112017-09-08 18:44:49 +0000351std::vector<FileCoverageSummary> CoverageReport::prepareFileReports(
352 const coverage::CoverageMapping &Coverage, FileCoverageSummary &Totals,
Sean Evesonfa8ef352017-09-28 10:07:30 +0000353 ArrayRef<std::string> Files, const CoverageViewOptions &Options,
354 const CoverageFilter &Filters) {
Vedant Kumar11813282017-02-23 22:20:32 +0000355 unsigned LCP = getRedundantPrefixLen(Files);
Max Morozcc254ba2018-01-05 16:15:07 +0000356 auto NumThreads = Options.NumThreads;
357
358 // If NumThreads is not specified, auto-detect a good default.
359 if (NumThreads == 0)
360 NumThreads =
361 std::max(1U, std::min(llvm::heavyweight_hardware_concurrency(),
362 unsigned(Files.size())));
363
364 ThreadPool Pool(NumThreads);
365
366 std::vector<FileCoverageSummary> FileReports;
367 FileReports.reserve(Files.size());
Vedant Kumar627887b62016-09-09 01:32:49 +0000368
369 for (StringRef Filename : Files) {
Max Morozcc254ba2018-01-05 16:15:07 +0000370 FileReports.emplace_back(Filename.drop_front(LCP));
371 Pool.async(&CoverageReport::prepareSingleFileReport, Filename,
372 &Coverage, Options, LCP, &FileReports.back(), &Filters);
Vedant Kumar627887b62016-09-09 01:32:49 +0000373 }
Max Morozcc254ba2018-01-05 16:15:07 +0000374 Pool.wait();
375
376 for (const auto &FileReport : FileReports)
377 Totals += FileReport;
Vedant Kumar627887b62016-09-09 01:32:49 +0000378
379 return FileReports;
380}
381
382void CoverageReport::renderFileReports(raw_ostream &OS) const {
Vedant Kumarbc647982016-09-23 18:57:32 +0000383 std::vector<std::string> UniqueSourceFiles;
384 for (StringRef SF : Coverage.getUniqueSourceFiles())
385 UniqueSourceFiles.emplace_back(SF.str());
Max Moroz4a4bfa42017-10-13 14:44:51 +0000386 renderFileReports(OS, UniqueSourceFiles);
387}
388
389void CoverageReport::renderFileReports(
390 raw_ostream &OS, ArrayRef<std::string> Files) const {
391 renderFileReports(OS, Files, CoverageFiltersMatchAll());
Vedant Kumar627887b62016-09-09 01:32:49 +0000392}
393
Sean Evesond932b2d2017-10-03 11:05:28 +0000394void CoverageReport::renderFileReports(
395 raw_ostream &OS, ArrayRef<std::string> Files,
396 const CoverageFiltersMatchAll &Filters) const {
Vedant Kumardab0ec12016-09-19 00:38:16 +0000397 FileCoverageSummary Totals("TOTAL");
Sean Evesonfa8ef352017-09-28 10:07:30 +0000398 auto FileReports =
399 prepareFileReports(Coverage, Totals, Files, Options, Filters);
Vedant Kumardab0ec12016-09-19 00:38:16 +0000400
401 std::vector<StringRef> Filenames;
402 for (const FileCoverageSummary &FCS : FileReports)
403 Filenames.emplace_back(FCS.Name);
404 adjustColumnWidths(Filenames, {});
405
Eli Friedman50479f62017-09-11 22:56:20 +0000406 OS << column("Filename", FileReportColumns[0]);
407 if (Options.ShowRegionSummary)
408 OS << column("Regions", FileReportColumns[1], Column::RightAlignment)
409 << column("Missed Regions", FileReportColumns[2], Column::RightAlignment)
410 << column("Cover", FileReportColumns[3], Column::RightAlignment);
411 OS << column("Functions", FileReportColumns[4], Column::RightAlignment)
Vedant Kumar5053b112016-09-06 22:46:00 +0000412 << column("Missed Functions", FileReportColumns[5], Column::RightAlignment)
Eli Friedman50479f62017-09-11 22:56:20 +0000413 << column("Executed", FileReportColumns[6], Column::RightAlignment);
414 if (Options.ShowInstantiationSummary)
415 OS << column("Instantiations", FileReportColumns[7], Column::RightAlignment)
416 << column("Missed Insts.", FileReportColumns[8], Column::RightAlignment)
417 << column("Executed", FileReportColumns[9], Column::RightAlignment);
418 OS << column("Lines", FileReportColumns[10], Column::RightAlignment)
Vedant Kumar016111f2016-09-19 00:38:23 +0000419 << column("Missed Lines", FileReportColumns[11], Column::RightAlignment)
420 << column("Cover", FileReportColumns[12], Column::RightAlignment) << "\n";
Alex Lorenze82d89c2014-08-22 22:56:03 +0000421 renderDivider(FileReportColumns, OS);
422 OS << "\n";
Vedant Kumarc3c39e72015-09-14 23:26:36 +0000423
Eli Friedmanc0c182c2017-08-09 20:43:31 +0000424 bool EmptyFiles = false;
425 for (const FileCoverageSummary &FCS : FileReports) {
Vedant Kumarc445e652017-09-15 23:00:01 +0000426 if (FCS.FunctionCoverage.getNumFunctions())
Eli Friedmanc0c182c2017-08-09 20:43:31 +0000427 render(FCS, OS);
428 else
429 EmptyFiles = true;
430 }
431
Sean Evesond932b2d2017-10-03 11:05:28 +0000432 if (EmptyFiles && Filters.empty()) {
Eli Friedmanc0c182c2017-08-09 20:43:31 +0000433 OS << "\n"
434 << "Files which contain no functions:\n";
435
436 for (const FileCoverageSummary &FCS : FileReports)
Vedant Kumarc445e652017-09-15 23:00:01 +0000437 if (!FCS.FunctionCoverage.getNumFunctions())
Eli Friedmanc0c182c2017-08-09 20:43:31 +0000438 render(FCS, OS);
439 }
Vedant Kumar627887b62016-09-09 01:32:49 +0000440
Alex Lorenze82d89c2014-08-22 22:56:03 +0000441 renderDivider(FileReportColumns, OS);
442 OS << "\n";
Justin Bognerf91bc6c2015-02-14 02:01:24 +0000443 render(Totals, OS);
Alex Lorenze82d89c2014-08-22 22:56:03 +0000444}
Vedant Kumar702bb9d2016-09-06 22:45:57 +0000445
446} // end namespace llvm