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 package org.spf4j;
33
34 import java.io.IOException;
35 import org.junit.Test;
36 import org.openjdk.jmh.results.format.ResultFormatType;
37 import org.openjdk.jmh.runner.Runner;
38 import org.openjdk.jmh.runner.RunnerException;
39 import org.openjdk.jmh.runner.options.Options;
40 import org.openjdk.jmh.runner.options.OptionsBuilder;
41 import org.slf4j.Logger;
42 import org.slf4j.LoggerFactory;
43 import org.spf4j.stackmonitor.JmhFlightRecorderProfiler;
44 import org.spf4j.stackmonitor.Spf4jJmhProfiler;
45 import org.spf4j.test.log.TestUtils;
46
47
48
49
50 public final class JmhTest {
51
52 private static final Logger LOG = LoggerFactory.getLogger(JmhTest.class);
53
54 @Test
55 public void runJmh() throws RunnerException, IOException {
56 if (TestUtils.isExecutedInCI()
57 || "true".equalsIgnoreCase(System.getProperty("is.release", "false"))
58 || !System.getProperty("project.version", "").contains("SNAPSHOT")) {
59 LOG.info("Benchmarks disabled in travis, not enough resources for this...");
60 return;
61 }
62 final String destinationFolder = System.getProperty("basedir",
63 org.spf4j.base.Runtime.USER_DIR) + "/target";
64 final String profile = System.getProperty("basedir",
65 org.spf4j.base.Runtime.USER_DIR) + "/src/main/jfc/profile.jfc";
66 Options opt = new OptionsBuilder()
67
68
69
70
71 .addProfiler(JmhFlightRecorderProfiler.class)
72 .addProfiler(Spf4jJmhProfiler.class)
73
74
75
76
77
78 .jvmArgs("-XX:MaxInlineLevel=12", "-XX:-RestrictContended",
79 "-XX:BiasedLockingStartupDelay=0",
80 "-Xmx256m", "-Xms256m", "-XX:+UnlockCommercialFeatures",
81 "-Djmh.stack.profiles=" + destinationFolder,
82
83 "-Dspf4j.executors.defaultExecutor.daemon=true",
84 "-Djmh.executor=FJP",
85 "-Djmh.fr.options=defaultrecording=true,settings=" + profile)
86 .result(destinationFolder + "/" + "benchmarkResults.csv")
87 .resultFormat(ResultFormatType.CSV)
88 .warmupIterations(3)
89 .measurementIterations(5)
90 .forks(1)
91 .build();
92 new Runner(opt).run();
93 }
94
95 }