aboutsummaryrefslogtreecommitdiff
path: root/contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2021-06-13 19:31:46 +0000
committerDimitry Andric <dim@FreeBSD.org>2021-06-13 19:37:19 +0000
commite8d8bef961a50d4dc22501cde4fb9fb0be1b2532 (patch)
tree94f04805f47bb7c59ae29690d8952b6074fff602 /contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
parentbb130ff39747b94592cb26d71b7cb097b9a4ea6b (diff)
parentb60736ec1405bb0a8dd40989f67ef4c93da068ab (diff)
Diffstat (limited to 'contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp')
-rw-r--r--contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp76
1 files changed, 74 insertions, 2 deletions
diff --git a/contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp b/contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
index 9d10def0a211..7ab1d6608ccf 100644
--- a/contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
+++ b/contrib/llvm-project/llvm/tools/llvm-cov/SourceCoverageViewHTML.cpp
@@ -248,7 +248,7 @@ const char *ReportTitleTag = "h2";
const char *CreatedTimeTag = "h4";
std::string getPathToStyle(StringRef ViewPath) {
- std::string PathToStyle = "";
+ std::string PathToStyle;
std::string PathSep = std::string(sys::path::get_separator());
unsigned NumSeps = ViewPath.count(PathSep);
for (unsigned I = 0, E = NumSeps; I < E; ++I)
@@ -313,6 +313,8 @@ static void emitColumnLabelsForIndex(raw_ostream &OS,
Columns.emplace_back(tag("td", "Line Coverage", "column-entry-bold"));
if (Opts.ShowRegionSummary)
Columns.emplace_back(tag("td", "Region Coverage", "column-entry-bold"));
+ if (Opts.ShowBranchSummary)
+ Columns.emplace_back(tag("td", "Branch Coverage", "column-entry-bold"));
OS << tag("tr", join(Columns.begin(), Columns.end(), ""));
}
@@ -378,6 +380,10 @@ void CoveragePrinterHTML::emitFileSummary(raw_ostream &OS, StringRef SF,
AddCoverageTripleToColumn(FCS.RegionCoverage.getCovered(),
FCS.RegionCoverage.getNumRegions(),
FCS.RegionCoverage.getPercentCovered());
+ if (Opts.ShowBranchSummary)
+ AddCoverageTripleToColumn(FCS.BranchCoverage.getCovered(),
+ FCS.BranchCoverage.getNumBranches(),
+ FCS.BranchCoverage.getPercentCovered());
if (IsTotals)
OS << tag("tr", join(Columns.begin(), Columns.end(), ""), "light-row-bold");
@@ -611,7 +617,7 @@ void SourceCoverageViewHTML::renderLine(raw_ostream &OS, LineRef L,
void SourceCoverageViewHTML::renderLineCoverageColumn(
raw_ostream &OS, const LineCoverageStats &Line) {
- std::string Count = "";
+ std::string Count;
if (Line.isMapped())
Count = tag("pre", formatCount(Line.getExecutionCount()));
std::string CoverageClass =
@@ -650,6 +656,72 @@ void SourceCoverageViewHTML::renderExpansionView(raw_ostream &OS,
OS << EndExpansionDiv;
}
+void SourceCoverageViewHTML::renderBranchView(raw_ostream &OS, BranchView &BRV,
+ unsigned ViewDepth) {
+ // Render the child subview.
+ if (getOptions().Debug)
+ errs() << "Branch at line " << BRV.getLine() << '\n';
+
+ OS << BeginExpansionDiv;
+ OS << BeginPre;
+ for (const auto &R : BRV.Regions) {
+ // Calculate TruePercent and False Percent.
+ double TruePercent = 0.0;
+ double FalsePercent = 0.0;
+ unsigned Total = R.ExecutionCount + R.FalseExecutionCount;
+
+ if (!getOptions().ShowBranchCounts && Total != 0) {
+ TruePercent = ((double)(R.ExecutionCount) / (double)Total) * 100.0;
+ FalsePercent = ((double)(R.FalseExecutionCount) / (double)Total) * 100.0;
+ }
+
+ // Display Line + Column.
+ std::string LineNoStr = utostr(uint64_t(R.LineStart));
+ std::string ColNoStr = utostr(uint64_t(R.ColumnStart));
+ std::string TargetName = "L" + LineNoStr;
+
+ OS << " Branch (";
+ OS << tag("span",
+ a("#" + TargetName, tag("span", LineNoStr + ":" + ColNoStr),
+ TargetName),
+ "line-number") +
+ "): [";
+
+ if (R.Folded) {
+ OS << "Folded - Ignored]\n";
+ continue;
+ }
+
+ // Display TrueCount or TruePercent.
+ std::string TrueColor = R.ExecutionCount ? "None" : "red";
+ std::string TrueCovClass =
+ (R.ExecutionCount > 0) ? "covered-line" : "uncovered-line";
+
+ OS << tag("span", "True", TrueColor);
+ OS << ": ";
+ if (getOptions().ShowBranchCounts)
+ OS << tag("span", formatCount(R.ExecutionCount), TrueCovClass) << ", ";
+ else
+ OS << format("%0.2f", TruePercent) << "%, ";
+
+ // Display FalseCount or FalsePercent.
+ std::string FalseColor = R.FalseExecutionCount ? "None" : "red";
+ std::string FalseCovClass =
+ (R.FalseExecutionCount > 0) ? "covered-line" : "uncovered-line";
+
+ OS << tag("span", "False", FalseColor);
+ OS << ": ";
+ if (getOptions().ShowBranchCounts)
+ OS << tag("span", formatCount(R.FalseExecutionCount), FalseCovClass);
+ else
+ OS << format("%0.2f", FalsePercent) << "%";
+
+ OS << "]\n";
+ }
+ OS << EndPre;
+ OS << EndExpansionDiv;
+}
+
void SourceCoverageViewHTML::renderInstantiationView(raw_ostream &OS,
InstantiationView &ISV,
unsigned ViewDepth) {