From a4c651a2cc5e5dc4b0b59a34af0c2fe7bab0cdab Mon Sep 17 00:00:00 2001 From: Mike Aizatsky Date: Thu, 24 Mar 2016 20:41:18 +0000 Subject: [PATCH] [sancov] adding leading zeros to coverage pct. Summary: Using leading zeroes allows you to search for "000%" to find non-covered items. Differential Revision: http://reviews.llvm.org/D18420 llvm-svn: 264336 --- llvm/tools/sancov/sancov.cc | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/llvm/tools/sancov/sancov.cc b/llvm/tools/sancov/sancov.cc index 31671f7..3871c17 100644 --- a/llvm/tools/sancov/sancov.cc +++ b/llvm/tools/sancov/sancov.cc @@ -46,6 +46,7 @@ #include "llvm/Support/ToolOutputFile.h" #include "llvm/Support/raw_ostream.h" +#include #include #include #include @@ -490,6 +491,19 @@ static std::string escapeHtml(const std::string &S) { return Result; } +// Adds leading zeroes wrapped in 'lz' style. +// Leading zeroes help locate 000% coverage. +static std::string formatHtmlPct(size_t Pct) { + Pct = std::max(std::size_t{0}, std::min(std::size_t{100}, Pct)); + + std::string Num = std::to_string(Pct); + std::string Zeroes(3 - Num.size(), '0'); + if (!Zeroes.empty()) + Zeroes = "" + Zeroes + ""; + + return Zeroes + Num; +} + static std::string anchorName(std::string Anchor) { llvm::MD5 Hasher; llvm::MD5::MD5Result Hash; @@ -885,7 +899,7 @@ public: OS << "" << stripPathPrefix(FileName) << "" - << "" << CovPct << "%" + << "" << formatHtmlPct(CovPct) << "%" << "" << FC.first << " (" << FC.second << ")" << "\n"; } @@ -923,7 +937,8 @@ public: std::string FunctionName = P.first.FunctionName; OS << "
"; - OS << "" << P.second << "% "; + OS << "" << formatHtmlPct(P.second) + << "% "; OS << ""; OS << escapeHtml(FunctionName) << ""; @@ -1108,6 +1123,7 @@ public: OS << ".fn { display: flex; flex-flow: row nowrap; }\n"; OS << ".pct { width: 3em; text-align: right; margin-right: 1em; }\n"; OS << ".name { flex: 2; }\n"; + OS << ".lz { color: lightgray; }\n"; OS << "\n"; OS << "" << Title << "\n"; OS << "\n"; -- 2.7.4