use of org.gridkit.jvmtool.event.UniversalEventWriter in project jvm-tools by aragozin.
the class ThreadEventReaderTest method read_dump_v1_rewrite_and_compare.
@Test
public void read_dump_v1_rewrite_and_compare() throws FileNotFoundException, IOException {
String sourceFile = "src/test/resources/dump_v1.std";
File file = new File("target/tmp/" + testName.getMethodName() + "-" + System.currentTimeMillis() + ".std");
file.getParentFile().mkdirs();
file.delete();
FileOutputStream fow = new FileOutputStream(file);
UniversalEventWriter writer = ThreadEventCodec.createEventWriter(fow);
EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream(sourceFile));
copyAllTraces(reader, writer);
writer.close();
System.out.println("New file " + file.length() + " bytes (original " + new File(sourceFile).length() + " bytes)");
reader = ThreadEventCodec.createEventReader(new FileInputStream(file));
EventReader<Event> origReader = ThreadEventCodec.createEventReader(new FileInputStream("src/test/resources/dump_v1.std"));
assertThat((Iterable<Event>) reader).is(exactlyAs(origReader));
}
use of org.gridkit.jvmtool.event.UniversalEventWriter 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);
}
use of org.gridkit.jvmtool.event.UniversalEventWriter in project jvm-tools by aragozin.
the class EventReadWriteTest method writeReadEvents.
private EventReader<Event> writeReadEvents(Event... events) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
UniversalEventWriter writer = ThreadEventCodec.createEventWriter(bos);
for (Event e : events) {
writer.store(e);
}
writer.close();
byte[] data = bos.toByteArray();
System.out.println("Encoded " + events.length + " events into " + data.length + " bytes");
ByteArrayInputStream bis = new ByteArrayInputStream(data);
EventReader<Event> reader = ThreadEventCodec.createEventReader(bis);
return reader;
}
use of org.gridkit.jvmtool.event.UniversalEventWriter in project jvm-tools by aragozin.
the class ThreadEventReaderTest method read_dump_v2_rewrite_and_compare.
@Test
public void read_dump_v2_rewrite_and_compare() throws FileNotFoundException, IOException {
File sourceFile = new File("src/test/resources/dump_v2.std");
File file = new File("target/tmp/" + testName.getMethodName() + "-" + System.currentTimeMillis() + ".std");
file.getParentFile().mkdirs();
file.delete();
FileOutputStream fow = new FileOutputStream(file);
UniversalEventWriter writer = ThreadEventCodec.createEventWriter(fow);
EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream(sourceFile));
copyAllTraces(reader, writer);
writer.close();
System.out.println("New file " + file.length() + " bytes (original " + sourceFile.length() + " bytes)");
reader = ThreadEventCodec.createEventReader(new FileInputStream(file));
EventReader<Event> origReader = ThreadEventCodec.createEventReader(new FileInputStream(sourceFile));
assertThat((Iterable<Event>) reader).is(exactlyAs(origReader));
}
use of org.gridkit.jvmtool.event.UniversalEventWriter in project jvm-tools by aragozin.
the class ThreadEventReaderTest method read_dump_v4_rewrite_and_compare.
@Test
public void read_dump_v4_rewrite_and_compare() throws FileNotFoundException, IOException {
File sourceFile = new File("src/test/resources/dump_v4.std");
File file = new File("target/tmp/" + testName.getMethodName() + "-" + System.currentTimeMillis() + ".std");
file.getParentFile().mkdirs();
file.delete();
FileOutputStream fow = new FileOutputStream(file);
UniversalEventWriter writer = ThreadEventCodec.createEventWriter(fow);
EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream(sourceFile));
copyAllTraces(reader, writer);
writer.close();
System.out.println("New file " + file.length() + " bytes (original " + sourceFile.length() + " bytes)");
reader = ThreadEventCodec.createEventReader(new FileInputStream(file));
EventReader<Event> origReader = ThreadEventCodec.createEventReader(new FileInputStream(sourceFile));
assertThat((Iterable<Event>) reader).is(exactlyAs(origReader));
}
Aggregations