forked from OSchip/llvm-project
[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
This commit is contained in:
parent
f79af6f8c4
commit
fa75437183
Binary file not shown.
|
@ -0,0 +1,19 @@
|
|||
f1
|
||||
0x0
|
||||
1
|
||||
1
|
||||
|
||||
f2
|
||||
0x0
|
||||
1
|
||||
1
|
||||
|
||||
f3
|
||||
0x0
|
||||
1
|
||||
1
|
||||
|
||||
f4
|
||||
0x0
|
||||
1
|
||||
1
|
|
@ -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
|
|
@ -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<StringRef> 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<StringRef> 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);
|
||||
|
|
Loading…
Reference in New Issue