12
0

Adding heap dump capability

Dieser Commit ist enthalten in:
Lixfel 2022-03-30 19:01:35 +02:00
Ursprung 42610701a0
Commit 45c50a8838
2 geänderte Dateien mit 25 neuen und 7 gelöschten Zeilen

Datei anzeigen

@ -1,6 +1,12 @@
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() {}
@ -24,6 +30,13 @@ public class Agent {
sampler.stop();
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);
}
break;
}
}
}

Datei anzeigen

@ -28,10 +28,13 @@ public class Main {
System.out.println(vmd.id() + " " + vmd.displayName());
}
}
}else if(args.length == 1) {
try {
VirtualMachine vm = VirtualMachine.attach(args[0]);
return;
}
try {
VirtualMachine vm = VirtualMachine.attach(args[0]);
if(args.length == 1 || !"heap".equals(args[1])) {
vm.loadAgent(jarPath.getAbsolutePath(), "start");
System.out.println("Press keyboard to stop sampling...");
@ -39,13 +42,15 @@ public class Main {
vm.loadAgent(jarPath.getAbsolutePath(), "stop");
vm.detach();
new ProcessBuilder("xdot", "samples.dot").directory(jarPath.getParentFile()).start();
} catch (AttachNotSupportedException | IOException | AgentLoadException | AgentInitializationException e) {
e.printStackTrace();
} else {
vm.loadAgent(jarPath.getAbsolutePath(), "heap");
}
vm.detach();
} catch (AttachNotSupportedException | IOException | AgentLoadException | AgentInitializationException e) {
e.printStackTrace();
}
}
}