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 Nov 29, 2022
1 parent b4d8c23 commit 0310530
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 @@ -283,9 +283,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 @@ -305,6 +303,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 @@ -391,6 +390,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 @@ -406,8 +406,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 0310530

Please sign in to comment.