changeset 1388:49b0a822bc1f

7901842: JMH perf* profilers and ocperf.py pmu-tools: accept JMH_PERF
author shade
date Mon, 05 Dec 2016 20:50:17 +0100
parents 1e15cc553559
children d6f22497f8b4
files 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/PerfSupport.java
diffstat 4 files changed, 48 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Mon Dec 05 20:40:04 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Mon Dec 05 20:50:17 2016 +0100
@@ -46,7 +46,7 @@
     public LinuxPerfAsmProfiler(String initLine) throws ProfilerException {
         super(initLine, "cycles", "instructions");
 
-        Collection<String> failMsg = Utils.tryWith("perf", "stat", "--log-fd", "2", "echo", "1");
+        Collection<String> failMsg = Utils.tryWith(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "echo", "1");
         if (!failMsg.isEmpty()) {
             throw new ProfilerException(failMsg.toString());
         }
@@ -67,7 +67,7 @@
 
     @Override
     public Collection<String> addJVMInvokeOptions(BenchmarkParams params) {
-        return Arrays.asList("perf", "record", "--freq", String.valueOf(sampleFrequency), "--event", Utils.join(events, ","), "--output", perfBinData);
+        return Arrays.asList(PerfSupport.PERF_EXEC, "record", "--freq", String.valueOf(sampleFrequency), "--event", Utils.join(events, ","), "--output", perfBinData);
     }
 
     @Override
@@ -78,7 +78,7 @@
     @Override
     protected void parseEvents() {
         try (FileOutputStream fos = new FileOutputStream(perfParsedData)) {
-            ProcessBuilder pb = new ProcessBuilder("perf", "script", "--fields", "time,event,ip,sym,dso", "--input", perfBinData);
+            ProcessBuilder pb = new ProcessBuilder(PerfSupport.PERF_EXEC, "script", "--fields", "time,event,ip,sym,dso", "--input", perfBinData);
             Process p = pb.start();
 
             // drain streams, else we might lock up
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfNormProfiler.java	Mon Dec 05 20:40:04 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfNormProfiler.java	Mon Dec 05 20:50:17 2016 +0100
@@ -107,12 +107,12 @@
             throw new ProfilerException(e.getMessage());
         }
 
-        Collection<String> msgs = Utils.tryWith("perf", "stat", "--log-fd", "2", "--field-separator", ",", "echo", "1");
+        Collection<String> msgs = Utils.tryWith(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--field-separator", ",", "echo", "1");
         if (!msgs.isEmpty()) {
             throw new ProfilerException(msgs.toString());
         }
 
-        Collection<String> incremental = Utils.tryWith("perf", "stat", "--log-fd", "2", "--field-separator", ",", "--interval-print", String.valueOf(incrementInterval), "echo", "1");
+        Collection<String> incremental = Utils.tryWith(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--field-separator", ",", "--interval-print", String.valueOf(incrementInterval), "echo", "1");
         isIncrementable = incremental.isEmpty();
 
         if (userEvents != null) {
@@ -124,7 +124,7 @@
 
         if (supportedEvents.isEmpty()) {
             for (String ev : interestingEvents) {
-                Collection<String> res = Utils.tryWith("perf", "stat", "--log-fd", "2", "--field-separator", ",", "--event", "cycles,instructions," + ev, "echo", "1");
+                Collection<String> res = Utils.tryWith(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--field-separator", ",", "--event", "cycles,instructions," + ev, "echo", "1");
                 if (res.isEmpty()) {
                     supportedEvents.add(ev);
                 }
@@ -136,9 +136,9 @@
     public Collection<String> addJVMInvokeOptions(BenchmarkParams params) {
         List<String> cmd = new ArrayList<>();
         if (useDefaultStats) {
-            cmd.addAll(Arrays.asList("perf", "stat", "--log-fd", "2", "--field-separator", ",", "--detailed", "--detailed", "--detailed"));
+            cmd.addAll(Arrays.asList(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--field-separator", ",", "--detailed", "--detailed", "--detailed"));
         } else {
-            cmd.addAll(Arrays.asList("perf", "stat", "--log-fd", "2", "--field-separator", ",", "--event", Utils.join(supportedEvents, ",")));
+            cmd.addAll(Arrays.asList(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--field-separator", ",", "--event", Utils.join(supportedEvents, ",")));
         }
         if (isIncrementable) {
             cmd.addAll(Arrays.asList("-I", String.valueOf(incrementInterval)));
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java	Mon Dec 05 20:40:04 2016 +0100
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfProfiler.java	Mon Dec 05 20:50:17 2016 +0100
@@ -64,12 +64,12 @@
             throw new ProfilerException(e.getMessage());
         }
 
-        Collection<String> msgs = Utils.tryWith("perf", "stat", "--log-fd", "2", "echo", "1");
+        Collection<String> msgs = Utils.tryWith(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "echo", "1");
         if (!msgs.isEmpty()) {
             throw new ProfilerException(msgs.toString());
         }
 
-        Collection<String> delay = Utils.tryWith("perf", "stat", "--log-fd", "2", "--delay", "1", "echo", "1");
+        Collection<String> delay = Utils.tryWith(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--delay", "1", "echo", "1");
         isDelayed = delay.isEmpty();
     }
 
@@ -85,9 +85,9 @@
         }
 
         if (isDelayed) {
-            return Arrays.asList("perf", "stat", "--log-fd", "2", "--detailed", "--detailed", "--detailed", "--delay", String.valueOf(delay));
+            return Arrays.asList(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--detailed", "--detailed", "--detailed", "--delay", String.valueOf(delay));
         } else {
-            return Arrays.asList("perf", "stat", "--log-fd", "2", "--detailed", "--detailed", "--detailed");
+            return Arrays.asList(PerfSupport.PERF_EXEC, "stat", "--log-fd", "2", "--detailed", "--detailed", "--detailed");
         }
     }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/PerfSupport.java	Mon Dec 05 20:50:17 2016 +0100
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2016, Red Hat Inc.
+ * 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;
+
+class PerfSupport {
+
+    static final String PERF_EXEC;
+
+    static {
+        String perf = System.getenv("JMH_PERF");
+        PERF_EXEC = (perf == null) ? "perf" : perf;
+    }
+
+}