Skip to content

llvm-cov: Introduce --binary-counters #120841

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Dec 27, 2024
Merged

llvm-cov: Introduce --binary-counters #120841

merged 7 commits into from
Dec 27, 2024

Conversation

chapuni
Copy link
Contributor

@chapuni chapuni commented Dec 21, 2024

In llvm-cov show, this option rounds counters (line, branch) to [1,0] at rendering. This will be useful when the number of counts doesn't interest but Covered/uncoverd does.

@@ -1023,6 +1023,11 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
cl::alias ShowOutputDirectoryA("o", cl::desc("Alias for --output-dir"),
cl::aliasopt(ShowOutputDirectory));

cl::opt<bool> BinaryCounters(
"binary-counters", cl::Optional,
cl::desc("Show 1/0 instead of actual counter values."),
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it might help coverage noobs a little to make it clear that 1 == covered, 0 == covered.

Show when source is covered (1) or uncovered (0) instead of showing actual counter values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, with rewording lines/branches since counters belong line and branches.

@@ -266,6 +268,10 @@ class SourceCoverageView {
/// digits.
static std::string formatCount(uint64_t N);

uint64_t Count1(uint64_t N) const { return (N && BinaryCounters ? 1 : N); }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does more than count ones, can you give it a more descriptive name?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer shorter names since they (Count1 and formatCount1) are replacements of Count and formatCount.
That said, they appear in fewer lines. BinaryCount/formatBinaryCount?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

BinaryCount + formatBinaryCount SGTM

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -266,6 +268,10 @@ class SourceCoverageView {
/// digits.
static std::string formatCount(uint64_t N);

uint64_t Count1(uint64_t N) const { return (N && BinaryCounters ? 1 : N); }

std::string formatCount1(uint64_t N) const { return formatCount(Count1(N)); }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same as above

Conflicts:
	llvm/test/tools/llvm-cov/branch-macros.test
	llvm/test/tools/llvm-cov/showLineExecutionCounts.test
@chapuni chapuni requested a review from MaskRay December 25, 2024 14:42
@chapuni
Copy link
Contributor Author

chapuni commented Dec 25, 2024

@MaskRay Could you take a look, please? Thanks!

@@ -1023,6 +1023,12 @@ int CodeCoverageTool::doShow(int argc, const char **argv,
cl::alias ShowOutputDirectoryA("o", cl::desc("Alias for --output-dir"),
cl::aliasopt(ShowOutputDirectory));

cl::opt<bool> BinaryCounters(
"binary-counters", cl::Optional,
cl::desc("Show when lines/branches are covered (1) or uncovered (0) "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Show binary counters instead of integer execution counts?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about "Show binary counters (1/0) in lines and branches instead of..."?

@@ -16,8 +17,10 @@
//
// Test html output.
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.dir/html -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs
// RUN: llvm-cov show %S/Inputs/lineExecutionCounts.covmapping -format html -o %t.dir/html.binary -binary-counters=true -instr-profile %t.profdata -path-equivalence=/tmp,%S/Inputs
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just -binary-counters. =true is a weird syntax that most command line parsing libraries don't allow.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've dropped =true. I like it, though.

@chapuni chapuni merged commit 223521b into main Dec 27, 2024
5 of 8 checks passed
@chapuni chapuni deleted the users/chapuni/cov/binary branch December 27, 2024 10:48
chapuni added a commit that referenced this pull request Dec 27, 2024
`SingleByteCoverage` is not per-region attribute at least.
Move it into `CoverageData` since it comes from `profdata`.

Depends on: #120841
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants