Skip to content

runtime/coverage: fix snapshot total calculation #62669

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/internal/coverage/defs.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func Round4(x int) int {
// numCtrs uint32
// pkgid uint32
// funcid uint32
// counterArray [numBlocks]uint32
// counterArray [numCtrs]uint32
// }
//
// where "numCtrs" is the number of blocks / coverable units within the
Expand Down
9 changes: 6 additions & 3 deletions src/runtime/coverage/testsupport.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,19 +294,22 @@ func snapshot() float64 {
totExec := uint64(0)
for _, c := range cl {
sd := unsafe.Slice((*atomic.Uint32)(unsafe.Pointer(c.Counters)), c.Len)
tot += uint64(len(sd))
for i := 0; i < len(sd); i++ {
nCtrs := sd[i+coverage.NumCtrsOffset].Load()

// Skip ahead until the next non-zero value.
if sd[i].Load() == 0 {
if nCtrs == 0 {
continue
}

// We found a function that was executed.
nCtrs := sd[i+coverage.NumCtrsOffset].Load()
cst := i + coverage.FirstCtrOffset

if cst+int(nCtrs) > len(sd) {
break
}

tot += uint64(nCtrs)
counters := sd[cst : cst+int(nCtrs)]
for i := range counters {
if counters[i].Load() != 0 {
Expand Down