use of org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent in project jvm-tools by aragozin.
the class ThreadDumpSource method getFilteredReader.
public EventReader<ThreadSnapshotEvent> getFilteredReader() {
if (traceFilter == null && traceTrim == null && threadName == null && timeRange == null) {
return getUnclassifiedReader();
} else {
EventReader<ThreadSnapshotEvent> reader = getUnclassifiedReader();
if (threadName != null) {
reader = reader.morph(new ThreadNameFilter(threadName));
}
if (timeRange != null) {
String[] lh = timeRange.split("[-]");
if (lh.length != 2) {
host.fail("Invalid time range '" + timeRange + "'", "Valid format yyyy.MM.dd_HH:mm:ss-yyyy.MM.dd_HH:mm:ss hours and higher parts can be ommited");
}
TimeRangeChecker checker = new TimeRangeChecker(lh[0], lh[1], timeZone);
reader = reader.morph(new TimeFilter(checker));
}
try {
CachingFilterFactory factory = new CachingFilterFactory();
if (traceFilter != null) {
ThreadSnapshotFilter ts = TraceFilterPredicateParser.parseFilter(traceFilter, factory);
reader = reader.morph(new ThreadEventFilter(ts));
}
if (traceTrim != null) {
final PositionalStackMatcher mt = TraceFilterPredicateParser.parsePositionMatcher(traceTrim, factory);
reader = reader.morph(new TrimProxy() {
@Override
public ThreadSnapshotEvent morph(ThreadSnapshotEvent event) {
int n = mt.matchNext(event, 0);
if (n >= 0) {
trimPoint = n;
return super.morph(event);
} else {
return null;
}
}
});
}
return reader;
} catch (ParserException e) {
throw host.fail("Failed to parse trace filter - " + e.getMessage() + " at " + e.getOffset() + " [" + e.getParseText() + "]");
}
}
}
use of org.gridkit.jvmtool.codec.stacktrace.ThreadSnapshotEvent 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.codec.stacktrace.ThreadSnapshotEvent 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.codec.stacktrace.ThreadSnapshotEvent in project jvm-tools by aragozin.
the class EventDecoratorTest method verify_thread_snapshot_event.
@Test
public void verify_thread_snapshot_event() {
ThreadSnapshotEventPojo a = new ThreadSnapshotEventPojo();
a.timestamp(10000);
a.tags().put("A", "1");
a.tags().put("B", "2");
a.tags().put("B", "3");
a.tags().put("C", "4");
a.counters().set("X", 10);
a.counters().set("zzz", Long.MAX_VALUE);
a.threadName("Test");
a.threadState(State.NEW);
ThreadSnapshotEventPojo b = new ThreadSnapshotEventPojo();
b.loadFrom(a);
assertThat(b).is(eventEquals(a));
EventDecorator deco = new EventDecorator();
ThreadSnapshotEvent c = deco.wrap(b);
assertThat(c).is(eventEquals(a));
deco.timestamp(77777);
deco.tags().put("F", "10");
deco.counters().set("__", 25);
assertThat(c.timestamp()).isEqualTo(77777);
assertThat(c.tags()).containsOnly("A", "B", "C", "F");
assertThat(c.counters()).containsOnly("X", "zzz", "__");
assertThat(c.threadName()).isEqualTo("Test");
assertThat(c.threadState()).isEqualTo(State.NEW);
}
Aggregations