changeset 386:ba51dff93e4b

OptionBuilder.detectJvmArgs() discovers parent VMs JVM args.
author shade
date Tue, 11 Feb 2014 19:54:50 +0400
parents 55a0d7fe2040
children a5dc4bed3735
files jmh-api-samples/src/main/java/org/openjdk/jmh/SimpleTest.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java
diffstat 3 files changed, 19 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-api-samples/src/main/java/org/openjdk/jmh/SimpleTest.java	Tue Feb 11 18:58:52 2014 +0400
+++ b/jmh-api-samples/src/main/java/org/openjdk/jmh/SimpleTest.java	Tue Feb 11 19:54:50 2014 +0400
@@ -46,7 +46,7 @@
                 .include(".*")
                 .warmupTime(TimeValue.milliseconds(100))
                 .measurementTime(TimeValue.milliseconds(100))
-                .jvmArgs("-server")
+                .detectJvmArgs()
                 .forks(5)
                 .build();
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java	Tue Feb 11 18:58:52 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/ChainedOptionsBuilder.java	Tue Feb 11 19:54:50 2014 +0400
@@ -224,4 +224,10 @@
      */
     ChainedOptionsBuilder jvmArgs(String... value);
 
+    /**
+     * Autodetect forked JVM arguments from the parent VM.
+     * @return builder
+     */
+    ChainedOptionsBuilder detectJvmArgs();
+
 }
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java	Tue Feb 11 18:58:52 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java	Tue Feb 11 19:54:50 2014 +0400
@@ -30,6 +30,7 @@
 import org.openjdk.jmh.runner.parameters.TimeValue;
 import org.openjdk.jmh.util.internal.Optional;
 
+import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -509,7 +510,12 @@
 
     @Override
     public ChainedOptionsBuilder jvmArgs(String... value) {
-        this.jvmArgs = Optional.<Collection<String>>of(Arrays.asList(value));
+        if (jvmArgs.hasValue()) {
+            jvmArgs.get().addAll(Arrays.asList(value));
+        } else {
+            Collection<String> vals = new ArrayList<String>(Arrays.asList(value));
+            jvmArgs = Optional.<Collection<String>>of(vals);
+        }
         return this;
     }
 
@@ -522,4 +528,9 @@
         }
     }
 
+    @Override
+    public ChainedOptionsBuilder detectJvmArgs() {
+        List<String> inputArguments = ManagementFactory.getRuntimeMXBean().getInputArguments();
+        return jvmArgs(inputArguments.toArray(new String[inputArguments.size()]));
+    }
 }