summaryrefslogtreecommitdiffstats
path: root/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp')
-rw-r--r--contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp46
1 files changed, 25 insertions, 21 deletions
diff --git a/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp b/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp
index 015099c..58c8a67 100644
--- a/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp
+++ b/contrib/llvm/tools/llvm-cov/SourceCoverageView.cpp
@@ -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,
OpenPOWER on IntegriCloud