Adding heap dump capability
Dieser Commit ist enthalten in:
Ursprung
42610701a0
Commit
45c50a8838
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren