Search in sources :

Example 1 with Method

use of com.insightfullogic.honest_profiler.core.parser.Method in project honest-profiler by jvm-profiling-tools.

the class FlameGraphCollector method addCurrentTrace.

private void addCurrentTrace() {
    if (currentMethodIds == null || currentMethodIds.size() == 0)
        return;
    if (lastMethodIds.equals(currentMethodIds)) {
        trace.incrementWeight();
        return;
    }
    List<Method> methods = currentMethodIds.stream().map(method -> this.methods.getOrDefault(method, unknownMethod)).collect(toList());
    trace = new FlameTrace(methods, 1);
    flameGraph.onNewTrace(trace);
}
Also used : FlameGraphListener(com.insightfullogic.honest_profiler.core.profiles.FlameGraphListener) TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) Monitor(com.insightfullogic.honest_profiler.core.Monitor) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) HashMap(java.util.HashMap) Method(com.insightfullogic.honest_profiler.core.parser.Method) ArrayList(java.util.ArrayList) FlameGraph(com.insightfullogic.honest_profiler.core.profiles.FlameGraph) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) FlameTrace(com.insightfullogic.honest_profiler.core.profiles.FlameTrace) LogEventListener(com.insightfullogic.honest_profiler.core.parser.LogEventListener) LogSource(com.insightfullogic.honest_profiler.core.sources.LogSource) ThreadMeta(com.insightfullogic.honest_profiler.core.parser.ThreadMeta) Map(java.util.Map) Box(com.insightfullogic.honest_profiler.core.Box) FlameTrace(com.insightfullogic.honest_profiler.core.profiles.FlameTrace) Method(com.insightfullogic.honest_profiler.core.parser.Method)

Example 2 with Method

use of com.insightfullogic.honest_profiler.core.parser.Method in project honest-profiler by jvm-profiling-tools.

the class LogCollectorTest method logCollectorShouldCopeWithUnexpectedFrames.

@Test
public void logCollectorShouldCopeWithUnexpectedFrames() {
    final Deque<Profile> found = new ArrayDeque<>();
    final LogCollector collector = new LogCollector(found::add, true);
    for (int i = 0; i < 10; i++) {
        collector.handle(new Method(i, "a", "Bass", "c" + i));
    }
    assertTrue("methods don't cause profiles", found.isEmpty());
    int threadId = 0;
    collector.handle(new TraceStart(2, ++threadId, 1, 1));
    assertTrue("nothing to profile still", found.isEmpty());
    collector.handle(new StackFrame(LINE, 0));
    collector.handle(new StackFrame(LINE, 1));
    // ..and one unexpected frame
    collector.handle(new StackFrame(LINE, 2));
    // normal method afterwards
    collector.handle(new TraceStart(2, ++threadId, 1, 1));
    collector.handle(new StackFrame(LINE, 6));
    collector.handle(new StackFrame(LINE, 7));
    // and continuation
    collector.handle(new TraceStart(20, ++threadId, 1, 1));
    assertArrayEquals(new long[] { 2, 7 }, idOfLastMethodInEachThread(found.getLast()));
}
Also used : TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) Method(com.insightfullogic.honest_profiler.core.parser.Method) Profile(com.insightfullogic.honest_profiler.core.profiles.Profile) ArrayDeque(java.util.ArrayDeque) Test(org.junit.Test)

Example 3 with Method

use of com.insightfullogic.honest_profiler.core.parser.Method 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);
            }
        }
    });
}
Also used : PrintStream(java.io.PrintStream) CmdLineParser(org.kohsuke.args4j.CmdLineParser) TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) Monitor(com.insightfullogic.honest_profiler.core.Monitor) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) HashMap(java.util.HashMap) Method(com.insightfullogic.honest_profiler.core.parser.Method) Option(org.kohsuke.args4j.Option) FileLogSource(com.insightfullogic.honest_profiler.ports.sources.FileLogSource) File(java.io.File) CmdLineException(org.kohsuke.args4j.CmdLineException) LogEventListener(com.insightfullogic.honest_profiler.core.parser.LogEventListener) ThreadMeta(com.insightfullogic.honest_profiler.core.parser.ThreadMeta) Map(java.util.Map) PrintStream(java.io.PrintStream) ThreadMeta(com.insightfullogic.honest_profiler.core.parser.ThreadMeta) HashMap(java.util.HashMap) LogEventListener(com.insightfullogic.honest_profiler.core.parser.LogEventListener) Method(com.insightfullogic.honest_profiler.core.parser.Method) FileLogSource(com.insightfullogic.honest_profiler.ports.sources.FileLogSource) TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame)

Example 4 with Method

use of com.insightfullogic.honest_profiler.core.parser.Method in project honest-profiler by jvm-profiling-tools.

the class CallCountAggregator method toFlatProfileEntry.

private FlatProfileEntry toFlatProfileEntry(final T key, final CallCounts callCounts, final int traceCount) {
    int totalCount = callCounts.getTimeAppeared();
    int selfCount = callCounts.getTimeInvokingThis();
    Method method;
    final Long methodId = getMethodId.apply(key);
    method = methodByMethodId.get(methodId);
    if (method == null) {
        method = new Method(methodId, "UNKNOWN", "UNKNOWN", String.valueOf(methodId));
    }
    Frame frame;
    if (key instanceof StackFrame) {
        frame = new FullFrame(method, (StackFrame) key);
    } else {
        frame = method;
    }
    return new FlatProfileEntry(frame, totalCount, selfCount, traceCount);
}
Also used : StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) Method(com.insightfullogic.honest_profiler.core.parser.Method)

Example 5 with Method

use of com.insightfullogic.honest_profiler.core.parser.Method in project honest-profiler by jvm-profiling-tools.

the class NodeCollector method normaliseBy.

private ProfileNode normaliseBy(int parentVisits, LongFunction<Method> nameRegistry) {
    Method method = nameRegistry.apply(methodId);
    List<ProfileNode> children = childrenByMethodId.values().stream().map(child -> child.normaliseBy(parentVisits, nameRegistry)).sorted(bySelfTimeShare).collect(toList());
    return new ProfileNode(method, visits, parentVisits, children);
}
Also used : ProfileNode(com.insightfullogic.honest_profiler.core.profiles.ProfileNode) Method(com.insightfullogic.honest_profiler.core.parser.Method)

Aggregations

Method (com.insightfullogic.honest_profiler.core.parser.Method)5 StackFrame (com.insightfullogic.honest_profiler.core.parser.StackFrame)4 TraceStart (com.insightfullogic.honest_profiler.core.parser.TraceStart)3 Monitor (com.insightfullogic.honest_profiler.core.Monitor)2 LogEventListener (com.insightfullogic.honest_profiler.core.parser.LogEventListener)2 ThreadMeta (com.insightfullogic.honest_profiler.core.parser.ThreadMeta)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Box (com.insightfullogic.honest_profiler.core.Box)1 FlameGraph (com.insightfullogic.honest_profiler.core.profiles.FlameGraph)1 FlameGraphListener (com.insightfullogic.honest_profiler.core.profiles.FlameGraphListener)1 FlameTrace (com.insightfullogic.honest_profiler.core.profiles.FlameTrace)1 Profile (com.insightfullogic.honest_profiler.core.profiles.Profile)1 ProfileNode (com.insightfullogic.honest_profiler.core.profiles.ProfileNode)1 LogSource (com.insightfullogic.honest_profiler.core.sources.LogSource)1 FileLogSource (com.insightfullogic.honest_profiler.ports.sources.FileLogSource)1 File (java.io.File)1 PrintStream (java.io.PrintStream)1 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1