Skip to content

Commit 10f119c

Browse files
authored
chore: add switchDictionary benchmarks (#14201)
This adds benchmarks for the `switchDictionary` method within pprofile. None of them should emit allocs ever. ``` goos: darwin goarch: arm64 pkg: go.opentelemetry.io/collector/pdata/pprofile cpu: Apple M1 Max BenchmarkFunctionSwitchDictionary-10 87434488 13.44 ns/op 0 B/op 0 allocs/op BenchmarkKeyValueAndUnitSwitchDictionary-10 584721352 2.047 ns/op 0 B/op 0 allocs/op BenchmarkLineSwitchDictionary-10 577840999 2.073 ns/op 0 B/op 0 allocs/op BenchmarkLocationSwitchDictionary-10 55512399 21.56 ns/op 0 B/op 0 allocs/op BenchmarkMappingSwitchDictionary-10 26952688 44.67 ns/op 0 B/op 0 allocs/op BenchmarkProfileSwitchDictionary-10 24649387 48.70 ns/op 0 B/op 0 allocs/op BenchmarkProfilesSwitchDictionary-10 58513749 20.36 ns/op 0 B/op 0 allocs/op BenchmarkResourceProfilesSwitchDictionary-10 67610554 16.99 ns/op 0 B/op 0 allocs/op BenchmarkSampleSwitchDictionary-10 468034540 2.573 ns/op 0 B/op 0 allocs/op BenchmarkScopeProfilesSwitchDictionary-10 90358615 13.13 ns/op 0 B/op 0 allocs/op BenchmarkStackSwitchDictionary-10 35702508 33.42 ns/op 0 B/op 0 allocs/op BenchmarkValueTypeSwitchDictionary-10 91959018 12.88 ns/op 0 B/op 0 allocs/op ```
1 parent 78ab16d commit 10f119c

File tree

35 files changed

+359
-0
lines changed

35 files changed

+359
-0
lines changed

connector/connectortest/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ replace go.opentelemetry.io/collector/pipeline/xpipeline => ../../pipeline/xpipe
6969
replace go.opentelemetry.io/collector/internal/fanoutconsumer => ../../internal/fanoutconsumer
7070

7171
replace go.opentelemetry.io/collector/featuregate => ../../featuregate
72+
73+
replace go.opentelemetry.io/collector/internal/testutil => ../../internal/testutil

connector/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,3 +51,5 @@ replace go.opentelemetry.io/collector/pipeline => ../pipeline
5151
replace go.opentelemetry.io/collector/internal/fanoutconsumer => ../internal/fanoutconsumer
5252

5353
replace go.opentelemetry.io/collector/featuregate => ../featuregate
54+
55+
replace go.opentelemetry.io/collector/internal/testutil => ../internal/testutil

connector/xconnector/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,5 @@ replace go.opentelemetry.io/collector/pipeline/xpipeline => ../../pipeline/xpipe
5656
replace go.opentelemetry.io/collector/internal/fanoutconsumer => ../../internal/fanoutconsumer
5757

5858
replace go.opentelemetry.io/collector/featuregate => ../../featuregate
59+
60+
replace go.opentelemetry.io/collector/internal/testutil => ../../internal/testutil

consumer/consumererror/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,5 @@ replace go.opentelemetry.io/collector/pdata => ../../pdata
3333
replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata
3434

3535
replace go.opentelemetry.io/collector/featuregate => ../../featuregate
36+
37+
replace go.opentelemetry.io/collector/internal/testutil => ../../internal/testutil

consumer/consumererror/xconsumererror/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,5 @@ replace go.opentelemetry.io/collector/pdata/pprofile => ../../../pdata/pprofile
3131
replace go.opentelemetry.io/collector/consumer/consumererror => ../../consumererror
3232

3333
replace go.opentelemetry.io/collector/featuregate => ../../../featuregate
34+
35+
replace go.opentelemetry.io/collector/internal/testutil => ../../../internal/testutil

consumer/consumertest/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ replace go.opentelemetry.io/collector/consumer/xconsumer => ../xconsumer
3535
replace go.opentelemetry.io/collector/pdata/testdata => ../../pdata/testdata
3636

3737
replace go.opentelemetry.io/collector/featuregate => ../../featuregate
38+
39+
replace go.opentelemetry.io/collector/internal/testutil => ../../internal/testutil

consumer/xconsumer/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,5 @@ replace go.opentelemetry.io/collector/pdata/pprofile => ../../pdata/pprofile
2828
replace go.opentelemetry.io/collector/consumer => ../
2929

3030
replace go.opentelemetry.io/collector/featuregate => ../../featuregate
31+
32+
replace go.opentelemetry.io/collector/internal/testutil => ../../internal/testutil

internal/fanoutconsumer/go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,5 @@ replace go.opentelemetry.io/collector/consumer/consumertest => ../../consumer/co
3838
replace go.opentelemetry.io/collector/consumer/xconsumer => ../../consumer/xconsumer
3939

4040
replace go.opentelemetry.io/collector/featuregate => ../../featuregate
41+
42+
replace go.opentelemetry.io/collector/internal/testutil => ../testutil

internal/testutil/benchmarks.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package testutil // import "go.opentelemetry.io/collector/internal/testutil"
5+
6+
import (
7+
"os"
8+
"testing"
9+
)
10+
11+
// SkipMemoryBench will skip memory benchmarks on CI, as we currently only
12+
// monitor duration.
13+
func SkipMemoryBench(b *testing.B) {
14+
if os.Getenv("MEMBENCH") == "" {
15+
b.Skip("Skipping since the 'MEMBENCH' environment variable was not set")
16+
}
17+
}

pdata/pprofile/function_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99

1010
"github.com/stretchr/testify/assert"
1111
"github.com/stretchr/testify/require"
12+
13+
"go.opentelemetry.io/collector/internal/testutil"
1214
)
1315

1416
func TestFunctionEqual(t *testing.T) {
@@ -252,6 +254,28 @@ func TestFunctionSwitchDictionary(t *testing.T) {
252254
}
253255
}
254256

257+
func BenchmarkFunctionSwitchDictionary(b *testing.B) {
258+
testutil.SkipMemoryBench(b)
259+
260+
fn := NewFunction()
261+
fn.SetNameStrindex(1)
262+
fn.SetSystemNameStrindex(2)
263+
264+
src := NewProfilesDictionary()
265+
src.StringTable().Append("", "test", "foo")
266+
267+
b.ReportAllocs()
268+
269+
for b.Loop() {
270+
b.StopTimer()
271+
dst := NewProfilesDictionary()
272+
dst.StringTable().Append("", "foo")
273+
b.StartTimer()
274+
275+
_ = fn.switchDictionary(src, dst)
276+
}
277+
}
278+
255279
func buildFunction(name, sName, fileName int32, startLine int64) Function {
256280
f := NewFunction()
257281
f.SetNameStrindex(name)

0 commit comments

Comments
 (0)