use of org.gridkit.jvmtool.gcmon.SimpleGcEventEncoder in project jvm-tools by aragozin.
the class CaptureCheck method capture.
@Test
public void capture() throws FileNotFoundException, IOException {
File dump = new File(taget);
if (dump.getParentFile() != null) {
dump.getParentFile().mkdirs();
}
UniversalEventWriter writer = ThreadEventCodec.createEventWriter(new FileOutputStream(dump));
MyEventWriter twriter = TypedEventWriterProxy.decorate(writer).pass(ThreadSnapshotEvent.class).pass(GarbageCollectionEvent.class).facade(MyEventWriter.class);
MBeanServerConnection conn = AttachManager.getJmxConnection(PID);
GcEventSubscriber subscriber = new GcEventSubscriber(conn, new SimpleGcEventEncoder(twriter));
if (!subscriber.subscribe()) {
// polling fallback
subscriber.schedule(500);
}
ThreadDumpSampler tdumper = new ThreadDumpSampler();
ThreadMXBean threadMXBean = ThreadMXBeanEx.BeanHelper.connectThreadMXBean(conn);
if (threadMXBean.isThreadContentionMonitoringSupported()) {
threadMXBean.setThreadContentionMonitoringEnabled(true);
}
tdumper.connect(threadMXBean);
long deadline = System.currentTimeMillis() + captureTime;
ThreadEventAdapter threadWriter = new ThreadEventAdapter(twriter);
while (System.currentTimeMillis() < deadline) {
tdumper.collect(threadWriter);
}
twriter.close();
System.out.println("Dump complete [" + dump.getPath() + "] " + dump.length() + " bytes");
int tc = 0;
int ntc = 0;
EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream(dump));
for (Event e : reader) {
if (e instanceof ThreadSnapshotEvent) {
++tc;
} else {
++ntc;
}
}
System.out.println("Thread events: " + tc + " Non thread events: " + ntc);
}
Aggregations