perfasm and the <kernel> region

Aleksey Shipilev aleksey.shipilev at oracle.com
Thu Apr 23 13:07:44 UTC 2015


On 04/23/2015 03:39 PM, Chris Vest wrote:
> I have a benchmark where perfasm reports that about 50% of the time
> is spent in the kernel. It’s an IO heavy benchmark, so it sounds
> reasonable. However, some locks are also being juggled, which may
> cause threads to be blocked.
> 
> I’m assuming the time spent in the system calls for the IO and the
> blocking/unblocking of threads are both included in the <kernel>
> region. Would it be possible to break them out? I tried strace’ing
> the benchmark, but the overhead of strace is so big that it changes
> the behavioural patterns of the code, ruining the measurement.

"perfasm" processes whatever events perf is providing back to us. At
this point, we attribute all events from the negative addresses as the
<kernel> region. One can massage perfasm code to parse those properly as
well, like this:

diff -r 172094a4b2c4
jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java
---
a/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java
Thu Apr 23 14:40:38 2015 +0300
+++
b/jmh-core/src/main/java/org/openjdk/jmh/profile/LinuxPerfAsmProfiler.java
Thu Apr 23 16:04:02 2015 +0300
@@ -36,6 +36,7 @@
 import java.io.FileOutputStream;
 import java.io.FileReader;
 import java.io.IOException;
+import java.math.BigInteger;
 import java.util.Arrays;
 import java.util.Collection;
 import java.util.HashMap;
@@ -185,19 +186,23 @@
                     continue;
                 }

+                Long addr;
                 try {
-                    Long addr = Long.valueOf(strAddr, 16);
-                    evs.add(addr);
-                    methods.put(addr, dedup.dedup(symbol));
-                    libs.put(addr, dedup.dedup(lib));
+                    addr = Long.valueOf(strAddr, 16);
                 } catch (NumberFormatException e) {
-                    // kernel addresses like "ffffffff810c1b00"
overflow signed long,
-                    // record them as dummy address
-                    evs.add(0L);
+                    try {
+                        addr = new BigInteger(strAddr, 16).longValue();
+                    } catch (NumberFormatException e1) {
+                        addr = 0L;
+                    }
                 }
+
+                evs.add(addr);
+                methods.put(addr, dedup.dedup(symbol));
+                libs.put(addr, dedup.dedup(lib));
             }

-            methods.put(0L, "<kernel>");
+            methods.put(0L, "<unresolved>");

             return new PerfEvents(tracedEvents, events, methods, libs);
         } catch (IOException e) {

On my dev laptop, it prints:

....[Hottest Methods (after inlining)].................................
 31.28%   28.79%  [unknown] ([kernel.kallsyms])


...but this is because my kernel symbols mapping is all FUBAR-ed. Can
you try on yours? Should probably require "echo -1 | sudo tee
/proc/sys/kernel/perf_event_paranoid".

-Aleksey.



More information about the jmh-dev mailing list