add average and max cpu to results.
MODIFY
benchmark-overhead/src/test/java/io/opentelemetry/results/AppPerfResults.java
benchmark-overhead/src/test/java/io/opentelemetry/results/AppPerfResults.java
@@ -23,6 +23,9 @@ public class AppPerfResults {
final long peakThreadCount;
final long averageNetworkRead;
final long averageNetworkWrite;
+ final float averageJvmUserCpu;
+ final float maxJvmUserCpu;
+
private AppPerfResults(Builder builder) {
this.agent = builder.agent;
@@ -39,6 +42,8 @@ public class AppPerfResults {
this.peakThreadCount = builder.peakThreadCount;
this.averageNetworkRead = builder.averageNetworkRead;
this.averageNetworkWrite = builder.averageNetworkWrite;
+ this.averageJvmUserCpu = builder.averageJvmUserCpu;
+ this.maxJvmUserCpu = builder.maxJvmUserCpu;
}
double getTotalAllocatedMB() {
@@ -67,6 +72,8 @@ public class AppPerfResults {
private long peakThreadCount;
public long averageNetworkRead;
public long averageNetworkWrite;
+ public float averageJvmUserCpu;
+ public float maxJvmUserCpu;
AppPerfResults build() {
return new AppPerfResults(this);
@@ -141,8 +148,20 @@ public class AppPerfResults {
this.averageNetworkWrite = averageNetworkWrite;
return this;
}
+
+ Builder averageJvmUserCpu(float averageJvmUserCpu){
+ this.averageJvmUserCpu = averageJvmUserCpu;
+ return this;
}
+ Builder maxJvmUserCpu(float maxJvmUserCpu){
+ this.maxJvmUserCpu = maxJvmUserCpu;
+ return this;
+ }
+ }
+
+
+
public static class MinMax {
public final long min;
public final long max;

MODIFY
benchmark-overhead/src/test/java/io/opentelemetry/results/CsvPersister.java
benchmark-overhead/src/test/java/io/opentelemetry/results/CsvPersister.java
@@ -42,6 +42,8 @@ class CsvPersister implements ResultsPersister {
sb.append(",").append(result.averageNetworkRead);
sb.append(",").append(result.averageNetworkWrite);
sb.append(",").append(result.peakThreadCount);
+ sb.append(",").append(result.averageJvmUserCpu);
+ sb.append(",").append(result.maxJvmUserCpu);
});
sb.append("\n");
try {
@@ -84,6 +86,8 @@ class CsvPersister implements ResultsPersister {
sb.append(",").append(agent).append(":netReadAvg");
sb.append(",").append(agent).append(":netWriteAvg");
sb.append(",").append(agent).append(":peakThreadCount");
+ sb.append(",").append(agent).append(":averageCpuUser");
+ sb.append(",").append(agent).append(":maxCpuUser");
});
sb.append("\n");
return sb.toString();

MODIFY
benchmark-overhead/src/test/java/io/opentelemetry/results/PrintStreamPersister.java
benchmark-overhead/src/test/java/io/opentelemetry/results/PrintStreamPersister.java
@@ -30,6 +30,8 @@ class PrintStreamPersister implements ResultsPersister {
out.println("----------------------------------------------------------");
display(sorted, "Agent", appPerfResults -> appPerfResults.agent.getName());
+ display(sorted, "Avg. CPU (user)", res -> String.valueOf(res.averageJvmUserCpu));
+ display(sorted, "Max. CPU (user)", res -> String.valueOf(res.maxJvmUserCpu));
display(sorted, "Startup time (ms)", res -> String.valueOf(res.startupDurationMs));
display(sorted, "Total allocated MB", res -> format(res.getTotalAllocatedMB()));
display(sorted, "Heap (min)", res -> String.valueOf(res.heapUsed.min));

MODIFY
benchmark-overhead/src/test/java/io/opentelemetry/results/ResultsCollector.java
benchmark-overhead/src/test/java/io/opentelemetry/results/ResultsCollector.java
@@ -77,7 +77,17 @@ public class ResultsCollector {
.maxThreadContextSwitchRate(readMaxThreadContextSwitchRate(jfrFile))
.peakThreadCount(readPeakThreadCount(jfrFile))
.averageNetworkRead(computeAverageNetworkRead(jfrFile))
- .averageNetworkWrite(computeAverageNetworkWrite(jfrFile));
+ .averageNetworkWrite(computeAverageNetworkWrite(jfrFile))
+ .averageJvmUserCpu(computeAverageJvmUserCpu(jfrFile))
+ .maxJvmUserCpu(computeMaxJvmUserCpu(jfrFile));
+ }
+
+ private float computeAverageJvmUserCpu(Path jfrFile) throws IOException {
+ return JFRUtils.computeAverageFloat(jfrFile, "jdk.CPULoad", "jvmUser");
+ }
+
+ private float computeMaxJvmUserCpu(Path jfrFile) throws IOException {
+ return JFRUtils.findMaxFloat(jfrFile, "jdk.CPULoad", "jvmUser");
}
private long computeAverageNetworkRead(Path jfrFile) throws IOException {

MODIFY
benchmark-overhead/src/test/java/io/opentelemetry/util/JFRUtils.java
benchmark-overhead/src/test/java/io/opentelemetry/util/JFRUtils.java
@@ -40,6 +40,12 @@ public class JFRUtils {
AverageSupport::add).average();
}
+ public static float computeAverageFloat(Path jfrFile, String eventName, String valueKey) throws IOException {
+ return reduce(jfrFile, eventName, valueKey,
+ new AverageFloatSupport(),
+ AverageFloatSupport::add).average();
+ }
+
private static <T, V> T reduce(Path jfrFile, String eventName,
String valueKey, T initial, BiFunction<T,V,T> reducer) throws IOException {
RecordingFile recordingFile = new RecordingFile(jfrFile);
@@ -67,4 +73,18 @@ public class JFRUtils {
return total/count;
}
}
+
+ static class AverageFloatSupport {
+ long count;
+ float total;
+ AverageFloatSupport add(float value){
+ count++;
+ total += value;
+ return this;
+ }
+ float average(){
+ if(count == 0) return -1;
+ return total/count;
+ }
+ }
}

add average and max cpu to results. (#3940)