From 03105304c1189f44a5ee5ac817b8f83f86a27e9b Mon Sep 17 00:00:00 2001 From: marselester Date: Tue, 29 Nov 2022 10:27:41 -0500 Subject: [PATCH] Move buf reset closer to its first usage --- pkg/profiler/cpu/maps.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pkg/profiler/cpu/maps.go b/pkg/profiler/cpu/maps.go index 7449f4dc8f..8e8463d703 100644 --- a/pkg/profiler/cpu/maps.go +++ b/pkg/profiler/cpu/maps.go @@ -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) @@ -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) @@ -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) } @@ -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.