Skip to content

Commit 4ff94ee

Browse files
committed
Add benchmark for *PartitionWriter.WriteProfileSymbols
I had to perform the initialization within the for loop as otherwise it always panics.
1 parent 1c81971 commit 4ff94ee

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

pkg/phlaredb/symdb/symdb_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,23 @@ func TestWritePartition(t *testing.T) {
227227
`
228228
require.Equal(t, expected, resolved.String())
229229
}
230+
231+
func BenchmarkPartitionWriter_WriteProfileSymbols(b *testing.B) {
232+
b.ReportAllocs()
233+
234+
for i := 0; i < b.N; i++ {
235+
// If opening the profile or creating the config, db, or
236+
// partition writer outside the loop it always results in a
237+
// panic.
238+
b.StopTimer()
239+
p, err := pprof.OpenFile("testdata/profile.pb.gz")
240+
require.NoError(b, err)
241+
p.Normalize()
242+
cfg := DefaultConfig().WithDirectory(b.TempDir())
243+
db := NewSymDB(cfg)
244+
pw := db.PartitionWriter(0)
245+
b.StartTimer()
246+
247+
pw.WriteProfileSymbols(p.Profile)
248+
}
249+
}

0 commit comments

Comments
 (0)