use of org.gridkit.jvmtool.event.Event 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.Event in project jvm-tools by aragozin.
the class ThreadEventReaderTest method copyAllTraces.
private void copyAllTraces(EventReader<Event> reader, UniversalEventWriter writer) throws IOException {
int tn = 0;
int ntn = 0;
for (Event e : reader) {
if (e instanceof ThreadSnapshotEvent) {
++tn;
} else {
++ntn;
}
writer.store(e);
}
System.out.println("Copy " + (tn + ntn) + " traces (" + tn + " + " + ntn + ")");
}
use of org.gridkit.jvmtool.event.Event 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.Event 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));
}
use of org.gridkit.jvmtool.event.Event in project jvm-tools by aragozin.
the class ThreadEventReaderTest method read_dump_v1.
@Test
public void read_dump_v1() throws FileNotFoundException, IOException {
EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream("src/test/resources/dump_v1.std"));
int n = 0;
for (Event e : reader) {
if (e instanceof ErrorEvent) {
fail("Error", ((ErrorEvent) e).exception());
}
++n;
}
System.out.println("Read " + n + " traces from file");
}
Aggregations