-
Notifications
You must be signed in to change notification settings - Fork 841
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 3rd and last part support for synchronous instrum…
…ents - exponential histogram (#6136) Co-authored-by: jack-berg <[email protected]>
- Loading branch information
Showing
7 changed files
with
299 additions
and
47 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
75 changes: 75 additions & 0 deletions
75
...s/src/jmhBasedTest/java/io/opentelemetry/sdk/metrics/internal/state/ProfileBenchmark.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,75 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.state; | ||
|
||
import io.opentelemetry.sdk.common.export.MemoryMode; | ||
import io.opentelemetry.sdk.metrics.data.AggregationTemporality; | ||
|
||
/** | ||
* This benchmark class is used to see memory allocation flame graphs for a single run. | ||
* | ||
* <p>Steps: | ||
* | ||
* <ol> | ||
* <li>Follow download instructions for async-profiler, located at <a | ||
* href="https://github.com/async-profiler/async-profiler">this location</a> | ||
* <li>Assuming you have extracted it at /tmp/async-profiler-2.9-macos, add the following to your | ||
* JVM arguments of your run configuration: | ||
* <pre> | ||
* -agentpath:/tmp/async-profiler-2.9-macos/build/libasyncProfiler.so=start,event=alloc,flamegraph,file=/tmp/profiled_data.html | ||
* </pre> | ||
* <li>Tune the parameters as you see fit (They are marked below with "Parameters") | ||
* <li>Run the class (its main function) | ||
* <li>Open /tmp/profiled_data.html with your browser | ||
* <li>Use the flame graph to see where the allocations are happening the most and fix | ||
* <li>Run {@link InstrumentGarbageCollectionBenchmark} and see if it passes now | ||
* <li>If not, repeat | ||
* </ol> | ||
*/ | ||
public class ProfileBenchmark { | ||
|
||
private ProfileBenchmark() {} | ||
|
||
public static void main(String[] args) { | ||
// Parameters | ||
AggregationTemporality aggregationTemporality = AggregationTemporality.DELTA; | ||
MemoryMode memoryMode = MemoryMode.REUSABLE_DATA; | ||
TestInstrumentType testInstrumentType = TestInstrumentType.EXPONENTIAL_HISTOGRAM; | ||
|
||
InstrumentGarbageCollectionBenchmark.ThreadState benchmarkSetup = | ||
new InstrumentGarbageCollectionBenchmark.ThreadState(); | ||
|
||
benchmarkSetup.aggregationTemporality = aggregationTemporality; | ||
benchmarkSetup.memoryMode = memoryMode; | ||
benchmarkSetup.testInstrumentType = testInstrumentType; | ||
|
||
InstrumentGarbageCollectionBenchmark benchmark = new InstrumentGarbageCollectionBenchmark(); | ||
|
||
benchmarkSetup.setup(); | ||
|
||
warmup(benchmark, benchmarkSetup); | ||
|
||
// This is divided explicitly to two methods so you can focus on `measure` in the flame graph | ||
// when trying to decrease the allocations | ||
measure(benchmark, benchmarkSetup); | ||
} | ||
|
||
public static void warmup( | ||
InstrumentGarbageCollectionBenchmark benchmark, | ||
InstrumentGarbageCollectionBenchmark.ThreadState benchmarkSetup) { | ||
for (int i = 0; i < 10; i++) { | ||
benchmark.recordAndCollect(benchmarkSetup); | ||
} | ||
} | ||
|
||
public static void measure( | ||
InstrumentGarbageCollectionBenchmark benchmark, | ||
InstrumentGarbageCollectionBenchmark.ThreadState benchmarkSetup) { | ||
for (int i = 0; i < 200; i++) { | ||
benchmark.recordAndCollect(benchmarkSetup); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
...src/jmhBasedTest/java/io/opentelemetry/sdk/metrics/internal/state/TestInstrumentType.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,50 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.sdk.metrics.internal.state; | ||
|
||
import io.opentelemetry.api.common.Attributes; | ||
import io.opentelemetry.sdk.metrics.Aggregation; | ||
import io.opentelemetry.sdk.metrics.SdkMeterProvider; | ||
import io.opentelemetry.sdk.metrics.internal.state.tester.AsyncCounterTester; | ||
import io.opentelemetry.sdk.metrics.internal.state.tester.ExponentialHistogramTester; | ||
import java.util.List; | ||
import java.util.Random; | ||
|
||
public enum TestInstrumentType { | ||
ASYNC_COUNTER() { | ||
@Override | ||
InstrumentTester createInstrumentTester() { | ||
return new AsyncCounterTester(); | ||
} | ||
}, | ||
EXPONENTIAL_HISTOGRAM() { | ||
@Override | ||
InstrumentTester createInstrumentTester() { | ||
return new ExponentialHistogramTester(); | ||
} | ||
}; | ||
|
||
abstract InstrumentTester createInstrumentTester(); | ||
|
||
TestInstrumentType() {} | ||
|
||
public interface InstrumentTester { | ||
Aggregation testedAggregation(); | ||
|
||
TestInstrumentsState buildInstruments( | ||
double instrumentCount, | ||
SdkMeterProvider sdkMeterProvider, | ||
List<Attributes> attributesList, | ||
Random random); | ||
|
||
void recordValuesInInstruments( | ||
TestInstrumentsState testInstrumentsState, List<Attributes> attributesList, Random random); | ||
} | ||
|
||
public interface TestInstrumentsState {} | ||
|
||
public static class EmptyInstrumentsState implements TestInstrumentsState {} | ||
} |
Oops, something went wrong.