use of com.insightfullogic.honest_profiler.core.parser.LogEventListener in project honest-profiler by jvm-profiling-tools.
the class InitializeProfileTask method consume.
/**
* Returns a {@link ProfileContext} which will emit {@link LeanProfile}s produced by consuming a non-live log file.
* <p>
* @param fileLogSource the non-live log file which will be processed
* @return a new {@link ProfileContext} for non-live log file consumption
*/
private ProfileContext consume(FileLogSource fileLogSource) {
ProfileContext profileContext = newProfileContext(LOG, fileLogSource);
final LogEventListener collector = new LogEventPublisher().publishTo(getCollector(profileContext));
pipe(fileLogSource, collector, false).run();
return profileContext;
}
use of com.insightfullogic.honest_profiler.core.parser.LogEventListener in project honest-profiler by jvm-profiling-tools.
the class ConsoleLogDumpApplication method run.
public void run() {
final PrintStream err = error.stream();
if (!logLocation.exists() || !logLocation.canRead()) {
err.println("Unable to find log file at: " + logLocation);
return;
}
final PrintStream out = output.stream();
out.println("Printing text representation for: " + logLocation.getAbsolutePath());
Monitor.consumeFile(new FileLogSource(logLocation), new LogEventListener() {
int indent;
long traceidx;
long errCount;
Map<String, Counter> errHistogram = new HashMap<>();
Map<Long, BoundMethod> methodNames = new HashMap<>();
Map<Long, String> threadNames = new HashMap<>();
@Override
public void handle(Method method) {
BoundMethod boundMethod = new BoundMethod(method.getClassName(), method.getMethodReturnType(), method.getMethodName(), method.getMethodSignature());
out.printf("Method : %d -> %s %s.%s%s\n", method.getMethodId(), method.getMethodReturnType(), method.getClassName(), method.getMethodName(), method.getMethodSignature());
methodNames.put(method.getMethodId(), boundMethod);
}
@Override
public void handle(StackFrame stackFrame) {
indent--;
long methodId = stackFrame.getMethodId();
BoundMethod boundMethod = methodNames.get(methodId);
if (methodId == 0) {
errCount++;
// null method
out.print("StackFrame: ");
indent(out);
out.printf("%d @ %s (bci=%s)\n", methodId, stackFrame.getLineNumber(), stackFrame.getBci());
Counter counter = errHistogram.computeIfAbsent("Null jmethodId", k -> new Counter());
counter.inc();
} else if (methodId < 0) {
errCount++;
// bad sample dressed up as a frame
out.print("StackFrame: ");
indent(out);
out.printf("%s %s::%s%s \n", boundMethod.returnType, boundMethod.className, boundMethod.methodName, boundMethod.methodSignature);
Counter counter = errHistogram.computeIfAbsent(boundMethod.methodName, k -> new Counter());
counter.inc();
} else if (boundMethod == null) {
out.print("StackFrame: ");
indent(out);
out.printf("%d @ %s (bci=%s)\n", methodId, stackFrame.getLineNumber(), stackFrame.getBci());
} else {
out.print("StackFrame: ");
indent(out);
out.printf("%s %s::%s%s @ %s (bci=%s)\n", boundMethod.returnType, boundMethod.className, boundMethod.methodName, boundMethod.methodSignature, stackFrame.getLineNumber(), stackFrame.getBci());
}
}
private void indent(final PrintStream out) {
for (int i = 0; i < indent; i++) out.print(' ');
}
@Override
public void handle(TraceStart traceStart) {
int frames = traceStart.getNumberOfFrames();
long tid = traceStart.getThreadId();
String tidString = tid >= 0 ? ("tid=" + tid) : "tid=unknown";
String name = threadNames.get(tid);
if (name == null || "".equals(name)) {
name = "Unknown";
}
out.printf("TraceStart: [%d] %d.%d %s,%s,frames=%d\n", traceidx, traceStart.getTraceEpoch(), traceStart.getTraceEpochNano(), name, tidString, frames);
indent = frames;
traceidx++;
}
@Override
public void handle(ThreadMeta newThreadMeta) {
long tid = newThreadMeta.getThreadId();
String name = newThreadMeta.getThreadName();
out.printf("ThreadMeta: tid=%d,name=%s\n", tid, name);
threadNames.put(tid, name);
}
@Override
public void endOfLog() {
out.printf("Processed %d traces, %d faulty\n", traceidx, errCount);
for (Map.Entry<String, Counter> e : errHistogram.entrySet()) {
final String errCode = e.getKey();
final int errCodeCount = e.getValue().i;
out.printf("%-20s: %d \n", errCode, errCodeCount);
}
}
});
}
Aggregations