From fa754371831b1e75c7b39128b8d8cbfe6862ebd9 Mon Sep 17 00:00:00 2001 From: Vedant Kumar Date: Thu, 8 Sep 2016 00:56:43 +0000 Subject: [PATCH] [llvm-cov] Drop the longest common filename prefix from summaries Remove the longest common prefix from filenames when printing coverage summaries. This makes them easier to compare. llvm-svn: 280895 --- .../llvm-cov/Inputs/multiple-files.covmapping | Bin 0 -> 380 bytes .../llvm-cov/Inputs/multiple-files.proftext | 19 +++++++++++++++ llvm/test/tools/llvm-cov/multiple-files.test | 9 +++++++ llvm/tools/llvm-cov/CoverageReport.cpp | 22 ++++++++++++++++-- 4 files changed, 48 insertions(+), 2 deletions(-) create mode 100644 llvm/test/tools/llvm-cov/Inputs/multiple-files.covmapping create mode 100644 llvm/test/tools/llvm-cov/Inputs/multiple-files.proftext create mode 100644 llvm/test/tools/llvm-cov/multiple-files.test diff --git a/llvm/test/tools/llvm-cov/Inputs/multiple-files.covmapping b/llvm/test/tools/llvm-cov/Inputs/multiple-files.covmapping new file mode 100644 index 0000000000000000000000000000000000000000..f8af44a7456d449b75957b48306f0ce0a6052ace GIT binary patch literal 380 zcmd1FDa%dHFUu`SEiOq(EJ?ImaJ;cWfQhT(mbWnr1H*rY84xxT10w^&ObDBefsv76 z7KF{nz{tcfn}w(1)@k1}XP6mSq#2hn00B@ng9s4wK-qgGn{#g`9hBh&@?n5cNWUbv zKp$v*YEfc(s(zZGUNTT0BO@a>120q&$Q&^s<^p06+bsRtf|Df^N>R)aK{Y2)Kg|f; zBy@AcE6-ak<#DvaXHJrSnlUzWB!KP^fVwA7{%nD(#@cQabHq^Hlcb-lpJsw?5(5JO Dw5CMY literal 0 HcmV?d00001 diff --git a/llvm/test/tools/llvm-cov/Inputs/multiple-files.proftext b/llvm/test/tools/llvm-cov/Inputs/multiple-files.proftext new file mode 100644 index 000000000000..1be93b71b77a --- /dev/null +++ b/llvm/test/tools/llvm-cov/Inputs/multiple-files.proftext @@ -0,0 +1,19 @@ +f1 +0x0 +1 +1 + +f2 +0x0 +1 +1 + +f3 +0x0 +1 +1 + +f4 +0x0 +1 +1 diff --git a/llvm/test/tools/llvm-cov/multiple-files.test b/llvm/test/tools/llvm-cov/multiple-files.test new file mode 100644 index 000000000000..0b3fb855fedc --- /dev/null +++ b/llvm/test/tools/llvm-cov/multiple-files.test @@ -0,0 +1,9 @@ +// RUN: llvm-profdata merge %S/Inputs/multiple-files.proftext -o %t.profdata +// RUN: llvm-cov report %S/Inputs/multiple-files.covmapping -instr-profile %t.profdata | FileCheck %s + +// CHECK: Filename +// CHECK-NEXT: --- +// CHECK-NEXT: {{^}}a{{[/\\]}}f2.c +// CHECK-NEXT: {{^}}b{{[/\\]}}c{{[/\\]}}f4.c +// CHECK-NEXT: {{^}}b{{[/\\]}}f3.c +// CHECK-NEXT: {{^}}f1.c diff --git a/llvm/tools/llvm-cov/CoverageReport.cpp b/llvm/tools/llvm-cov/CoverageReport.cpp index 4ce642c0fb06..648ddf89f81f 100644 --- a/llvm/tools/llvm-cov/CoverageReport.cpp +++ b/llvm/tools/llvm-cov/CoverageReport.cpp @@ -116,6 +116,19 @@ raw_ostream::Colors determineCoveragePercentageColor(const T &Info) { : raw_ostream::RED; } +/// \brief Determine the length of the longest common prefix of the strings in +/// \p Strings. +unsigned getLongestCommonPrefixLen(ArrayRef Strings) { + unsigned LCP = Strings[0].size(); + for (unsigned I = 1, E = Strings.size(); LCP > 0 && I < E; ++I) { + auto Mismatch = + std::mismatch(Strings[0].begin(), Strings[0].end(), Strings[I].begin()) + .first; + LCP = std::min(LCP, (unsigned)std::distance(Strings[0].begin(), Mismatch)); + } + return LCP; +} + } // end anonymous namespace namespace llvm { @@ -236,9 +249,14 @@ void CoverageReport::renderFileReports(raw_ostream &OS) { renderDivider(FileReportColumns, OS); OS << "\n"; + std::vector UniqueSourceFiles = Coverage.getUniqueSourceFiles(); + unsigned LCP = 0; + if (UniqueSourceFiles.size() > 1) + LCP = getLongestCommonPrefixLen(UniqueSourceFiles); + FileCoverageSummary Totals("TOTAL"); - for (StringRef Filename : Coverage.getUniqueSourceFiles()) { - FileCoverageSummary Summary(Filename); + for (StringRef Filename : UniqueSourceFiles) { + FileCoverageSummary Summary(Filename.drop_front(LCP)); for (const auto &F : Coverage.getCoveredFunctions(Filename)) { FunctionCoverageSummary Function = FunctionCoverageSummary::get(F); Summary.addFunction(Function);