changeset 147:f8d3b5ff18ee

Extract ProfilerType.
author shade
date Tue, 27 Aug 2013 14:05:34 +0400
parents 86d787cc5309
children ca8d6876f031
files jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerFactory.java jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerType.java jmh-core/src/main/java/org/openjdk/jmh/runner/BaseMicroBenchmarkHandler.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/BaseOptions.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/DefaultBuilder.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/Options.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java jmh-core/src/main/java/org/openjdk/jmh/runner/options/handlers/ProfilersOptionHandler.java
diffstat 8 files changed, 308 insertions(+), 285 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerFactory.java	Tue Aug 27 13:09:03 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerFactory.java	Tue Aug 27 14:05:34 2013 +0400
@@ -29,266 +29,8 @@
 
 public class ProfilerFactory {
 
-    public enum Profilers {
-
-        GC {
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new GCProfiler(label(), verbose);
-            }
-
-            @Override
-            public boolean isSupported() {
-                return GCProfiler.isSupported();
-            }
-
-            @Override
-            public String id() {
-                return "gc";
-            }
-
-            @Override
-            public String label() {
-                return "GC";
-            }
-
-            @Override
-            public String description() {
-                return "GC profiling via standard MBeans";
-            }
-        },
-        COMP {
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new CompilerProfiler(label(), verbose);
-            }
-
-            @Override
-            public boolean isSupported() {
-                return CompilerProfiler.isSupported();
-            }
-
-            @Override
-            public String id() {
-                return "comp";
-            }
-
-            @Override
-            public String label() {
-                return "JIT";
-            }
-
-            @Override
-            public String description() {
-                return "JIT compiler profiling via standard MBeans";
-            }
-        },
-        CL {
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new ClassloaderProfiler(label(), verbose);
-            }
-
-            @Override
-            public boolean isSupported() {
-                return ClassloaderProfiler.isSupported();
-            }
-
-            @Override
-            public String id() {
-                return "cl";
-            }
-
-            @Override
-            public String label() {
-                return "Class";
-            }
-
-            @Override
-            public String description() {
-                return "Classloader profiling via standard MBeans";
-            }
-        },
-        HS_RUNTIME {
-            @Override
-            public String id() {
-                return "hs_rt";
-            }
-
-            @Override
-            public String label() {
-                return "HS(RT)";
-            }
-
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new HotspotRuntimeProfiler(label(), verbose);
-            }
-
-            @Override
-            public boolean isSupported() {
-                return HotspotRuntimeProfiler.isSupported();
-            }
-
-            @Override
-            public String description() {
-                return "HotSpot (tm) runtime profiling via implementation-specific MBeans";
-            }
-        },
-        HS_CL {
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new HotspotClassloadingProfiler(label(), verbose);
-            }
-
-            @Override
-            public boolean isSupported() {
-                return HotspotClassloadingProfiler.isSupported();
-            }
-
-            @Override
-            public String id() {
-                return "hs_cl";
-            }
-
-            @Override
-            public String label() {
-                return "HS(Class)";
-            }
-
-            @Override
-            public String description() {
-                return "HotSpot (tm) classloader profiling via implementation-specific MBeans";
-            }
-        },
-        HS_COMP {
-            @Override
-            public String id() {
-                return "hs_comp";
-            }
-
-            @Override
-            public String label() {
-                return "HS(JIT)";
-            }
-
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new HotspotCompilationProfiler(label(), verbose);
-            }
-
-            @Override
-            public boolean isSupported() {
-                return HotspotCompilationProfiler.isSupported();
-            }
-
-            @Override
-            public String description() {
-                return "HotSpot (tm) JIT compiler profiling via implementation-specific MBeans";
-            }
-        },
-        HS_GC {
-            @Override
-            public String id() {
-                return "hs_gc";
-            }
-
-            @Override
-            public String label() {
-                return "HS(GC)";
-            }
-
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new HotspotMemoryProfiler(label(), verbose);
-            }
-
-            @Override
-            public boolean isSupported() {
-                return HotspotMemoryProfiler.isSupported();
-            }
-
-            @Override
-            public String description() {
-                return "HotSpot (tm) memory manager (GC) profiling via implementation-specific MBeans";
-            }
-        },
-        HS_THREAD {
-            @Override
-            public String id() {
-                return "hs_thr";
-            }
-
-            @Override
-            public String label() {
-                return "HS(THR)";
-            }
-
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new HotspotThreadProfiler(label(), verbose);
-            }
-
-            @Override
-            public boolean isSupported() {
-                return HotspotThreadProfiler.isSupported();
-            }
-
-            @Override
-            public String description() {
-                return "HotSpot (tm) threading subsystem via implementation-specific MBeans";
-            }
-        },
-        STACK_PROFILER {
-            @Override
-            public String id() {
-                return "stack";
-            }
-
-            @Override
-            public String label() {
-                return "Stack";
-            }
-
-            @Override
-            public Profiler createInstance(boolean verbose) {
-                return new StackProfiler(label());
-            }
-
-            @Override
-            public boolean isSupported() {
-                return true;
-            }
-
-            @Override
-            public String description() {
-                return "Simple and naive Java stack profiler";
-            }
-        };
-
-        public abstract Profiler createInstance(boolean verbose);
-
-        public abstract boolean isSupported();
-
-        /**
-         * @return id to reference the profiler
-         */
-        public abstract String id();
-
-        /**
-         * @return label to pretty-print profiler name
-         */
-        public abstract String label();
-
-        /**
-         * @return longer description for profiler
-         */
-        public abstract String description();
-    }
-
-
-    public static Profilers getProfiler(String id) {
-        for (Profilers p : Profilers.values()) {
+    public static ProfilerType getProfiler(String id) {
+        for (ProfilerType p : ProfilerType.values()) {
             if (p.id().toLowerCase().equals(id.toLowerCase())) {
                 return p;
             }
@@ -298,19 +40,19 @@
 
     public static List<String> getAvailableProfilers() {
         List<String> res = new ArrayList<String>();
-        for (Profilers p : Profilers.values()) {
+        for (ProfilerType p : ProfilerType.values()) {
             res.add(p.id().toLowerCase());
         }
         return res;
     }
 
     public static boolean isSupported(String id) {
-        Profilers profiler = getProfiler(id);
+        ProfilerType profiler = getProfiler(id);
         return (profiler != null) && profiler.isSupported();
     }
 
     public static String getDescription(String id) {
-        Profilers profiler = getProfiler(id);
+        ProfilerType profiler = getProfiler(id);
         if (profiler != null) {
             return profiler.description();
         }
@@ -319,7 +61,7 @@
 
     public static List<String> getSupportedProfilers() {
         List<String> res = new ArrayList<String>();
-        for (Profilers p : Profilers.values()) {
+        for (ProfilerType p : ProfilerType.values()) {
             if (p.isSupported()) {
                 res.add(p.id().toLowerCase());
             }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/ProfilerType.java	Tue Aug 27 14:05:34 2013 +0400
@@ -0,0 +1,282 @@
+/*
+ * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+package org.openjdk.jmh.profile;
+
+public enum ProfilerType {
+
+    GC {
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new GCProfiler(label(), verbose);
+        }
+
+        @Override
+        public boolean isSupported() {
+            return GCProfiler.isSupported();
+        }
+
+        @Override
+        public String id() {
+            return "gc";
+        }
+
+        @Override
+        public String label() {
+            return "GC";
+        }
+
+        @Override
+        public String description() {
+            return "GC profiling via standard MBeans";
+        }
+    },
+    COMP {
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new CompilerProfiler(label(), verbose);
+        }
+
+        @Override
+        public boolean isSupported() {
+            return CompilerProfiler.isSupported();
+        }
+
+        @Override
+        public String id() {
+            return "comp";
+        }
+
+        @Override
+        public String label() {
+            return "JIT";
+        }
+
+        @Override
+        public String description() {
+            return "JIT compiler profiling via standard MBeans";
+        }
+    },
+    CL {
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new ClassloaderProfiler(label(), verbose);
+        }
+
+        @Override
+        public boolean isSupported() {
+            return ClassloaderProfiler.isSupported();
+        }
+
+        @Override
+        public String id() {
+            return "cl";
+        }
+
+        @Override
+        public String label() {
+            return "Class";
+        }
+
+        @Override
+        public String description() {
+            return "Classloader profiling via standard MBeans";
+        }
+    },
+    HS_RUNTIME {
+        @Override
+        public String id() {
+            return "hs_rt";
+        }
+
+        @Override
+        public String label() {
+            return "HS(RT)";
+        }
+
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new HotspotRuntimeProfiler(label(), verbose);
+        }
+
+        @Override
+        public boolean isSupported() {
+            return HotspotRuntimeProfiler.isSupported();
+        }
+
+        @Override
+        public String description() {
+            return "HotSpot (tm) runtime profiling via implementation-specific MBeans";
+        }
+    },
+    HS_CL {
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new HotspotClassloadingProfiler(label(), verbose);
+        }
+
+        @Override
+        public boolean isSupported() {
+            return HotspotClassloadingProfiler.isSupported();
+        }
+
+        @Override
+        public String id() {
+            return "hs_cl";
+        }
+
+        @Override
+        public String label() {
+            return "HS(Class)";
+        }
+
+        @Override
+        public String description() {
+            return "HotSpot (tm) classloader profiling via implementation-specific MBeans";
+        }
+    },
+    HS_COMP {
+        @Override
+        public String id() {
+            return "hs_comp";
+        }
+
+        @Override
+        public String label() {
+            return "HS(JIT)";
+        }
+
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new HotspotCompilationProfiler(label(), verbose);
+        }
+
+        @Override
+        public boolean isSupported() {
+            return HotspotCompilationProfiler.isSupported();
+        }
+
+        @Override
+        public String description() {
+            return "HotSpot (tm) JIT compiler profiling via implementation-specific MBeans";
+        }
+    },
+    HS_GC {
+        @Override
+        public String id() {
+            return "hs_gc";
+        }
+
+        @Override
+        public String label() {
+            return "HS(GC)";
+        }
+
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new HotspotMemoryProfiler(label(), verbose);
+        }
+
+        @Override
+        public boolean isSupported() {
+            return HotspotMemoryProfiler.isSupported();
+        }
+
+        @Override
+        public String description() {
+            return "HotSpot (tm) memory manager (GC) profiling via implementation-specific MBeans";
+        }
+    },
+    HS_THREAD {
+        @Override
+        public String id() {
+            return "hs_thr";
+        }
+
+        @Override
+        public String label() {
+            return "HS(THR)";
+        }
+
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new HotspotThreadProfiler(label(), verbose);
+        }
+
+        @Override
+        public boolean isSupported() {
+            return HotspotThreadProfiler.isSupported();
+        }
+
+        @Override
+        public String description() {
+            return "HotSpot (tm) threading subsystem via implementation-specific MBeans";
+        }
+    },
+    STACK_PROFILER {
+        @Override
+        public String id() {
+            return "stack";
+        }
+
+        @Override
+        public String label() {
+            return "Stack";
+        }
+
+        @Override
+        public Profiler createInstance(boolean verbose) {
+            return new StackProfiler(label());
+        }
+
+        @Override
+        public boolean isSupported() {
+            return true;
+        }
+
+        @Override
+        public String description() {
+            return "Simple and naive Java stack profiler";
+        }
+    };
+
+    public abstract Profiler createInstance(boolean verbose);
+
+    public abstract boolean isSupported();
+
+    /**
+     * @return id to reference the profiler
+     */
+    public abstract String id();
+
+    /**
+     * @return label to pretty-print profiler name
+     */
+    public abstract String label();
+
+    /**
+     * @return longer description for profiler
+     */
+    public abstract String description();
+}
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseMicroBenchmarkHandler.java	Tue Aug 27 13:09:03 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/BaseMicroBenchmarkHandler.java	Tue Aug 27 14:05:34 2013 +0400
@@ -27,7 +27,7 @@
 import org.openjdk.jmh.logic.results.IterationData;
 import org.openjdk.jmh.output.format.OutputFormat;
 import org.openjdk.jmh.profile.Profiler;
-import org.openjdk.jmh.profile.ProfilerFactory;
+import org.openjdk.jmh.profile.ProfilerType;
 import org.openjdk.jmh.runner.options.Options;
 import org.openjdk.jmh.runner.parameters.MicroBenchmarkParameters;
 
@@ -81,7 +81,7 @@
     private static List<Profiler> createProfilers(Options options) {
         List<Profiler> list = new ArrayList<Profiler>();
         // register the profilers
-        for (ProfilerFactory.Profilers prof : options.getProfilers()) {
+        for (ProfilerType prof : options.getProfilers()) {
             list.add(prof.createInstance(options.isVerbose()));
         }
         return list;
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/BaseOptions.java	Tue Aug 27 13:09:03 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/BaseOptions.java	Tue Aug 27 14:05:34 2013 +0400
@@ -26,11 +26,10 @@
 
 import org.kohsuke.args4j.Option;
 import org.openjdk.jmh.annotations.Mode;
-import org.openjdk.jmh.profile.ProfilerFactory;
+import org.openjdk.jmh.profile.ProfilerType;
 import org.openjdk.jmh.runner.options.handlers.BenchmarkModeTypeOptionHandler;
 import org.openjdk.jmh.runner.options.handlers.BooleanOptionHandler;
 import org.openjdk.jmh.runner.options.handlers.ProfilersOptionHandler;
-import org.openjdk.jmh.runner.options.handlers.ThreadCountsOptionHandler;
 import org.openjdk.jmh.runner.options.handlers.ThreadsOptionHandler;
 import org.openjdk.jmh.runner.options.handlers.TimeUnitOptionHandler;
 import org.openjdk.jmh.runner.options.handlers.TimeValueOptionHandler;
@@ -106,7 +105,7 @@
     protected boolean failOnError = false;
 
     @Option(name = "-prof", aliases = {"--useprofiler"}, multiValued = false, usage = "Use profilers for collecting additional info, use --listprofilers to list available profilers", handler = ProfilersOptionHandler.class)
-    protected Set<ProfilerFactory.Profilers> profilers = EnumSet.noneOf(ProfilerFactory.Profilers.class);
+    protected Set<ProfilerType> profilers = EnumSet.noneOf(ProfilerType.class);
 
     @Option(name = "-tu", aliases = {"--timeunit"}, usage = "Output time unit. Available values: m, s, ms, us, ns", handler = TimeUnitOptionHandler.class)
     protected TimeUnit timeUnit = null;
@@ -255,8 +254,8 @@
                     if (isTail) {
                         sb.append(',');
                     }
-                    if( o instanceof ProfilerFactory.Profilers) {
-                        sb.append(((ProfilerFactory.Profilers) o).id());
+                    if( o instanceof ProfilerType) {
+                        sb.append(((ProfilerType) o).id());
                     } else {
                         sb.append(o);
                     }
@@ -424,7 +423,7 @@
      * @return the value
      */
     @Override
-    public Set<ProfilerFactory.Profilers> getProfilers() {
+    public Set<ProfilerType> getProfilers() {
         return profilers;
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/DefaultBuilder.java	Tue Aug 27 13:09:03 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/DefaultBuilder.java	Tue Aug 27 14:05:34 2013 +0400
@@ -26,7 +26,7 @@
 
 import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.output.OutputFormatType;
-import org.openjdk.jmh.profile.ProfilerFactory;
+import org.openjdk.jmh.profile.ProfilerType;
 import org.openjdk.jmh.runner.parameters.TimeValue;
 
 import java.util.ArrayList;
@@ -149,16 +149,16 @@
 
     // ---------------------------------------------------------------------------
 
-    private EnumSet<ProfilerFactory.Profilers> profilers = EnumSet.noneOf(ProfilerFactory.Profilers.class);
+    private EnumSet<ProfilerType> profilers = EnumSet.noneOf(ProfilerType.class);
 
     @Override
-    public OptionsBuilder addProfiler(ProfilerFactory.Profilers prof) {
+    public OptionsBuilder addProfiler(ProfilerType prof) {
         this.profilers.add(prof);
         return this;
     }
 
     @Override
-    public Set<ProfilerFactory.Profilers> getProfilers() {
+    public Set<ProfilerType> getProfilers() {
         return profilers;
     }
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/Options.java	Tue Aug 27 13:09:03 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/Options.java	Tue Aug 27 14:05:34 2013 +0400
@@ -26,7 +26,7 @@
 
 import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.output.OutputFormatType;
-import org.openjdk.jmh.profile.ProfilerFactory;
+import org.openjdk.jmh.profile.ProfilerType;
 import org.openjdk.jmh.runner.parameters.TimeValue;
 
 import java.util.Collection;
@@ -75,10 +75,9 @@
 
     /**
      * Profilers to use for the run.
-     * TODO: Rework Profilers enum
      * @return profilers to use; empty set if no profilers are required
      */
-    Collection<ProfilerFactory.Profilers> getProfilers();
+    Collection<ProfilerType> getProfilers();
 
     /**
      * Should be extra verbose?
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java	Tue Aug 27 13:09:03 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/OptionsBuilder.java	Tue Aug 27 14:05:34 2013 +0400
@@ -26,7 +26,7 @@
 
 import org.openjdk.jmh.annotations.Mode;
 import org.openjdk.jmh.output.OutputFormatType;
-import org.openjdk.jmh.profile.ProfilerFactory;
+import org.openjdk.jmh.profile.ProfilerType;
 import org.openjdk.jmh.runner.parameters.TimeValue;
 
 import java.util.concurrent.TimeUnit;
@@ -46,7 +46,7 @@
 
     OptionsBuilder shouldList(boolean value);
 
-    OptionsBuilder addProfiler(ProfilerFactory.Profilers prof);
+    OptionsBuilder addProfiler(ProfilerType prof);
 
     OptionsBuilder shouldBeVerbose(boolean value);
 
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/options/handlers/ProfilersOptionHandler.java	Tue Aug 27 13:09:03 2013 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/options/handlers/ProfilersOptionHandler.java	Tue Aug 27 14:05:34 2013 +0400
@@ -31,6 +31,7 @@
 import org.kohsuke.args4j.spi.Parameters;
 import org.kohsuke.args4j.spi.Setter;
 import org.openjdk.jmh.profile.ProfilerFactory;
+import org.openjdk.jmh.profile.ProfilerType;
 
 import java.util.EnumSet;
 
@@ -39,7 +40,7 @@
  *
  * @author sergey.kuksenko@oracle.com
  */
-public class ProfilersOptionHandler extends OptionHandler<EnumSet<ProfilerFactory.Profilers>> {
+public class ProfilersOptionHandler extends OptionHandler<EnumSet<ProfilerType>> {
 
     /**
      * Constructor
@@ -48,7 +49,7 @@
      * @param option Run-time copy of the Option
      * @param setter Setter to feed back the value
      */
-    public ProfilersOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super EnumSet<ProfilerFactory.Profilers>> setter) {
+    public ProfilersOptionHandler(CmdLineParser parser, OptionDef option, Setter<? super EnumSet<ProfilerType>> setter) {
         super(parser, option, setter);
     }
 
@@ -56,9 +57,9 @@
     public int parseArguments(Parameters params) throws CmdLineException {
         String param = params.getParameter(0);
         String[] possibleProfilers = param.split(",");
-        EnumSet<ProfilerFactory.Profilers> profSet = EnumSet.noneOf(ProfilerFactory.Profilers.class);
+        EnumSet<ProfilerType> profSet = EnumSet.noneOf(ProfilerType.class);
         for (String s : possibleProfilers) {
-            ProfilerFactory.Profilers prof = ProfilerFactory.getProfiler(s);
+            ProfilerType prof = ProfilerFactory.getProfiler(s);
             if (prof == null) {
                 throw new CmdLineException(owner, param + "; unknown profiler: '" + s + '\'');
             }