Search in sources :

Example 6 with Event

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) Event(org.gridkit.jvmtool.event.Event) CommonEvent(org.gridkit.jvmtool.event.CommonEvent) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UniversalEventWriter(org.gridkit.jvmtool.event.UniversalEventWriter)

Example 7 with Event

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 + ")");
}
Also used : Event(org.gridkit.jvmtool.event.Event) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent)

Example 8 with Event

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));
}
Also used : FileOutputStream(java.io.FileOutputStream) Event(org.gridkit.jvmtool.event.Event) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) UniversalEventWriter(org.gridkit.jvmtool.event.UniversalEventWriter) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 9 with Event

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));
}
Also used : FileOutputStream(java.io.FileOutputStream) Event(org.gridkit.jvmtool.event.Event) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) UniversalEventWriter(org.gridkit.jvmtool.event.UniversalEventWriter) File(java.io.File) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Example 10 with Event

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");
}
Also used : ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) Event(org.gridkit.jvmtool.event.Event) ErrorEvent(org.gridkit.jvmtool.event.ErrorEvent) FileInputStream(java.io.FileInputStream) Test(org.junit.Test)

Aggregations

Event (org.gridkit.jvmtool.event.Event)10 FileInputStream (java.io.FileInputStream)7 ErrorEvent (org.gridkit.jvmtool.event.ErrorEvent)7 Test (org.junit.Test)6 UniversalEventWriter (org.gridkit.jvmtool.event.UniversalEventWriter)5 File (java.io.File)4 FileOutputStream (java.io.FileOutputStream)4 IOException (java.io.IOException)2 ThreadSnapshotEvent (org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ThreadMXBean (java.lang.management.ThreadMXBean)1 MBeanServerConnection (javax.management.MBeanServerConnection)1 ThreadSnapshotExpander (org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotExpander)1 ChainedEventReader (org.gridkit.jvmtool.event.ChainedEventReader)1 CommonEvent (org.gridkit.jvmtool.event.CommonEvent)1 ErrorHandler (org.gridkit.jvmtool.event.ErrorHandler)1 EventReader (org.gridkit.jvmtool.event.EventReader)1 ShieldedEventReader (org.gridkit.jvmtool.event.ShieldedEventReader)1 SimpleErrorEvent (org.gridkit.jvmtool.event.SimpleErrorEvent)1