-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathWhiteboxProfiler.java
More file actions
64 lines (57 loc) · 2.41 KB
/
WhiteboxProfiler.java
File metadata and controls
64 lines (57 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package com.datadoghq.profiler.stresstest;
import com.datadoghq.profiler.JavaProfiler;
import org.openjdk.jmh.infra.BenchmarkParams;
import org.openjdk.jmh.infra.IterationParams;
import org.openjdk.jmh.profile.InternalProfiler;
import org.openjdk.jmh.results.AggregationPolicy;
import org.openjdk.jmh.results.IterationResult;
import org.openjdk.jmh.results.Result;
import org.openjdk.jmh.results.ScalarResult;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
public class WhiteboxProfiler implements InternalProfiler {
private Path jfr;
@Override
public String getDescription() {
return "ddprof-whitebox";
}
@Override
public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) {
try {
jfr = Files.createTempFile(benchmarkParams.getBenchmark() + System.currentTimeMillis(), ".jfr");
String command = "start," + benchmarkParams.getParam("command")
+ ",jfr,file=" + jfr.toAbsolutePath();
JavaProfiler.getInstance().execute(command);
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
public Collection<? extends Result> afterIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams, IterationResult result) {
// TODO unit encoded in counter name for now, so results are effectively dimensionless
try {
JavaProfiler.getInstance().stop();
long fileSize = Files.size(jfr);
Files.deleteIfExists(jfr);
if (!Boolean.parseBoolean(benchmarkParams.getParam("skipResults"))) {
List<ScalarResult> results = new ArrayList<>();
results.add(new ScalarResult("jfr_filesize_bytes", fileSize, "", AggregationPolicy.MAX));
for (Map.Entry<String, Long> counter : JavaProfiler.getInstance().getDebugCounters().entrySet()) {
results.add(new ScalarResult(counter.getKey(), counter.getValue(), "", AggregationPolicy.MAX));
}
return results;
} else {
return Collections.emptyList();
}
} catch (IOException e) {
e.printStackTrace();
return Collections.emptyList();
}
}
}