From ac81cd0caa461ba87cccc0d18254d6b067a456fb Mon Sep 17 00:00:00 2001 From: csuzhang Date: Sat, 5 Mar 2022 17:37:49 +0800 Subject: [PATCH 1/5] add benchmark metric test for UpDownCounter --- sdk/metric/benchmark_test.go | 51 ++++++++++++++++++++++++++++++++++-- 1 file changed, 49 insertions(+), 2 deletions(-) diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index fd5f49bd1ef..cff954b3891 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -65,6 +65,7 @@ func (f *benchFixture) iCounter(name string) syncint64.Counter { } return ctr } + func (f *benchFixture) fCounter(name string) syncfloat64.Counter { ctr, err := f.meter.SyncFloat64().Counter(name) if err != nil { @@ -72,6 +73,23 @@ func (f *benchFixture) fCounter(name string) syncfloat64.Counter { } return ctr } + +func (f *benchFixture) iUpDownCounter(name string) syncfloat64.UpDownCounter { + ctr, err := f.meter.SyncFloat64().UpDownCounter(name) + if err != nil { + f.B.Error(err) + } + return ctr +} + +func (f *benchFixture) fUpDownCounter(name string) syncfloat64.UpDownCounter { + ctr, err := f.meter.SyncFloat64().UpDownCounter(name) + if err != nil { + f.B.Error(err) + } + return ctr +} + func (f *benchFixture) iHistogram(name string) syncint64.Histogram { ctr, err := f.meter.SyncInt64().Histogram(name) if err != nil { @@ -79,6 +97,7 @@ func (f *benchFixture) iHistogram(name string) syncint64.Histogram { } return ctr } + func (f *benchFixture) fHistogram(name string) syncfloat64.Histogram { ctr, err := f.meter.SyncFloat64().Histogram(name) if err != nil { @@ -179,8 +198,6 @@ func BenchmarkIterator_16(b *testing.B) { benchmarkIterator(b, 16) } -// Counters - // TODO readd global // func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) { @@ -203,6 +220,8 @@ func BenchmarkIterator_16(b *testing.B) { // } // } +// Counters + func BenchmarkInt64CounterAdd(b *testing.B) { ctx := context.Background() fix := newFixture(b) @@ -229,6 +248,34 @@ func BenchmarkFloat64CounterAdd(b *testing.B) { } } +// UpDownCounter + +func BenchmarkInt64UpDownCounterAdd(b *testing.B) { + ctx := context.Background() + fix := newFixture(b) + labs := makeLabels(1) + cnt := fix.iUpDownCounter("int64.sum") + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + cnt.Add(ctx, 1.1, labs...) + } +} + +func BenchmarkFloat64UpDownCounterAdd(b *testing.B) { + ctx := context.Background() + fix := newFixture(b) + labs := makeLabels(1) + cnt := fix.fUpDownCounter("float64.sum") + + b.ResetTimer() + + for i := 0; i < b.N; i++ { + cnt.Add(ctx, 1.1, labs...) + } +} + // LastValue func BenchmarkInt64LastValueAdd(b *testing.B) { From 215b1521f05de4a419ece66d38d46c7d639d0526 Mon Sep 17 00:00:00 2001 From: csuzhang Date: Mon, 7 Mar 2022 17:15:54 +0800 Subject: [PATCH 2/5] move counter annotation up --- sdk/metric/benchmark_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index cff954b3891..33988bf518c 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -198,6 +198,8 @@ func BenchmarkIterator_16(b *testing.B) { benchmarkIterator(b, 16) } +// Counters + // TODO readd global // func BenchmarkGlobalInt64CounterAddWithSDK(b *testing.B) { @@ -220,8 +222,6 @@ func BenchmarkIterator_16(b *testing.B) { // } // } -// Counters - func BenchmarkInt64CounterAdd(b *testing.B) { ctx := context.Background() fix := newFixture(b) From 62c650535540da9b9d9811aeb893c63c8d72b439 Mon Sep 17 00:00:00 2001 From: csuzhang Date: Wed, 30 Mar 2022 14:25:19 +0800 Subject: [PATCH 3/5] fix syncFloat64 to syncInt64 --- sdk/metric/benchmark_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index 33988bf518c..120435934ee 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -74,8 +74,8 @@ func (f *benchFixture) fCounter(name string) syncfloat64.Counter { return ctr } -func (f *benchFixture) iUpDownCounter(name string) syncfloat64.UpDownCounter { - ctr, err := f.meter.SyncFloat64().UpDownCounter(name) +func (f *benchFixture) iUpDownCounter(name string) syncint64.UpDownCounter { + ctr, err := f.meter.SyncInt64().UpDownCounter(name) if err != nil { f.B.Error(err) } From 9ccb1b2970cd3769b50d1c52571c001bd20abe0d Mon Sep 17 00:00:00 2001 From: csuzhang Date: Wed, 30 Mar 2022 14:34:15 +0800 Subject: [PATCH 4/5] fix syncFloat64 to syncInt64 --- sdk/metric/benchmark_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index 120435934ee..e6beb7021cf 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -259,7 +259,7 @@ func BenchmarkInt64UpDownCounterAdd(b *testing.B) { b.ResetTimer() for i := 0; i < b.N; i++ { - cnt.Add(ctx, 1.1, labs...) + cnt.Add(ctx, 1, labs...) } } From 1d48108da8247e790fa42bd4cb6e8b85f3db1426 Mon Sep 17 00:00:00 2001 From: csuzhang Date: Thu, 28 Apr 2022 20:01:59 +0800 Subject: [PATCH 5/5] fix go-lint err --- sdk/metric/benchmark_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sdk/metric/benchmark_test.go b/sdk/metric/benchmark_test.go index 1c60487382f..ff05792b1b1 100644 --- a/sdk/metric/benchmark_test.go +++ b/sdk/metric/benchmark_test.go @@ -252,7 +252,7 @@ func BenchmarkFloat64CounterAdd(b *testing.B) { func BenchmarkInt64UpDownCounterAdd(b *testing.B) { ctx := context.Background() fix := newFixture(b) - labs := makeLabels(1) + labs := makeAttrs(1) cnt := fix.iUpDownCounter("int64.sum") b.ResetTimer() @@ -265,7 +265,7 @@ func BenchmarkInt64UpDownCounterAdd(b *testing.B) { func BenchmarkFloat64UpDownCounterAdd(b *testing.B) { ctx := context.Background() fix := newFixture(b) - labs := makeLabels(1) + labs := makeAttrs(1) cnt := fix.fUpDownCounter("float64.sum") b.ResetTimer()