Skip to content

Commit

Permalink
Move buf reset closer to its first usage
Browse files Browse the repository at this point in the history
  • Loading branch information
marselester committed Dec 12, 2022
1 parent 8938213 commit 01f2497
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions pkg/profiler/cpu/maps.go
Original file line number Diff line number Diff line change
Expand Up @@ -318,9 +318,7 @@ func (m *bpfMaps) clean() error {
// setUnwindTable updates the unwind tables with the given unwind table.
func (m *bpfMaps) setUnwindTable(pid int, ut unwind.UnwindTable) error {
buf := m.pool.Get().(*bytes.Buffer)
buf.Reset()
keyBuf := m.pool.Get().(*bytes.Buffer)
keyBuf.Reset()
defer func() {
m.pool.Put(buf)
m.pool.Put(keyBuf)
Expand All @@ -340,6 +338,7 @@ func (m *bpfMaps) setUnwindTable(pid int, ut unwind.UnwindTable) error {

chunk := ut[i:upTo]

buf.Reset()
// Write `.low_pc`
if err := binary.Write(buf, m.byteOrder, chunk[0].Loc); err != nil {
return fmt.Errorf("write the number of rows: %w", err)
Expand Down Expand Up @@ -426,6 +425,7 @@ func (m *bpfMaps) setUnwindTable(pid int, ut unwind.UnwindTable) error {
}

// Set (PID, shard ID) -> unwind table for each shard.
keyBuf.Reset()
if err := binary.Write(keyBuf, m.byteOrder, int32(pid)); err != nil {
return fmt.Errorf("write RBP offset bytes: %w", err)
}
Expand All @@ -441,8 +441,6 @@ func (m *bpfMaps) setUnwindTable(pid int, ut unwind.UnwindTable) error {
return fmt.Errorf("update unwind tables: %w", err)
}
shardIndex++
buf.Reset()
keyBuf.Reset()
}

// HACK(javierhonduco): remove this.
Expand Down

0 comments on commit 01f2497

Please sign in to comment.