mirror of
https://github.com/RPCSX/llvm.git
synced 2025-04-03 16:51:42 +00:00
InstrProf: Fix display of large numbers in llvm-cov
llvm-cov was truncating numbers that were larger than a particular fixed width, which is as confusing as it is useless. Instead, we use engineering notation with SI prefix for magnitude. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@237307 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
parent
33bf03ed89
commit
98f0f26fdf
@ -1,8 +1,8 @@
|
|||||||
main
|
main
|
||||||
0x000000000028434d
|
0x000000000028434d
|
||||||
5
|
5
|
||||||
1
|
161
|
||||||
0
|
0
|
||||||
100
|
16100
|
||||||
1
|
161
|
||||||
0
|
0
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
main
|
main
|
||||||
0x000000000028434d
|
0x000000000028434d
|
||||||
5
|
5
|
||||||
1
|
1111000
|
||||||
0
|
0
|
||||||
100
|
111100000
|
||||||
1
|
1111000
|
||||||
0
|
0
|
||||||
|
@ -1,30 +1,30 @@
|
|||||||
// Basic handling of line counts.
|
// Basic handling of line counts.
|
||||||
// RUN: llvm-profdata merge %S/Inputs/lineExecutionCounts.proftext -o %t.profdata
|
// RUN: llvm-profdata merge %S/Inputs/lineExecutionCounts.proftext -o %t.profdata
|
||||||
|
|
||||||
// before any coverage // WHOLE-FILE: | [[@LINE]]|// before
|
// before any coverage // WHOLE-FILE: | [[@LINE]]|// before
|
||||||
// FILTER-NOT: | [[@LINE-1]]|// before
|
// FILTER-NOT: | [[@LINE-1]]|// before
|
||||||
int main() { // CHECK: 1| [[@LINE]]|int main(
|
int main() { // CHECK: 161| [[@LINE]]|int main(
|
||||||
int x = 0; // CHECK: 1| [[@LINE]]| int x
|
int x = 0; // CHECK: 161| [[@LINE]]| int x
|
||||||
// CHECK: 1| [[@LINE]]|
|
// CHECK: 161| [[@LINE]]|
|
||||||
if (x) { // CHECK: 0| [[@LINE]]| if (x)
|
if (x) { // CHECK: 0| [[@LINE]]| if (x)
|
||||||
x = 0; // CHECK: 0| [[@LINE]]| x = 0
|
x = 0; // CHECK: 0| [[@LINE]]| x = 0
|
||||||
} else { // CHECK: 1| [[@LINE]]| } else
|
} else { // CHECK: 161| [[@LINE]]| } else
|
||||||
x = 1; // CHECK: 1| [[@LINE]]| x = 1
|
x = 1; // CHECK: 161| [[@LINE]]| x = 1
|
||||||
} // CHECK: 1| [[@LINE]]| }
|
} // CHECK: 161| [[@LINE]]| }
|
||||||
// CHECK: 1| [[@LINE]]|
|
// CHECK: 161| [[@LINE]]|
|
||||||
for (int i = 0; i < 100; ++i) { // CHECK: 101| [[@LINE]]| for (
|
for (int i = 0; i < 100; ++i) { // CHECK: 16.2k| [[@LINE]]| for (
|
||||||
x = 1; // CHECK: 100| [[@LINE]]| x = 1
|
x = 1; // CHECK: 16.1k| [[@LINE]]| x = 1
|
||||||
} // CHECK: 100| [[@LINE]]| }
|
} // CHECK: 16.1k| [[@LINE]]| }
|
||||||
// CHECK: 1| [[@LINE]]|
|
// CHECK: 161| [[@LINE]]|
|
||||||
x = x < 10 ? x + 1 : x - 1; // CHECK: 1| [[@LINE]]| x =
|
x = x < 10 ? x + 1 : x - 1; // CHECK: 161| [[@LINE]]| x =
|
||||||
x = x > 10 ? // CHECK: 1| [[@LINE]]| x =
|
x = x > 10 ? // CHECK: 161| [[@LINE]]| x =
|
||||||
x - 1: // CHECK: 0| [[@LINE]]| x
|
x - 1: // CHECK: 0| [[@LINE]]| x
|
||||||
x + 1; // CHECK: 1| [[@LINE]]| x
|
x + 1; // CHECK: 161| [[@LINE]]| x
|
||||||
// CHECK: 1| [[@LINE]]|
|
// CHECK: 161| [[@LINE]]|
|
||||||
return 0; // CHECK: 1| [[@LINE]]| return
|
return 0; // CHECK: 161| [[@LINE]]| return
|
||||||
} // CHECK: 1| [[@LINE]]|}
|
} // CHECK: 161| [[@LINE]]|}
|
||||||
// after coverage // WHOLE-FILE: | [[@LINE]]|// after
|
// after coverage // WHOLE-FILE: | [[@LINE]]|// after
|
||||||
// FILTER-NOT: | [[@LINE-1]]|// after
|
// FILTER-NOT: | [[@LINE-1]]|// after
|
||||||
|
|
||||||
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck -check-prefix=CHECK -check-prefix=WHOLE-FILE %s
|
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -filename-equivalence %s | FileCheck -check-prefix=CHECK -check-prefix=WHOLE-FILE %s
|
||||||
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -filename-equivalence -name=main %s | FileCheck -check-prefix=CHECK -check-prefix=FILTER %s
|
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -instr-profile %t.profdata -filename-equivalence -name=main %s | FileCheck -check-prefix=CHECK -check-prefix=FILTER %s
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
// RUN: llvm-profdata merge %S/Inputs/regionMarkers.proftext -o %t.profdata
|
// RUN: llvm-profdata merge %S/Inputs/regionMarkers.proftext -o %t.profdata
|
||||||
|
|
||||||
int main() { // CHECK: Marker at [[@LINE]]:12 = 1
|
int main() { // CHECK: Marker at [[@LINE]]:12 = 1.11M
|
||||||
int x = 0;
|
int x = 0;
|
||||||
|
|
||||||
if (x) { // CHECK: Marker at [[@LINE]]:10 = 0
|
if (x) { // CHECK: Marker at [[@LINE]]:10 = 0
|
||||||
x = 0;
|
x = 0;
|
||||||
} else { // CHECK: Marker at [[@LINE]]:10 = 1
|
} else { // CHECK: Marker at [[@LINE]]:10 = 1.11M
|
||||||
x = 1;
|
x = 1;
|
||||||
}
|
}
|
||||||
// CHECK: Marker at [[@LINE+2]]:19 = 101
|
// CHECK: Marker at [[@LINE+2]]:19 = 112M
|
||||||
// CHECK: Marker at [[@LINE+1]]:28 = 100
|
// CHECK: Marker at [[@LINE+1]]:28 = 111M
|
||||||
for (int i = 0; i < 100; ++i) { // CHECK: Marker at [[@LINE]]:33 = 100
|
for (int i = 0; i < 100; ++i) { // CHECK: Marker at [[@LINE]]:33 = 111M
|
||||||
x = 1;
|
x = 1;
|
||||||
}
|
}
|
||||||
// CHECK: Marker at [[@LINE+1]]:16 = 1
|
// CHECK: Marker at [[@LINE+1]]:16 = 1.11M
|
||||||
x = x < 10 ? x + 1 : x - 1; // CHECK: Marker at [[@LINE]]:24 = 0
|
x = x < 10 ? x + 1 : x - 1; // CHECK: Marker at [[@LINE]]:24 = 0
|
||||||
x = x > 10 ?
|
x = x > 10 ?
|
||||||
x - 1: // CHECK: Marker at [[@LINE]]:9 = 0
|
x - 1: // CHECK: Marker at [[@LINE]]:9 = 0
|
||||||
x + 1; // CHECK: Marker at [[@LINE]]:9 = 1
|
x + 1; // CHECK: Marker at [[@LINE]]:9 = 1.11M
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -14,6 +14,7 @@
|
|||||||
#include "SourceCoverageView.h"
|
#include "SourceCoverageView.h"
|
||||||
#include "llvm/ADT/Optional.h"
|
#include "llvm/ADT/Optional.h"
|
||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
|
#include "llvm/ADT/StringExtras.h"
|
||||||
#include "llvm/Support/LineIterator.h"
|
#include "llvm/Support/LineIterator.h"
|
||||||
|
|
||||||
using namespace llvm;
|
using namespace llvm;
|
||||||
@ -77,6 +78,22 @@ void SourceCoverageView::renderViewDivider(unsigned Level, unsigned Length,
|
|||||||
OS << "-";
|
OS << "-";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Format a count using engineering notation with 3 significant digits.
|
||||||
|
static std::string formatCount(uint64_t N) {
|
||||||
|
std::string Number = utostr(N);
|
||||||
|
int Len = Number.size();
|
||||||
|
if (Len <= 3)
|
||||||
|
return Number;
|
||||||
|
int IntLen = Len % 3 == 0 ? 3 : Len % 3;
|
||||||
|
std::string Result(Number.data(), IntLen);
|
||||||
|
if (IntLen != 3) {
|
||||||
|
Result.push_back('.');
|
||||||
|
Result += Number.substr(IntLen, 3 - IntLen);
|
||||||
|
}
|
||||||
|
Result.push_back(" kMGTPEZY"[(Len - 1) / 3]);
|
||||||
|
return Result;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
SourceCoverageView::renderLineCoverageColumn(raw_ostream &OS,
|
SourceCoverageView::renderLineCoverageColumn(raw_ostream &OS,
|
||||||
const LineCoverageInfo &Line) {
|
const LineCoverageInfo &Line) {
|
||||||
@ -84,17 +101,11 @@ SourceCoverageView::renderLineCoverageColumn(raw_ostream &OS,
|
|||||||
OS.indent(LineCoverageColumnWidth) << '|';
|
OS.indent(LineCoverageColumnWidth) << '|';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
SmallString<32> Buffer;
|
std::string C = formatCount(Line.ExecutionCount);
|
||||||
raw_svector_ostream BufferOS(Buffer);
|
OS.indent(LineCoverageColumnWidth - C.size());
|
||||||
BufferOS << Line.ExecutionCount;
|
|
||||||
auto Str = BufferOS.str();
|
|
||||||
// Trim
|
|
||||||
Str = Str.substr(0, std::min(Str.size(), (size_t)LineCoverageColumnWidth));
|
|
||||||
// Align to the right
|
|
||||||
OS.indent(LineCoverageColumnWidth - Str.size());
|
|
||||||
colored_ostream(OS, raw_ostream::MAGENTA,
|
colored_ostream(OS, raw_ostream::MAGENTA,
|
||||||
Line.hasMultipleRegions() && Options.Colors)
|
Line.hasMultipleRegions() && Options.Colors)
|
||||||
<< Str;
|
<< C;
|
||||||
OS << '|';
|
OS << '|';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -111,9 +122,6 @@ void SourceCoverageView::renderLineNumberColumn(raw_ostream &OS,
|
|||||||
|
|
||||||
void SourceCoverageView::renderRegionMarkers(
|
void SourceCoverageView::renderRegionMarkers(
|
||||||
raw_ostream &OS, ArrayRef<const coverage::CoverageSegment *> Segments) {
|
raw_ostream &OS, ArrayRef<const coverage::CoverageSegment *> Segments) {
|
||||||
SmallString<32> Buffer;
|
|
||||||
raw_svector_ostream BufferOS(Buffer);
|
|
||||||
|
|
||||||
unsigned PrevColumn = 1;
|
unsigned PrevColumn = 1;
|
||||||
for (const auto *S : Segments) {
|
for (const auto *S : Segments) {
|
||||||
if (!S->IsRegionEntry)
|
if (!S->IsRegionEntry)
|
||||||
@ -122,20 +130,16 @@ void SourceCoverageView::renderRegionMarkers(
|
|||||||
if (S->Col > PrevColumn)
|
if (S->Col > PrevColumn)
|
||||||
OS.indent(S->Col - PrevColumn);
|
OS.indent(S->Col - PrevColumn);
|
||||||
PrevColumn = S->Col + 1;
|
PrevColumn = S->Col + 1;
|
||||||
BufferOS << S->Count;
|
std::string C = formatCount(S->Count);
|
||||||
StringRef Str = BufferOS.str();
|
PrevColumn += C.size();
|
||||||
// Trim the execution count
|
OS << '^' << C;
|
||||||
Str = Str.substr(0, std::min(Str.size(), (size_t)7));
|
|
||||||
PrevColumn += Str.size();
|
|
||||||
OS << '^' << Str;
|
|
||||||
Buffer.clear();
|
|
||||||
}
|
}
|
||||||
OS << "\n";
|
OS << "\n";
|
||||||
|
|
||||||
if (Options.Debug)
|
if (Options.Debug)
|
||||||
for (const auto *S : Segments)
|
for (const auto *S : Segments)
|
||||||
errs() << "Marker at " << S->Line << ":" << S->Col << " = " << S->Count
|
errs() << "Marker at " << S->Line << ":" << S->Col << " = "
|
||||||
<< (S->IsRegionEntry ? "\n" : " (pop)\n");
|
<< formatCount(S->Count) << (S->IsRegionEntry ? "\n" : " (pop)\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
void SourceCoverageView::render(raw_ostream &OS, bool WholeFile,
|
void SourceCoverageView::render(raw_ostream &OS, bool WholeFile,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user