llvm.org GIT mirror llvm / 9bcc2d4
[llvm-cov] Rearrange entries in report index. Files which don't contain any functions are likely useless; don't include them in the main table. Put the links at the bottom of the page, in case someone wants to figure out coverage for code inside a macro. Not sure if this is the best solution, but it seems like an improvement. Differential Revision: https://reviews.llvm.org/D36298 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310518 91177308-0d34-0410-b5e6-96231b3b80d8 Eli Friedman 2 years ago
4 changed file(s) with 62 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
99 // RUN: llvm-profdata merge %S/Inputs/zeroFunctionFile.proftext -o %t.profdata
1010
1111 // RUN: llvm-cov report %S/Inputs/zeroFunctionFile.covmapping -instr-profile %t.profdata 2>&1 | FileCheck --check-prefix=REPORT --strict-whitespace %s
12 // REPORT: 0 0 - 0 0 - 0 0 - 0 0 -
13 // REPORT-NO: 0%
12 // REPORT: Files which contain no functions
13 // REPORT: zeroFunctionFile.h
1414
1515 // RUN: llvm-cov show -j 1 %S/Inputs/zeroFunctionFile.covmapping -format html -instr-profile %t.profdata -o %t.dir
1616 // RUN: FileCheck %s -input-file=%t.dir/index.html -check-prefix=HTML
17 // HTML:
- (0/0)

                  
                
1817 // HTML-NO: 0.00% (0/0)
18 // HTML: Files which contain no functions
19 // HTML: zeroFunctionFile.h
370370 renderDivider(FileReportColumns, OS);
371371 OS << "\n";
372372
373 for (const FileCoverageSummary &FCS : FileReports)
374 render(FCS, OS);
373 bool EmptyFiles = false;
374 for (const FileCoverageSummary &FCS : FileReports) {
375 if (FCS.FunctionCoverage.NumFunctions)
376 render(FCS, OS);
377 else
378 EmptyFiles = true;
379 }
380
381 if (EmptyFiles) {
382 OS << "\n"
383 << "Files which contain no functions:\n";
384
385 for (const FileCoverageSummary &FCS : FileReports)
386 if (!FCS.FunctionCoverage.NumFunctions)
387 render(FCS, OS);
388 }
375389
376390 renderDivider(FileReportColumns, OS);
377391 OS << "\n";
293293 OS << tag("tr", join(Columns.begin(), Columns.end(), ""));
294294 }
295295
296 std::string
297 CoveragePrinterHTML::buildLinkToFile(StringRef SF,
298 const FileCoverageSummary &FCS) const {
299 SmallString<128> LinkTextStr(sys::path::relative_path(FCS.Name));
300 sys::path::remove_dots(LinkTextStr, /*remove_dot_dots=*/true);
301 sys::path::native(LinkTextStr);
302 std::string LinkText = escape(LinkTextStr, Opts);
303 std::string LinkTarget =
304 escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts);
305 return a(LinkTarget, LinkText);
306 }
307
296308 /// Render a file coverage summary (\p FCS) in a table row. If \p IsTotals is
297309 /// false, link the summary to \p SF.
298310 void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
325337 if (IsTotals) {
326338 Filename = "TOTALS";
327339 } else {
328 SmallString<128> LinkTextStr(sys::path::relative_path(FCS.Name));
329 sys::path::remove_dots(LinkTextStr, /*remove_dot_dots=*/true);
330 sys::path::native(LinkTextStr);
331 std::string LinkText = escape(LinkTextStr, Opts);
332 std::string LinkTarget =
333 escape(getOutputPath(SF, "html", /*InToplevel=*/false), Opts);
334 Filename = a(LinkTarget, LinkText);
340 Filename = buildLinkToFile(SF, FCS);
335341 }
336342
337343 Columns.emplace_back(tag("td", tag("pre", Filename)));
386392 " for information about interpreting this report.");
387393
388394 // Emit a table containing links to reports for each file in the covmapping.
395 // Exclude files which don't contain any regions.
389396 OSRef << BeginCenteredDiv << BeginTable;
390397 emitColumnLabelsForIndex(OSRef);
391398 FileCoverageSummary Totals("TOTALS");
392399 auto FileReports =
393400 CoverageReport::prepareFileReports(Coverage, Totals, SourceFiles);
394 for (unsigned I = 0, E = FileReports.size(); I < E; ++I)
395 emitFileSummary(OSRef, SourceFiles[I], FileReports[I]);
401 bool EmptyFiles = false;
402 for (unsigned I = 0, E = FileReports.size(); I < E; ++I) {
403 if (FileReports[I].FunctionCoverage.NumFunctions)
404 emitFileSummary(OSRef, SourceFiles[I], FileReports[I]);
405 else
406 EmptyFiles = true;
407 }
396408 emitFileSummary(OSRef, "Totals", Totals, /*IsTotals=*/true);
397 OSRef << EndTable << EndCenteredDiv
398 << tag("h5", escape(Opts.getLLVMVersionString(), Opts));
409 OSRef << EndTable << EndCenteredDiv;
410
411 // Emit links to files which don't contain any functions. These are normally
412 // not very useful, but could be relevant for code which abuses the
413 // preprocessor.
414 if (EmptyFiles) {
415 OSRef << tag("p", "Files which contain no functions. (These "
416 "files contain code pulled into other files "
417 "by the preprocessor.)\n");
418 OSRef << BeginCenteredDiv << BeginTable;
419 for (unsigned I = 0, E = FileReports.size(); I < E; ++I)
420 if (!FileReports[I].FunctionCoverage.NumFunctions) {
421 std::string Link = buildLinkToFile(SourceFiles[I], FileReports[I]);
422 OSRef << tag("tr", tag("td", tag("pre", Link)), "light-row") << '\n';
423 }
424 OSRef << EndTable << EndCenteredDiv;
425 }
426
427 OSRef << tag("h5", escape(Opts.getLLVMVersionString(), Opts));
399428 emitEpilog(OSRef);
400429
401430 return Error::success();
3737 void emitFileSummary(raw_ostream &OS, StringRef SF,
3838 const FileCoverageSummary &FCS,
3939 bool IsTotals = false) const;
40 std::string buildLinkToFile(StringRef SF,
41 const FileCoverageSummary &FCS) const;
4042 };
4143
4244 /// \brief A code coverage view which supports html-based rendering.