13
0

JVM independence, no line numbers anymore

Dieser Commit ist enthalten in:
Lixfel 2022-04-23 20:37:03 +02:00
Ursprung 45c50a8838
Commit 45349e18ed
3 geänderte Dateien mit 46 neuen und 21 gelöschten Zeilen

Datei anzeigen

@ -1,12 +1,6 @@
package de.steamwar;
import com.ibm.jvm.Dump;
import com.ibm.jvm.InvalidDumpOptionException;
import java.io.File;
import java.lang.instrument.Instrumentation;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Agent {
private Agent() {}
@ -31,11 +25,7 @@ public class Agent {
sampler = null;
break;
case "heap":
try {
Dump.heapDumpToFile(new File(Main.jarPath.getParentFile(), "heap.phd").getPath());
} catch (InvalidDumpOptionException e) {
Logger.getGlobal().log(Level.WARNING, "Could not perform heap dump", e);
}
OpenJ9.heapdump();
break;
}
}

Datei anzeigen

@ -0,0 +1,20 @@
package de.steamwar;
import com.ibm.jvm.Dump;
import com.ibm.jvm.InvalidDumpOptionException;
import java.io.File;
import java.util.logging.Level;
import java.util.logging.Logger;
public class OpenJ9 {
private OpenJ9() {}
public static void heapdump() {
try {
Dump.heapDumpToFile(new File(Main.jarPath.getParentFile(), "heap.phd").getPath());
} catch (InvalidDumpOptionException e) {
Logger.getGlobal().log(Level.WARNING, "Could not perform heap dump", e);
}
}
}

Datei anzeigen

@ -10,18 +10,23 @@ import java.util.concurrent.locks.LockSupport;
public class Sampler {
public static final long SAMPLING_SPEED = 1000000;
public static final double FILTER = 0.005;
public static final double FILTER = 0.01;
private static final Set<String> waitingMethods = new HashSet<>();
static {
waitingMethods.add("io.netty.channel.epoll.Native.epollWait:-2");
waitingMethods.add("io.netty.channel.epoll.Native.epollWait0:-2");
waitingMethods.add("org.bukkit.craftbukkit.libs.jline.internal.NonBlockingInputStream.read:248");
waitingMethods.add("com.ibm.lang.management.internal.MemoryNotificationThread.processNotificationLoop:-2");
waitingMethods.add("net.minecrell.terminalconsole.SimpleTerminalConsole.readCommands:180");
waitingMethods.add("sun.nio.ch.SocketDispatcher.read0:-2");
waitingMethods.add("openj9.internal.tools.attach.target.IPC.waitSemaphore:-2");
waitingMethods.add("sun.nio.ch.Net.poll:-2");
waitingMethods.add("io.netty.channel.epoll.Native.epollWait");
waitingMethods.add("io.netty.channel.epoll.Native.epollWait0");
waitingMethods.add("org.bukkit.craftbukkit.libs.jline.internal.NonBlockingInputStream.read");
waitingMethods.add("com.ibm.lang.management.internal.MemoryNotificationThread.processNotificationLoop");
waitingMethods.add("net.minecrell.terminalconsole.SimpleTerminalConsole.readCommands");
waitingMethods.add("sun.nio.ch.SocketDispatcher.read0");
waitingMethods.add("openj9.internal.tools.attach.target.IPC.waitSemaphore");
waitingMethods.add("sun.nio.ch.Net.poll");
waitingMethods.add("java.lang.ProcessHandleImpl.waitForProcessExit0");
waitingMethods.add("java.io.FileInputStream.readBytes");
waitingMethods.add("java.util.concurrent.locks.LockSupport.parkNanos");
waitingMethods.add("sun.awt.X11.XToolkit.waitForEvents");
waitingMethods.add("java.lang.ref.Reference.waitForReferencePendingList");
}
private static final List<String> omittedMethods = new ArrayList<>();
@ -29,6 +34,16 @@ public class Sampler {
omittedMethods.add("java.lang.reflect.Method.invoke");
omittedMethods.add("java.lang.Thread.run");
omittedMethods.add("jdk.internal");
omittedMethods.add("java.util.stream");
omittedMethods.add("java.util.Iterator.forEachRemaining");
omittedMethods.add("java.lang.Iterable.forEach");
omittedMethods.add("java.util.Spliterators");
omittedMethods.add("java.util.ArrayList$ArrayListSpliterator");
omittedMethods.add("java.util.AbstractList$RandomAccessSpliterator");
omittedMethods.add("java.util.ArrayList.forEach");
omittedMethods.add("java.util.Map.forEach");
omittedMethods.add("java.util.concurrent");
}
private final Map<String, Trace> traces = new HashMap<>();
@ -109,7 +124,7 @@ public class Sampler {
String[] ids = new String[stack.length];
for(int i = 0; i < stack.length; i++) {
StackTraceElement ste = stack[i];
String id = ste.getClassName() + "." + ste.getMethodName() + ":" + ste.getLineNumber();
String id = ste.getClassName() + "." + ste.getMethodName();
ids[i] = id;
if (waitingMethods.contains(id))