use of org.gridkit.jvmtool.event.Event in project jvm-tools by aragozin.
the class ThreadEventCodec method createEventReader.
public static EventReader<Event> createEventReader(byte[] magic, InputStream is) throws IOException {
if (Arrays.equals(magic, StackTraceCodec.MAGIC)) {
StackTraceReader lreader = new StackTraceReaderV1(is);
EventReader<Event> reader = new LegacyThreadEventReader(lreader);
return reader;
}
if (Arrays.equals(magic, StackTraceCodec.MAGIC2)) {
StackTraceReader lreader = new StackTraceReaderV2(is);
EventReader<Event> reader = new LegacyThreadEventReader(lreader);
return reader;
} else // MAGIC3 is not used
if (Arrays.equals(magic, StackTraceCodec.MAGIC4)) {
EventReader<Event> reader = new StackTraceEventReaderV4(is).morph(new ThreadSnapshotExpander());
return reader;
} else {
throw new IOException("Unknown magic '" + new String(magic) + "'");
}
}
use of org.gridkit.jvmtool.event.Event in project jvm-tools by aragozin.
the class ThreadEventReaderTest method read_dump_v2.
@Test
public void read_dump_v2() throws FileNotFoundException, IOException {
EventReader<Event> reader = ThreadEventCodec.createEventReader(new FileInputStream("src/test/resources/dump_v2.std"));
int n = 0;
for (Event e : reader) {
if (e instanceof ErrorEvent) {
fail("Error", ((ErrorEvent) e).exception());
}
// System.out.println(((MultiCounterEvent)e).counters());
++n;
}
System.out.println("Read " + n + " traces from file");
}
use of org.gridkit.jvmtool.event.Event 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.Event in project jvm-tools by aragozin.
the class ThreadDumpSource method getUnclassifiedReader.
public EventReader<ThreadSnapshotEvent> getUnclassifiedReader() {
if (files == null) {
host.fail("No input files provided, used -f option");
}
final Iterator<String> it = files.iterator();
ChainedEventReader<Event> reader = new ChainedEventReader<Event>() {
@Override
protected EventReader<Event> produceNext() {
return it.hasNext() ? open(it.next()) : null;
}
private EventReader<Event> open(String next) {
try {
return ThreadEventCodec.createEventReader(new FileInputStream(next));
} catch (IOException e) {
return new SingleEventReader<Event>(new SimpleErrorEvent(e));
}
}
};
ShieldedEventReader<ThreadSnapshotEvent> shielderReader = new ShieldedEventReader<ThreadSnapshotEvent>(reader, ThreadSnapshotEvent.class, new ErrorHandler() {
@Override
public void onException(Exception e) {
System.err.println("Stream reader error: " + e);
}
});
return shielderReader;
}
use of org.gridkit.jvmtool.event.Event 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