mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-11-01 15:17:25 +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:
@@ -14,6 +14,7 @@
|
||||
#include "SourceCoverageView.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/ADT/SmallString.h"
|
||||
#include "llvm/ADT/StringExtras.h"
|
||||
#include "llvm/Support/LineIterator.h"
|
||||
|
||||
using namespace llvm;
|
||||
@@ -77,6 +78,22 @@ void SourceCoverageView::renderViewDivider(unsigned Level, unsigned Length,
|
||||
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
|
||||
SourceCoverageView::renderLineCoverageColumn(raw_ostream &OS,
|
||||
const LineCoverageInfo &Line) {
|
||||
@@ -84,17 +101,11 @@ SourceCoverageView::renderLineCoverageColumn(raw_ostream &OS,
|
||||
OS.indent(LineCoverageColumnWidth) << '|';
|
||||
return;
|
||||
}
|
||||
SmallString<32> Buffer;
|
||||
raw_svector_ostream BufferOS(Buffer);
|
||||
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());
|
||||
std::string C = formatCount(Line.ExecutionCount);
|
||||
OS.indent(LineCoverageColumnWidth - C.size());
|
||||
colored_ostream(OS, raw_ostream::MAGENTA,
|
||||
Line.hasMultipleRegions() && Options.Colors)
|
||||
<< Str;
|
||||
<< C;
|
||||
OS << '|';
|
||||
}
|
||||
|
||||
@@ -111,9 +122,6 @@ void SourceCoverageView::renderLineNumberColumn(raw_ostream &OS,
|
||||
|
||||
void SourceCoverageView::renderRegionMarkers(
|
||||
raw_ostream &OS, ArrayRef<const coverage::CoverageSegment *> Segments) {
|
||||
SmallString<32> Buffer;
|
||||
raw_svector_ostream BufferOS(Buffer);
|
||||
|
||||
unsigned PrevColumn = 1;
|
||||
for (const auto *S : Segments) {
|
||||
if (!S->IsRegionEntry)
|
||||
@@ -122,20 +130,16 @@ void SourceCoverageView::renderRegionMarkers(
|
||||
if (S->Col > PrevColumn)
|
||||
OS.indent(S->Col - PrevColumn);
|
||||
PrevColumn = S->Col + 1;
|
||||
BufferOS << S->Count;
|
||||
StringRef Str = BufferOS.str();
|
||||
// Trim the execution count
|
||||
Str = Str.substr(0, std::min(Str.size(), (size_t)7));
|
||||
PrevColumn += Str.size();
|
||||
OS << '^' << Str;
|
||||
Buffer.clear();
|
||||
std::string C = formatCount(S->Count);
|
||||
PrevColumn += C.size();
|
||||
OS << '^' << C;
|
||||
}
|
||||
OS << "\n";
|
||||
|
||||
if (Options.Debug)
|
||||
for (const auto *S : Segments)
|
||||
errs() << "Marker at " << S->Line << ":" << S->Col << " = " << S->Count
|
||||
<< (S->IsRegionEntry ? "\n" : " (pop)\n");
|
||||
errs() << "Marker at " << S->Line << ":" << S->Col << " = "
|
||||
<< formatCount(S->Count) << (S->IsRegionEntry ? "\n" : " (pop)\n");
|
||||
}
|
||||
|
||||
void SourceCoverageView::render(raw_ostream &OS, bool WholeFile,
|
||||
|
||||
Reference in New Issue
Block a user