Skip to content
This repository was archived by the owner on Mar 28, 2020. It is now read-only.

Commit a57be10

Browse files
committed
[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. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@280895 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 2a93bda commit a57be10

File tree

4 files changed

+48
-2
lines changed

4 files changed

+48
-2
lines changed
Binary file not shown.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
f1
2+
0x0
3+
1
4+
1
5+
6+
f2
7+
0x0
8+
1
9+
1
10+
11+
f3
12+
0x0
13+
1
14+
1
15+
16+
f4
17+
0x0
18+
1
19+
1
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// RUN: llvm-profdata merge %S/Inputs/multiple-files.proftext -o %t.profdata
2+
// RUN: llvm-cov report %S/Inputs/multiple-files.covmapping -instr-profile %t.profdata | FileCheck %s
3+
4+
// CHECK: Filename
5+
// CHECK-NEXT: ---
6+
// CHECK-NEXT: {{^}}a{{[/\\]}}f2.c
7+
// CHECK-NEXT: {{^}}b{{[/\\]}}c{{[/\\]}}f4.c
8+
// CHECK-NEXT: {{^}}b{{[/\\]}}f3.c
9+
// CHECK-NEXT: {{^}}f1.c

tools/llvm-cov/CoverageReport.cpp

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,19 @@ raw_ostream::Colors determineCoveragePercentageColor(const T &Info) {
116116
: raw_ostream::RED;
117117
}
118118

119+
/// \brief Determine the length of the longest common prefix of the strings in
120+
/// \p Strings.
121+
unsigned getLongestCommonPrefixLen(ArrayRef<StringRef> Strings) {
122+
unsigned LCP = Strings[0].size();
123+
for (unsigned I = 1, E = Strings.size(); LCP > 0 && I < E; ++I) {
124+
auto Mismatch =
125+
std::mismatch(Strings[0].begin(), Strings[0].end(), Strings[I].begin())
126+
.first;
127+
LCP = std::min(LCP, (unsigned)std::distance(Strings[0].begin(), Mismatch));
128+
}
129+
return LCP;
130+
}
131+
119132
} // end anonymous namespace
120133

121134
namespace llvm {
@@ -236,9 +249,14 @@ void CoverageReport::renderFileReports(raw_ostream &OS) {
236249
renderDivider(FileReportColumns, OS);
237250
OS << "\n";
238251

252+
std::vector<StringRef> UniqueSourceFiles = Coverage.getUniqueSourceFiles();
253+
unsigned LCP = 0;
254+
if (UniqueSourceFiles.size() > 1)
255+
LCP = getLongestCommonPrefixLen(UniqueSourceFiles);
256+
239257
FileCoverageSummary Totals("TOTAL");
240-
for (StringRef Filename : Coverage.getUniqueSourceFiles()) {
241-
FileCoverageSummary Summary(Filename);
258+
for (StringRef Filename : UniqueSourceFiles) {
259+
FileCoverageSummary Summary(Filename.drop_front(LCP));
242260
for (const auto &F : Coverage.getCoveredFunctions(Filename)) {
243261
FunctionCoverageSummary Function = FunctionCoverageSummary::get(F);
244262
Summary.addFunction(Function);

0 commit comments

Comments
 (0)