Skip to content

Commit

Permalink
internal/coverage/encodecounter: followup changes from code review
Browse files Browse the repository at this point in the history
This patch contains a small set of changes with fixes for some
issues that surfaced during the code review for CL 484535. Due
to an error on my part, these never got included in the final version
that was checked in (I rebased, mailed the rebase, but then never
mailed the final patch set with the changes). This patch sends
the remaining bits and pieces.

Updates golang#59563.

Change-Id: I87dc05a83f8e44c8bfe7203bc2b035defc817af9
Reviewed-on: https://go-review.googlesource.com/c/go/+/492981
Run-TryBot: Than McIntosh <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Cherry Mui <[email protected]>
  • Loading branch information
thanm committed May 5, 2023
1 parent 13a59e3 commit 695a536
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions src/internal/coverage/encodecounter/encode.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ type CoverageDataWriter struct {
w *bufio.Writer
csh coverage.CounterSegmentHeader
tmp []byte
nfuncs uint64
cflavor coverage.CounterFlavor
segs uint32
debug bool
Expand Down Expand Up @@ -86,17 +85,25 @@ func padToFourByteBoundary(ws *slicewriter.WriteSeeker) error {
}

func (cfw *CoverageDataWriter) patchSegmentHeader(ws *slicewriter.WriteSeeker) error {
// record position
off, err := ws.Seek(0, io.SeekCurrent)
if err != nil {
return fmt.Errorf("error seeking in patchSegmentHeader: %v", err)
}
// seek back to start so that we can update the segment header
if _, err := ws.Seek(0, io.SeekStart); err != nil {
return fmt.Errorf("error seeking in patchSegmentHeader: %v", err)
}
cfw.csh.FcnEntries = cfw.nfuncs
cfw.nfuncs = 0
if cfw.debug {
fmt.Fprintf(os.Stderr, "=-= writing counter segment header: %+v", cfw.csh)
}
if err := binary.Write(ws, binary.LittleEndian, cfw.csh); err != nil {
return err
}
// ... and finally return to the original offset.
if _, err := ws.Seek(off, io.SeekStart); err != nil {
return fmt.Errorf("error seeking in patchSegmentHeader: %v", err)
}
return nil
}

Expand Down Expand Up @@ -167,8 +174,7 @@ func (cfw *CoverageDataWriter) AppendSegment(args map[string]string, visitor Cou
cfw.stab.Lookup(v)
}

var swws slicewriter.WriteSeeker
ws := &swws
ws := &slicewriter.WriteSeeker{}
if err = cfw.writeSegmentPreamble(args, ws); err != nil {
return err
}
Expand Down Expand Up @@ -253,7 +259,7 @@ func (cfw *CoverageDataWriter) writeCounters(visitor CounterVisitor, ws *slicewr

// Write out entries for each live function.
emitter := func(pkid uint32, funcid uint32, counters []uint32) error {
cfw.nfuncs++
cfw.csh.FcnEntries++
if err := wrval(uint32(len(counters))); err != nil {
return err
}
Expand Down

0 comments on commit 695a536

Please sign in to comment.