changeset 1458:66fb723292d4

7902329: perf profiler should accept events Contributed-by: Eric Caspole <eric.caspole@oracle.com>
author shade
date Wed, 26 Sep 2018 16:57:35 +0200
parents 3769055ad883
children a180846b4cb2
files jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java
diffstat 1 files changed, 18 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java	Fri May 04 17:58:58 2018 +0200
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java	Wed Sep 26 16:57:35 2018 +0200
@@ -37,8 +37,10 @@
 import java.text.NumberFormat;
 import java.text.ParseException;
 import java.util.Arrays;
+import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.List;
 import java.util.concurrent.TimeUnit;
 import java.util.regex.Matcher;
 import java.util.regex.Pattern;
@@ -47,6 +49,7 @@
 
     private final boolean isDelayed;
     private final int delayMs;
+    private final List<String> events;
 
     public LinuxPerfProfiler(String initLine) throws ProfilerException {
         OptionParser parser = new OptionParser();
@@ -56,9 +59,14 @@
                 "Delay collection for a given time, in milliseconds; -1 to detect automatically.")
                 .withRequiredArg().ofType(Integer.class).describedAs("ms").defaultsTo(-1);
 
+        OptionSpec<String> optEvents = parser.accepts("events",
+                        "Events to gather.")
+                .withRequiredArg().ofType(String.class).withValuesSeparatedBy(",").describedAs("event");
+
         OptionSet set = ProfilerUtils.parseInitLine(initLine, parser);
 
         try {
+            events = set.valuesOf(optEvents);
             delayMs = set.valueOf(optDelay);
         } catch (OptionException e) {
             throw new ProfilerException(e.getMessage());
@@ -84,11 +92,18 @@
             delay = delayMs;
         }
 
+        List<String> invokeOptions = new ArrayList<>(Arrays.asList(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--detailed", "--detailed", "--detailed"));
+
         if (isDelayed) {
-            return Arrays.asList(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--detailed", "--detailed", "--detailed", "--delay", String.valueOf(delay));
-        } else {
-            return Arrays.asList(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--detailed", "--detailed", "--detailed");
+            invokeOptions.add("--delay");
+            invokeOptions.add(String.valueOf(delay));
         }
+        if (!events.isEmpty()) {
+            invokeOptions.add("-e");
+            invokeOptions.add(Utils.join(events, ","));
+        }
+
+        return invokeOptions;
     }
 
     @Override