changeset 858:db0ebff29146

profilers: perfasm, name residuals in native code.
author shade
date Fri, 27 Jun 2014 15:02:12 +0400
parents 5254c21f2284
children a03482339392
files jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java
diffstat 1 files changed, 41 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Fri Jun 27 14:38:42 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java	Fri Jun 27 15:02:12 2014 +0400
@@ -253,7 +253,7 @@
 
         double skipSec = 1.0 * delayNs / TimeUnit.SECONDS.toNanos(1);
 
-        Map<String, Multiset<Long>> events = readEvents(skipSec);
+        PerfEvents events = readEvents(skipSec);
 
         if (!events.isEmpty()) {
             pw.printf("Perf output processed (skipped %.3f seconds):%n", skipSec);
@@ -428,7 +428,7 @@
                         pw.printf("%9s", "");
                     }
                 }
-                pw.printf("[0x%x]%n", addr);
+                pw.printf("[0x%x] %s %n", addr, events.methods.get(addr));
             }
         }
 
@@ -530,13 +530,10 @@
         pw.println();
     }
 
-    Collection<Region> makeRegions(Assembly asms, Map<String, Multiset<Long>> events) {
+    Collection<Region> makeRegions(Assembly asms, PerfEvents events) {
         SortedSet<Region> regions = new TreeSet<Region>(Region.BEGIN_COMPARATOR);
 
-        SortedSet<Long> addrs = new TreeSet<Long>();
-        for (Map.Entry<String, Multiset<Long>> e : events.entrySet()) {
-            addrs.addAll(e.getValue().keys());
-        }
+        SortedSet<Long> addrs = events.getAllAddresses();
 
         Set<Long> eventfulAddrs = new HashSet<Long>();
         Long lastBegin = null;
@@ -604,6 +601,36 @@
         }
     }
 
+    static class PerfEvents {
+        final Map<String, Multiset<Long>> events;
+        final Map<Long, String> methods;
+
+        PerfEvents(Map<String, Multiset<Long>> events, Map<Long, String> methods) {
+            this.events = events;
+            this.methods = methods;
+        }
+
+        public PerfEvents() {
+            this(Collections.<String, Multiset<Long>>emptyMap(), Collections.<Long, String>emptyMap());
+        }
+
+        public boolean isEmpty() {
+            return events.isEmpty();
+        }
+
+        public Multiset<Long> get(String event) {
+            return events.get(event);
+        }
+
+        public SortedSet<Long> getAllAddresses() {
+            SortedSet<Long> addrs = new TreeSet<Long>();
+            for (Multiset<Long> e : events.values()) {
+                addrs.addAll(e.keys());
+            }
+            return addrs;
+        }
+    }
+
     static class Assembly {
         List<ASMLine> lines;
         SortedMap<Long, Integer> addressMap;
@@ -713,11 +740,12 @@
         }
     }
 
-    Map<String, Multiset<Long>> readEvents(double skipSec) {
+    PerfEvents readEvents(double skipSec) {
         try {
             FileInputStream fis = new FileInputStream(perfParsedData);
             BufferedReader reader = new BufferedReader(new InputStreamReader(fis));
 
+            Map<Long, String> methods = new HashMap<Long, String>();
             Map<String, Multiset<Long>> events = new LinkedHashMap<String, Multiset<Long>>();
             for (String evName : EVENTS) {
                 events.put(evName, new TreeMultiset<Long>());
@@ -751,15 +779,16 @@
                     try {
                         Long element = Long.valueOf(elements[4], 16);
                         evs.add(element);
+                        methods.put(element, elements[5]); // TODO: Deduplicate method names
                     } catch (NumberFormatException e) {
                         // TODO: Kernel addresses like "ffffffff810c1b00" overflow signed long
                     }
                 }
             }
 
-            return events;
+            return new PerfEvents(events, methods);
         } catch (IOException e) {
-            return Collections.emptyMap();
+            return new PerfEvents();
         }
     }
 
@@ -785,7 +814,7 @@
             }
         };
 
-        static Comparator<Region> getSortedEventComparator(final Map<String, Multiset<Long>> events, final String event) {
+        static Comparator<Region> getSortedEventComparator(final PerfEvents events, final String event) {
             return new Comparator<Region>() {
                 @Override
                 public int compare(Region o1, Region o2) {
@@ -810,7 +839,7 @@
             this.eventCountCache = new HashMap<String, Long>();
         }
 
-        long getEventCount(Map<String, Multiset<Long>> events, String event) {
+        long getEventCount(PerfEvents events, String event) {
             if (!eventCountCache.containsKey(event)) {
                 Multiset<Long> evs = events.get(event);
                 long count = 0;