changeset 1252:8aaae8226846

7901460: Profilers throw opaque InvocationTargetExceptions when options are mistyped
author shade
date Wed, 08 Jul 2015 00:24:16 +0300
parents ef2249099e8b
children e801861b0f09
files jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfNormProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/StackProfiler.java jmh-core/src/main/java/org/openjdk/jmh/profile/WinPerfAsmProfiler.java
diffstat 6 files changed, 73 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java	Tue Jul 07 23:51:41 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/AbstractPerfAsmProfiler.java	Wed Jul 08 00:24:16 2015 +0300
@@ -24,6 +24,7 @@
  */
 package org.openjdk.jmh.profile;
 
+import joptsimple.OptionException;
 import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
@@ -188,34 +189,38 @@
 
         set = ProfilerUtils.parseInitLine(initLine, parser);
 
-        this.events = set.valuesOf(optEvents);
-        regionRateThreshold = set.valueOf(optThresholdRate);
-        regionShowTop = set.valueOf(optShowTop);
-        regionTooBigThreshold = set.valueOf(optThreshold);
-        printMargin = set.valueOf(optPrintMargin);
-        mergeMargin = set.valueOf(optMergeMargin);
-        delayMsec = set.valueOf(optDelay);
+        try {
+            this.events = set.valuesOf(optEvents);
+            regionRateThreshold = set.valueOf(optThresholdRate);
+            regionShowTop = set.valueOf(optShowTop);
+            regionTooBigThreshold = set.valueOf(optThreshold);
+            printMargin = set.valueOf(optPrintMargin);
+            mergeMargin = set.valueOf(optMergeMargin);
+            delayMsec = set.valueOf(optDelay);
 
-        skipAssembly = set.valueOf(optSkipAsm);
-        skipInterpreter = set.valueOf(optSkipInterpreter);
-        skipVMStubs = set.valueOf(optSkipVMStubs);
+            skipAssembly = set.valueOf(optSkipAsm);
+            skipInterpreter = set.valueOf(optSkipInterpreter);
+            skipVMStubs = set.valueOf(optSkipVMStubs);
 
-        savePerfOutput = set.valueOf(optPerfOut);
-        savePerfOutputTo = set.valueOf(optPerfOutTo);
-        savePerfOutputToFile = set.valueOf(optPerfOutToFile);
+            savePerfOutput = set.valueOf(optPerfOut);
+            savePerfOutputTo = set.valueOf(optPerfOutTo);
+            savePerfOutputToFile = set.valueOf(optPerfOutToFile);
 
-        savePerfBin = set.valueOf(optPerfBin);
-        savePerfBinTo = set.valueOf(optPerfBinTo);
-        savePerfBinFile = set.valueOf(optPerfBinToFile);
+            savePerfBin = set.valueOf(optPerfBin);
+            savePerfBinTo = set.valueOf(optPerfBinTo);
+            savePerfBinFile = set.valueOf(optPerfBinToFile);
 
-        saveLog = set.valueOf(optSaveLog);
-        saveLogTo = set.valueOf(optSaveLogTo);
-        saveLogToFile = set.valueOf(optSaveLogToFile);
+            saveLog = set.valueOf(optSaveLog);
+            saveLogTo = set.valueOf(optSaveLogTo);
+            saveLogToFile = set.valueOf(optSaveLogToFile);
 
-        intelSyntax = set.valueOf(optIntelSyntax);
-        printCompilationInfo = set.valueOf(optPrintCompilationInfo);
-        drawIntraJumps = set.valueOf(optDrawInterJumps);
-        drawInterJumps = set.valueOf(optDrawIntraJumps);
+            intelSyntax = set.valueOf(optIntelSyntax);
+            printCompilationInfo = set.valueOf(optPrintCompilationInfo);
+            drawIntraJumps = set.valueOf(optDrawInterJumps);
+            drawInterJumps = set.valueOf(optDrawIntraJumps);
+        } catch (OptionException e) {
+            throw new ProfilerException(e.getMessage());
+        }
     }
 
     protected abstract void addMyOptions(OptionParser parser);
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Tue Jul 07 23:51:41 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Wed Jul 08 00:24:16 2015 +0300
@@ -24,6 +24,7 @@
  */
 package org.openjdk.jmh.profile;
 
+import joptsimple.OptionException;
 import joptsimple.OptionParser;
 import joptsimple.OptionSpec;
 import org.openjdk.jmh.infra.BenchmarkParams;
@@ -50,7 +51,11 @@
             throw new ProfilerException(failMsg.toString());
         }
 
-        sampleFrequency = set.valueOf(optFrequency);
+        try {
+            sampleFrequency = set.valueOf(optFrequency);
+        } catch (OptionException e) {
+            throw new ProfilerException(e.getMessage());
+        }
     }
 
     @Override
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfNormProfiler.java	Tue Jul 07 23:51:41 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfNormProfiler.java	Wed Jul 08 00:24:16 2015 +0300
@@ -24,6 +24,7 @@
  */
 package org.openjdk.jmh.profile;
 
+import joptsimple.OptionException;
 import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
@@ -95,12 +96,17 @@
 
         OptionSet set = ProfilerUtils.parseInitLine(initLine, parser);
 
-        delayMs = set.valueOf(optDelay);
-        incrementInterval = set.valueOf(optIncrementInterval);
-        highPassFilter = set.valueOf(optHighPassFilter);
-        useDefaultStats = set.valueOf(optDefaultStat);
+        Collection<String> userEvents;
 
-        Collection<String> userEvents = set.valuesOf(optEvents);
+        try {
+            delayMs = set.valueOf(optDelay);
+            incrementInterval = set.valueOf(optIncrementInterval);
+            highPassFilter = set.valueOf(optHighPassFilter);
+            useDefaultStats = set.valueOf(optDefaultStat);
+            userEvents = set.valuesOf(optEvents);
+        } catch (OptionException e) {
+            throw new ProfilerException(e.getMessage());
+        }
 
         Collection<String> msgs = Utils.tryWith("perf", "stat", "--log-fd", "2", "--field-separator", ",", "echo", "1");
         if (!msgs.isEmpty()) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java	Tue Jul 07 23:51:41 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java	Wed Jul 08 00:24:16 2015 +0300
@@ -24,6 +24,7 @@
  */
 package org.openjdk.jmh.profile;
 
+import joptsimple.OptionException;
 import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
@@ -58,7 +59,11 @@
 
         OptionSet set = ProfilerUtils.parseInitLine(initLine, parser);
 
-        delayMs = set.valueOf(optDelay);
+        try {
+            delayMs = set.valueOf(optDelay);
+        } catch (OptionException e) {
+            throw new ProfilerException(e.getMessage());
+        }
 
         Collection<String> msgs = Utils.tryWith("perf", "stat", "--log-fd", "2", "echo", "1");
         if (!msgs.isEmpty()) {
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/StackProfiler.java	Tue Jul 07 23:51:41 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/StackProfiler.java	Wed Jul 08 00:24:16 2015 +0300
@@ -24,6 +24,7 @@
  */
 package org.openjdk.jmh.profile;
 
+import joptsimple.OptionException;
 import joptsimple.OptionParser;
 import joptsimple.OptionSet;
 import joptsimple.OptionSpec;
@@ -98,15 +99,19 @@
 
         OptionSet set = ProfilerUtils.parseInitLine(initLine, parser);
 
-        sampleLine = set.valueOf(optDetailLine);
-        periodMsec = set.valueOf(optSamplePeriod);
-        topStacks = set.valueOf(optTopStacks);
-        stackLines = set.valueOf(optStackLines);
+        try {
+            sampleLine = set.valueOf(optDetailLine);
+            periodMsec = set.valueOf(optSamplePeriod);
+            topStacks = set.valueOf(optTopStacks);
+            stackLines = set.valueOf(optStackLines);
 
-        boolean excludePackages = set.valueOf(optExclude);
-        excludePackageNames = excludePackages ?
-                new HashSet<String>(set.valuesOf(optExcludeClasses)) :
-                Collections.<String>emptySet();
+            boolean excludePackages = set.valueOf(optExclude);
+            excludePackageNames = excludePackages ?
+                    new HashSet<String>(set.valuesOf(optExcludeClasses)) :
+                    Collections.<String>emptySet();
+        } catch (OptionException e) {
+            throw new ProfilerException(e.getMessage());
+        }
     }
 
     private volatile SamplingTask samplingTask;
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/WinPerfAsmProfiler.java	Tue Jul 07 23:51:41 2015 +0300
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/WinPerfAsmProfiler.java	Wed Jul 08 00:24:16 2015 +0300
@@ -24,6 +24,7 @@
  */
 package org.openjdk.jmh.profile;
 
+import joptsimple.OptionException;
 import joptsimple.OptionParser;
 import joptsimple.OptionSpec;
 import org.openjdk.jmh.infra.BenchmarkParams;
@@ -83,11 +84,14 @@
     public WinPerfAsmProfiler(String initLine) throws ProfilerException {
         super(initLine, "SampledProfile");
 
-        String xperfDir = set.valueOf(optXperfDir);
-        xperfProviders = set.valueOf(optXperfProviders);
-        symbolDir = set.valueOf(optSymbolDir);
-
-        path = xperfDir != null && !xperfDir.isEmpty() ? xperfDir + File.separatorChar + "xperf" : "xperf";
+        try {
+            String xperfDir = set.valueOf(optXperfDir);
+            xperfProviders = set.valueOf(optXperfProviders);
+            symbolDir = set.valueOf(optSymbolDir);
+            path = xperfDir != null && !xperfDir.isEmpty() ? xperfDir + File.separatorChar + "xperf" : "xperf";
+        } catch (OptionException e) {
+            throw new ProfilerException(e.getMessage());
+        }
 
         Collection<String> errs = Utils.tryWith(path);
         if (!errs.isEmpty()) {