dumpOtlp() should accept Counter argument (#1728)

This commit is contained in:
Andrei Pangin
2026-04-15 19:38:08 +01:00
committed by GitHub
parent 86adc1605a
commit f6ca3c1ff8
4 changed files with 8 additions and 7 deletions

View File

@@ -201,7 +201,7 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
@Override
public String dumpCollapsed(Counter counter) {
try {
return execute0("collapsed," + counter.name().toLowerCase());
return execute0("collapsed," + (counter == Counter.SAMPLES ? "samples" : "total"));
} catch (IOException e) {
throw new IllegalStateException(e);
}
@@ -242,12 +242,13 @@ public class AsyncProfiler implements AsyncProfilerMXBean {
* <p>
* This API is UNSTABLE and might change or be removed in the next version of async-profiler.
*
* @param counter Which counter to use for aggregation
* @return OTLP representation of the profile
*/
@Override
public byte[] dumpOtlp() {
public byte[] dumpOtlp(Counter counter) {
try {
return execute1("otlp");
return execute1("otlp," + (counter == Counter.SAMPLES ? "samples" : "total"));
} catch (IOException e) {
throw new IllegalStateException(e);
}

View File

@@ -31,5 +31,5 @@ public interface AsyncProfilerMXBean {
String dumpCollapsed(Counter counter);
String dumpTraces(int maxTraces);
String dumpFlat(int maxMethods);
byte[] dumpOtlp();
byte[] dumpOtlp(Counter counter);
}

View File

@@ -5,7 +5,6 @@
package test.api;
import java.nio.ByteBuffer;
import one.profiler.AsyncProfiler;
import one.profiler.Counter;
import one.profiler.Events;
@@ -22,7 +21,7 @@ public class DumpOtlp extends BusyLoops {
}
// TODO: Should we test this further?
byte[] profile = AsyncProfiler.getInstance().dumpOtlp();
byte[] profile = AsyncProfiler.getInstance().dumpOtlp(Counter.TOTAL);
System.out.println(profile.length);
}
}

View File

@@ -5,6 +5,7 @@
package test.otlp;
import one.profiler.AsyncProfiler;
import one.profiler.Counter;
import one.profiler.Events;
import io.opentelemetry.proto.profiles.v1development.*;
@@ -39,7 +40,7 @@ public class OtlpProfileTimeTest {
}
public static Profile dumpAndGetProfile(AsyncProfiler profiler) throws Exception {
byte[] dump = profiler.dumpOtlp();
byte[] dump = profiler.dumpOtlp(Counter.SAMPLES);
ProfilesData data = ProfilesData.parseFrom(dump);
return data.getResourceProfiles(0).getScopeProfiles(0).getProfiles(0);
}