[PATCH] D116876: [llvm-cov] New parameters to set coverage watermark
Jinhua Tan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 8 20:09:20 PST 2022
tanjinhua updated this revision to Diff 398390.
tanjinhua added a comment.
add reviewer
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D116876/new/
https://reviews.llvm.org/D116876
Files:
llvm/tools/llvm-cov/CodeCoverage.cpp
llvm/tools/llvm-cov/CoverageViewOptions.h
llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
Index: llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
===================================================================
--- llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -338,7 +338,7 @@
SmallVector<std::string, 8> Columns;
// Format a coverage triple and add the result to the list of columns.
- auto AddCoverageTripleToColumn = [&Columns](unsigned Hit, unsigned Total,
+ auto AddCoverageTripleToColumn = [&Columns, this](unsigned Hit, unsigned Total,
float Pctg) {
std::string S;
{
@@ -350,9 +350,9 @@
RSO << '(' << Hit << '/' << Total << ')';
}
const char *CellClass = "column-entry-yellow";
- if (Hit == Total)
+ if (Pctg >= Opts.MediumCovWatermark)
CellClass = "column-entry-green";
- else if (Pctg < 80.0)
+ else if (Pctg < Opts.LowCovWatermark)
CellClass = "column-entry-red";
Columns.emplace_back(tag("td", tag("pre", S), CellClass));
};
Index: llvm/tools/llvm-cov/CoverageViewOptions.h
===================================================================
--- llvm/tools/llvm-cov/CoverageViewOptions.h
+++ llvm/tools/llvm-cov/CoverageViewOptions.h
@@ -50,6 +50,8 @@
std::string CreatedTimeStr;
unsigned NumThreads;
std::string CompilationDirectory;
+ float MediumCovWatermark;
+ float LowCovWatermark;
/// Change the output's stream color if the colors are enabled.
ColoredRawOstream colored_ostream(raw_ostream &OS,
Index: llvm/tools/llvm-cov/CodeCoverage.cpp
===================================================================
--- llvm/tools/llvm-cov/CodeCoverage.cpp
+++ llvm/tools/llvm-cov/CodeCoverage.cpp
@@ -973,6 +973,11 @@
"project-title", cl::Optional,
cl::desc("Set project title for the coverage report"));
+ cl::opt<std::string> CovWatermark(
+ "coverage-watermark", cl::Optional,
+ cl::desc("<medium>,<low> value indicate thresholds for medium and low"
+ "coverage watermark"));
+
auto Err = commandLineParser(argc, argv);
if (Err)
return Err;
@@ -982,6 +987,34 @@
return 1;
}
+ ViewOpts.MediumCovWatermark = 100.0;
+ ViewOpts.LowCovWatermark = 80.0;
+ if (!CovWatermark.empty()) {
+ auto WaterMarkPair = StringRef(CovWatermark).split(',');
+ if (WaterMarkPair.first.empty() || WaterMarkPair.second.empty()) {
+ error("invalid argument '" + CovWatermark +
+ "', must be in format 'medium,low'", "-coverage-watermark");
+ return 1;
+ }
+
+ char *EndPointer = nullptr;
+ ViewOpts.MediumCovWatermark = strtod(WaterMarkPair.first.begin(),
+ &EndPointer);
+ if (EndPointer != WaterMarkPair.first.end()) {
+ error("invalid argument '" + WaterMarkPair.first +
+ "', invalid value for 'medium'", "-coverage-watermark");
+ return 1;
+ }
+
+ ViewOpts.LowCovWatermark = strtod(WaterMarkPair.second.begin(),
+ &EndPointer);
+ if (EndPointer != WaterMarkPair.second.end()) {
+ error("invalid argument '" + WaterMarkPair.second +
+ "', invalid value for 'second'", "-coverage-watermark");
+ return 1;
+ }
+ }
+
ViewOpts.ShowLineNumbers = true;
ViewOpts.ShowLineStats = ShowLineExecutionCounts.getNumOccurrences() != 0 ||
!ShowRegions || ShowBestLineRegionsCounts;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116876.398390.patch
Type: text/x-patch
Size: 3435 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220109/a8c9690c/attachment.bin>
More information about the llvm-commits
mailing list