-
Notifications
You must be signed in to change notification settings - Fork 812
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Memory mode: Adding support for synchronous instruments - Counter (#6182
- Loading branch information
Showing
13 changed files
with
386 additions
and
134 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...jmhBasedTest/java/io/opentelemetry/sdk/metrics/internal/state/tester/DoubleSumTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.state.tester; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.DoubleCounter; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class DoubleSumTester implements TestInstrumentType.InstrumentTester { | ||
private static final int measurementsPerAttributeSet = 1_000; | ||
|
||
static class DoubleSumState implements TestInstrumentType.TestInstrumentsState { | ||
DoubleCounter doubleCounter; | ||
} | ||
|
||
@Override | ||
public Aggregation testedAggregation() { | ||
return Aggregation.sum(); | ||
} | ||
|
||
@Override | ||
public TestInstrumentType.TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
DoubleSumState doubleSumState = new DoubleSumState(); | ||
|
||
Meter meter = sdkMeterProvider.meterBuilder("meter").build(); | ||
doubleSumState.doubleCounter = meter.counterBuilder("test.double.sum").ofDoubles().build(); | ||
|
||
return doubleSumState; | ||
} | ||
|
||
@SuppressWarnings("ForLoopReplaceableByForEach") // This is for GC sensitivity testing: no streams | ||
@Override | ||
public void recordValuesInInstruments( | ||
TestInstrumentType.TestInstrumentsState testInstrumentsState, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
DoubleSumState state = (DoubleSumState) testInstrumentsState; | ||
|
||
for (int j = 0; j < attributesList.size(); j++) { | ||
Attributes attributes = attributesList.get(j); | ||
for (int i = 0; i < measurementsPerAttributeSet; i++) { | ||
state.doubleCounter.add(1.2f, attributes); | ||
} | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...c/jmhBasedTest/java/io/opentelemetry/sdk/metrics/internal/state/tester/LongSumTester.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.state.tester; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.api.metrics.LongCounter; | ||
import io.opentelemetry.api.metrics.Meter; | ||
import io.opentelemetry.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.state.TestInstrumentType; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public class LongSumTester implements TestInstrumentType.InstrumentTester { | ||
private static final int measurementsPerAttributeSet = 1_000; | ||
|
||
static class LongSumState implements TestInstrumentType.TestInstrumentsState { | ||
LongCounter longCounter; | ||
} | ||
|
||
@Override | ||
public Aggregation testedAggregation() { | ||
return Aggregation.sum(); | ||
} | ||
|
||
@Override | ||
public TestInstrumentType.TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
LongSumState longSumState = new LongSumState(); | ||
|
||
Meter meter = sdkMeterProvider.meterBuilder("meter").build(); | ||
longSumState.longCounter = meter.counterBuilder("test.long.sum").build(); | ||
|
||
return longSumState; | ||
} | ||
|
||
@SuppressWarnings("ForLoopReplaceableByForEach") // This is for GC sensitivity testing: no streams | ||
@Override | ||
public void recordValuesInInstruments( | ||
TestInstrumentType.TestInstrumentsState testInstrumentsState, | ||
List<Attributes> attributesList, | ||
Random random) { | ||
LongSumState state = (LongSumState) testInstrumentsState; | ||
|
||
for (int j = 0; j < attributesList.size(); j++) { | ||
Attributes attributes = attributesList.get(j); | ||
for (int i = 0; i < measurementsPerAttributeSet; i++) { | ||
state.longCounter.add(1, attributes); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.