changeset 1450:9df26c5f8b4b

7902169: JMH should capture and print VM name
author shade
date Fri, 04 May 2018 14:02:30 +0200
parents 2985092a3a59
children cfbab7c4f410
files jmh-core/src/main/java/org/openjdk/jmh/infra/BenchmarkParams.java jmh-core/src/main/java/org/openjdk/jmh/results/format/JSONResultFormat.java jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java jmh-core/src/main/java/org/openjdk/jmh/runner/format/TextReportFormat.java jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java jmh-core/src/test/java/org/openjdk/jmh/results/TestAggregateResult.java jmh-core/src/test/java/org/openjdk/jmh/results/format/ResultFormatTest.java jmh-core/src/test/java/org/openjdk/jmh/runner/RunnerTest.java jmh-core/src/test/resources/org/openjdk/jmh/results/format/output-golden.json
diffstat 9 files changed, 34 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/infra/BenchmarkParams.java	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/infra/BenchmarkParams.java	Fri May 04 14:02:30 2018 +0200
@@ -71,7 +71,7 @@
                            Mode mode, WorkloadParams params,
                            TimeUnit timeUnit, int opsPerInvocation,
                            String jvm, Collection<String> jvmArgs,
-                           String jdkVersion, String vmVersion, String jmhVersion,
+                           String jdkVersion, String vmName, String vmVersion, String jmhVersion,
                            TimeValue timeout) {
         super(benchmark, generatedTarget, synchIterations,
                 threads, threadGroups, threadGroupLabels,
@@ -80,7 +80,7 @@
                 mode, params,
                 timeUnit, opsPerInvocation,
                 jvm, jvmArgs,
-                jdkVersion, vmVersion, jmhVersion,
+                jdkVersion, vmName, vmVersion, jmhVersion,
                 timeout);
     }
 }
@@ -96,7 +96,7 @@
                              Mode mode, WorkloadParams params,
                              TimeUnit timeUnit, int opsPerInvocation,
                              String jvm, Collection<String> jvmArgs,
-                             String jdkVersion, String vmVersion, String jmhVersion,
+                             String jdkVersion, String vmName, String vmVersion, String jmhVersion,
                              TimeValue timeout) {
         super(benchmark, generatedTarget, synchIterations,
                 threads, threadGroups, threadGroupLabels,
@@ -105,7 +105,7 @@
                 mode, params,
                 timeUnit, opsPerInvocation,
                 jvm, jvmArgs,
-                jdkVersion, vmVersion, jmhVersion,
+                jdkVersion, vmName, vmVersion, jmhVersion,
                 timeout);
     }
 }
@@ -137,7 +137,7 @@
                              Mode mode, WorkloadParams params,
                              TimeUnit timeUnit, int opsPerInvocation,
                              String jvm, Collection<String> jvmArgs,
-                             String jdkVersion, String vmVersion, String jmhVersion,
+                             String jdkVersion, String vmName, String vmVersion, String jmhVersion,
                              TimeValue timeout) {
         super(benchmark, generatedTarget, synchIterations,
                 threads, threadGroups, threadGroupLabels,
@@ -146,7 +146,7 @@
                 mode, params,
                 timeUnit, opsPerInvocation,
                 jvm, jvmArgs,
-                jdkVersion, vmVersion, jmhVersion,
+                jdkVersion, vmName, vmVersion, jmhVersion,
                 timeout);
     }
 }
@@ -195,6 +195,7 @@
     protected final Collection<String> jvmArgs;
     protected final String jdkVersion;
     protected final String jmhVersion;
+    protected final String vmName;
     protected final String vmVersion;
     protected final TimeValue timeout;
 
@@ -205,7 +206,7 @@
                              Mode mode, WorkloadParams params,
                              TimeUnit timeUnit, int opsPerInvocation,
                              String jvm, Collection<String> jvmArgs,
-                             String jdkVersion, String vmVersion, String jmhVersion,
+                             String jdkVersion, String vmName, String vmVersion, String jmhVersion,
                              TimeValue timeout) {
         this.benchmark = benchmark;
         this.generatedTarget = generatedTarget;
@@ -224,6 +225,7 @@
         this.jvm = jvm;
         this.jvmArgs = jvmArgs;
         this.jdkVersion = jdkVersion;
+        this.vmName = vmName;
         this.vmVersion = vmVersion;
         this.jmhVersion = jmhVersion;
         this.timeout = timeout;
@@ -386,6 +388,14 @@
         return vmVersion;
     }
 
+    /**
+     * @return name information as returned by the effective target JVM,
+     *         via system property {@code java.vm.name}
+     */
+    public String getVmName() {
+        return vmName;
+    }
+
     @Override
     public boolean equals(Object o) {
         if (this == o) return true;
--- a/jmh-core/src/main/java/org/openjdk/jmh/results/format/JSONResultFormat.java	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/results/format/JSONResultFormat.java	Fri May 04 14:02:30 2018 +0200
@@ -80,6 +80,7 @@
             printStringArray(pw, params.getJvmArgs());
             pw.println("],");
             pw.println("\"jdkVersion\" : " + toJsonString(params.getJdkVersion()) + ",");
+            pw.println("\"vmName\" : " + toJsonString(params.getVmName()) + ",");
             pw.println("\"vmVersion\" : " + toJsonString(params.getVmVersion()) + ",");
             pw.println("\"warmupIterations\" : " + params.getWarmup().getCount() + ",");
             pw.println("\"warmupTime\" : \"" + params.getWarmup().getTime() + "\",");
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/Runner.java	Fri May 04 14:02:30 2018 +0200
@@ -495,12 +495,13 @@
 
         String jdkVersion = targetProperties.getProperty("java.version");
         String vmVersion = targetProperties.getProperty("java.vm.version");
+        String vmName = targetProperties.getProperty("java.vm.name");
         return new BenchmarkParams(benchmark.getUsername(), benchmark.generatedTarget(), synchIterations,
                 threads, threadGroups, benchmark.getThreadGroupLabels().orElse(Collections.<String>emptyList()),
                 forks, warmupForks,
                 warmup, measurement, benchmark.getMode(), benchmark.getWorkloadParams(), timeUnit, opsPerInvocation,
                 jvm, jvmArgs,
-                jdkVersion, vmVersion, Version.getPlainVersion(),
+                jdkVersion, vmName, vmVersion, Version.getPlainVersion(),
                 timeout);
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/format/TextReportFormat.java	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/format/TextReportFormat.java	Fri May 04 14:02:30 2018 +0200
@@ -62,7 +62,7 @@
         }
 
         println("# JMH version: " + params.getJmhVersion());
-        println("# VM version: JDK " + params.getJdkVersion() + ", VM " + params.getVmVersion());
+        println("# VM version: JDK " + params.getJdkVersion() + ", " + params.getVmName() + ", " + params.getVmVersion());
         println("# VM invoker: " + params.getJvm());
         println("# VM options: " + opts);
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/util/Utils.java	Fri May 04 14:02:30 2018 +0200
@@ -507,7 +507,7 @@
      * @return Copy of system properties we want to record in the results.
      */
     public static Properties getRecordedSystemProperties() {
-        String[] names = new String[]{"java.version", "java.vm.version"};
+        String[] names = new String[]{"java.version", "java.vm.version", "java.vm.name"};
         Properties p = new Properties();
         for (String i : names) {
             p.setProperty(i, System.getProperty(i));
--- a/jmh-core/src/test/java/org/openjdk/jmh/results/TestAggregateResult.java	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/test/java/org/openjdk/jmh/results/TestAggregateResult.java	Fri May 04 14:02:30 2018 +0200
@@ -57,7 +57,7 @@
                         new IterationParams(IterationType.MEASUREMENT, 1, TimeValue.seconds(1), 1),
                         Mode.Throughput, null, TimeUnit.SECONDS, 1,
                         Utils.getCurrentJvm(), Collections.<String>emptyList(),
-                        System.getProperty("java.version"), System.getProperty("java.vm.version"), Version.getPlainVersion(),
+                        System.getProperty("java.version"), System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), Version.getPlainVersion(),
                         TimeValue.days(1)),
                 new IterationParams(IterationType.MEASUREMENT, 1, TimeValue.days(1), 1),
                 null
--- a/jmh-core/src/test/java/org/openjdk/jmh/results/format/ResultFormatTest.java	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/test/java/org/openjdk/jmh/results/format/ResultFormatTest.java	Fri May 04 14:02:30 2018 +0200
@@ -56,6 +56,8 @@
      */
     private static final String JDK_VERSION_DUMMY = "1.8-dummy";
 
+    private static final String VM_NAME_DUMMY = "DummyVM";
+
     private static final String VM_VERSION_DUMMY = "4711";
 
     private static final String JMH_VERSION_DUMMY = "1.18";
@@ -86,7 +88,7 @@
                     TimeUnit.SECONDS, 1,
                     JVM_DUMMY,
                     Collections.<String>emptyList(),
-                    JDK_VERSION_DUMMY, VM_VERSION_DUMMY, JMH_VERSION_DUMMY,
+                    JDK_VERSION_DUMMY, VM_NAME_DUMMY, VM_VERSION_DUMMY, JMH_VERSION_DUMMY,
                     TimeValue.days(1));
 
             Collection<BenchmarkResult> benchmarkResults = new ArrayList<>();
--- a/jmh-core/src/test/java/org/openjdk/jmh/runner/RunnerTest.java	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/test/java/org/openjdk/jmh/runner/RunnerTest.java	Fri May 04 14:02:30 2018 +0200
@@ -66,7 +66,7 @@
                 new IterationParams(IterationType.MEASUREMENT, 1, TimeValue.seconds(1), 1),
                 Mode.Throughput, null, TimeUnit.SECONDS, 1,
                 Utils.getCurrentJvm(), Collections.<String>emptyList(),
-                System.getProperty("java.version"), System.getProperty("java.vm.version"), Version.getPlainVersion(),
+                System.getProperty("java.version"), System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), Version.getPlainVersion(),
                 TimeValue.days(1));
         List<String> command = blade.getForkedMainCommand(bp, Collections.<ExternalProfiler>emptyList(), DUMMY_HOST, DUMMY_PORT);
 
@@ -98,7 +98,7 @@
                 new IterationParams(IterationType.MEASUREMENT, 1, TimeValue.seconds(1), 1),
                 Mode.Throughput, null, TimeUnit.SECONDS, 1,
                 Utils.getCurrentJvm(), Collections.singletonList(CompilerHints.XX_COMPILE_COMMAND_FILE + tempHints),
-                System.getProperty("java.version"), System.getProperty("java.vm.version"), Version.getPlainVersion(),
+                System.getProperty("java.version"), System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), Version.getPlainVersion(),
                 TimeValue.days(1));
         List<String> command = blade.getForkedMainCommand(bp, Collections.<ExternalProfiler>emptyList(), DUMMY_HOST, DUMMY_PORT);
 
@@ -135,7 +135,7 @@
                 Mode.Throughput, null, TimeUnit.SECONDS, 1,
                 Utils.getCurrentJvm(),
                 Arrays.asList(CompilerHints.XX_COMPILE_COMMAND_FILE + tempHints1, CompilerHints.XX_COMPILE_COMMAND_FILE + tempHints2),
-                System.getProperty("java.version"), System.getProperty("java.vm.version"), Version.getPlainVersion(),
+                System.getProperty("java.version"), System.getProperty("java.vm.name"), System.getProperty("java.vm.version"), Version.getPlainVersion(),
                 TimeValue.days(1));
         List<String> command = blade.getForkedMainCommand(bp, Collections.<ExternalProfiler>emptyList(), DUMMY_HOST, DUMMY_PORT);
 
--- a/jmh-core/src/test/resources/org/openjdk/jmh/results/format/output-golden.json	Fri May 04 13:19:01 2018 +0200
+++ b/jmh-core/src/test/resources/org/openjdk/jmh/results/format/output-golden.json	Fri May 04 14:02:30 2018 +0200
@@ -9,6 +9,7 @@
         "jvmArgs" : [
         ],
         "jdkVersion" : "1.8-dummy",
+        "vmName" : "DummyVM",
         "vmVersion" : "4711",
         "warmupIterations" : 84,
         "warmupTime" : "375 s",
@@ -231,6 +232,7 @@
         "jvmArgs" : [
         ],
         "jdkVersion" : "1.8-dummy",
+        "vmName" : "DummyVM",
         "vmVersion" : "4711",
         "warmupIterations" : 544,
         "warmupTime" : "409 s",
@@ -336,6 +338,7 @@
         "jvmArgs" : [
         ],
         "jdkVersion" : "1.8-dummy",
+        "vmName" : "DummyVM",
         "vmVersion" : "4711",
         "warmupIterations" : 384,
         "warmupTime" : "105 s",
@@ -503,6 +506,7 @@
         "jvmArgs" : [
         ],
         "jdkVersion" : "1.8-dummy",
+        "vmName" : "DummyVM",
         "vmVersion" : "4711",
         "warmupIterations" : 628,
         "warmupTime" : "207 s",
@@ -702,6 +706,7 @@
         "jvmArgs" : [
         ],
         "jdkVersion" : "1.8-dummy",
+        "vmName" : "DummyVM",
         "vmVersion" : "4711",
         "warmupIterations" : 997,
         "warmupTime" : "651 s",