Skip to content

Commit

Permalink
add benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
dmathieu committed Jan 30, 2025
1 parent bd8ad31 commit fb15046
Showing 1 changed file with 82 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package serializeprofiles

import (
"testing"

"go.opentelemetry.io/collector/pdata/pprofile"
)

func BenchmarkTransform(b *testing.B) {
for _, bb := range []struct {
name string
buildResourceProfiles func() pprofile.ResourceProfiles
}{
{
name: "with a basic recorded sample",
buildResourceProfiles: func() pprofile.ResourceProfiles {
rp := pprofile.NewResourceProfiles()

sp := rp.ScopeProfiles().AppendEmpty()
p := sp.Profiles().AppendEmpty()

a := p.AttributeTable().AppendEmpty()
a.SetKey("profile.frame.type")
a.Value().SetStr("native")
a = p.AttributeTable().AppendEmpty()
a.SetKey("process.executable.build_id.profiling")
a.Value().SetStr(buildIDEncoded)
a = p.AttributeTable().AppendEmpty()
a.SetKey("process.executable.build_id.profiling")
a.Value().SetStr(buildID2Encoded)

p.StringTable().Append("firefox", "libc.so", "samples", "count", "cpu", "nanoseconds")
st := p.SampleType().AppendEmpty()
st.SetTypeStrindex(2)
st.SetUnitStrindex(3)
pt := p.PeriodType()
pt.SetTypeStrindex(4)
pt.SetUnitStrindex(5)

m := p.MappingTable().AppendEmpty()
m.AttributeIndices().Append(1)
m.SetFilenameStrindex(0)
m = p.MappingTable().AppendEmpty()
m.AttributeIndices().Append(2)
m.SetFilenameStrindex(1)

l := p.LocationTable().AppendEmpty()
l.SetAddress(address)
l.AttributeIndices().Append(0)
l.SetMappingIndex(0)
l = p.LocationTable().AppendEmpty()
l.SetAddress(address2)
l.AttributeIndices().Append(0)
l.SetMappingIndex(1)

s := p.Sample().AppendEmpty()
s.TimestampsUnixNano().Append(42)
s.Value().Append(1)
s.SetLocationsLength(2)
s.SetLocationsStartIndex(0)

return rp
},
},
} {
b.Run(bb.name, func(b *testing.B) {
rp := bb.buildResourceProfiles()
sp := rp.ScopeProfiles().At(0)
p := sp.Profiles().At(0)

b.ReportAllocs()
b.ResetTimer()

for i := 0; i < b.N; i++ {
_, _ = Transform(rp.Resource(), sp.Scope(), p)
}
})
}
}

0 comments on commit fb15046

Please sign in to comment.