Search in sources :

Example 6 with StackFrame

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

the class ProfileTreeTest method printlnCallingPrintf.

private void printlnCallingPrintf(final int threadId) {
    collector.handle(new TraceStart(2, threadId, 0, 0));
    collector.handle(new StackFrame(20, ProfileFixtures.printfId));
    collector.handle(ProfileFixtures.printf);
    collector.handle(new StackFrame(20, ProfileFixtures.printlnId));
}
Also used : TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame)

Example 7 with StackFrame

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

the class ProfileTreeTest method printlnCallingAppend.

private void printlnCallingAppend(int threadId) {
    collector.handle(new TraceStart(2, threadId, 0, 0));
    collector.handle(new StackFrame(20, ProfileFixtures.appendId));
    collector.handle(ProfileFixtures.append);
    collector.handle(new StackFrame(20, ProfileFixtures.printlnId));
    collector.handle(ProfileFixtures.println);
}
Also used : TraceStart(com.insightfullogic.honest_profiler.core.parser.TraceStart) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame)

Example 8 with StackFrame

use of com.insightfullogic.honest_profiler.core.parser.StackFrame 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 9 with StackFrame

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

the class LeanProfileGenerator method assertProfileContainsStack.

public void assertProfileContainsStack(long threadId, StackFrame... stack) {
    LeanNode current = currentProfile.getThreads().get(threadId);
    assertNotNull("Thread not found in Profile", current);
    int level = 0;
    List<StackFrame> frames = asList(stack);
    reverse(frames);
    for (StackFrame frame : frames) {
        level++;
        Optional<LeanNode> child = current.getChildren().stream().filter(node -> node.getFrame().getMethodId() == frame.getMethodId() && node.getFrame().getLineNr() == frame.getLineNumber() && node.getFrame().getBci() == frame.getBci()).findFirst();
        assertTrue("Descendant at level " + level + " not found", child.isPresent());
        current = child.get();
        assertNodeRepresentsFrame(current, frame);
    }
}
Also used : LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Collections.reverse(java.util.Collections.reverse) Assert.assertNotNull(org.junit.Assert.assertNotNull) NumericInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.NumericInfo) ThreadInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.ThreadInfo) Assert.assertTrue(org.junit.Assert.assertTrue) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) Method(com.insightfullogic.honest_profiler.core.parser.Method) LeanLogCollectorDriver(com.insightfullogic.honest_profiler.framework.LeanLogCollectorDriver) MethodInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.MethodInfo) List(java.util.List) LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Assert.assertNull(org.junit.Assert.assertNull) FrameInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.FrameInfo) Arrays.asList(java.util.Arrays.asList) ThreadMeta(com.insightfullogic.honest_profiler.core.parser.ThreadMeta) Optional(java.util.Optional) BigInteger(java.math.BigInteger) LeanProfile(com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile) Assert.assertEquals(org.junit.Assert.assertEquals) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame)

Example 10 with StackFrame

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

the class LeanProfileGenerator method getNode.

public LeanNode getNode(long threadId, StackFrame... stack) {
    LeanNode current = currentProfile.getThreads().get(threadId);
    List<StackFrame> frames = asList(stack);
    reverse(frames);
    for (StackFrame frame : frames) {
        Optional<LeanNode> child = current.getChildren().stream().filter(node -> node.getFrame().getMethodId() == frame.getMethodId()).findFirst();
        current = child.get();
    }
    return current;
}
Also used : LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Collections.reverse(java.util.Collections.reverse) Assert.assertNotNull(org.junit.Assert.assertNotNull) NumericInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.NumericInfo) ThreadInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.ThreadInfo) Assert.assertTrue(org.junit.Assert.assertTrue) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame) Method(com.insightfullogic.honest_profiler.core.parser.Method) LeanLogCollectorDriver(com.insightfullogic.honest_profiler.framework.LeanLogCollectorDriver) MethodInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.MethodInfo) List(java.util.List) LeanNode(com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode) Assert.assertNull(org.junit.Assert.assertNull) FrameInfo(com.insightfullogic.honest_profiler.core.profiles.lean.info.FrameInfo) Arrays.asList(java.util.Arrays.asList) ThreadMeta(com.insightfullogic.honest_profiler.core.parser.ThreadMeta) Optional(java.util.Optional) BigInteger(java.math.BigInteger) LeanProfile(com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile) Assert.assertEquals(org.junit.Assert.assertEquals) StackFrame(com.insightfullogic.honest_profiler.core.parser.StackFrame)

Aggregations

StackFrame (com.insightfullogic.honest_profiler.core.parser.StackFrame)12 TraceStart (com.insightfullogic.honest_profiler.core.parser.TraceStart)7 Method (com.insightfullogic.honest_profiler.core.parser.Method)5 Test (org.junit.Test)4 ThreadMeta (com.insightfullogic.honest_profiler.core.parser.ThreadMeta)3 Profile (com.insightfullogic.honest_profiler.core.profiles.Profile)3 LeanNode (com.insightfullogic.honest_profiler.core.profiles.lean.LeanNode)2 LeanProfile (com.insightfullogic.honest_profiler.core.profiles.lean.LeanProfile)2 FrameInfo (com.insightfullogic.honest_profiler.core.profiles.lean.info.FrameInfo)2 MethodInfo (com.insightfullogic.honest_profiler.core.profiles.lean.info.MethodInfo)2 NumericInfo (com.insightfullogic.honest_profiler.core.profiles.lean.info.NumericInfo)2 ThreadInfo (com.insightfullogic.honest_profiler.core.profiles.lean.info.ThreadInfo)2 LeanLogCollectorDriver (com.insightfullogic.honest_profiler.framework.LeanLogCollectorDriver)2 BigInteger (java.math.BigInteger)2 Arrays.asList (java.util.Arrays.asList)2 Collections.reverse (java.util.Collections.reverse)2 List (java.util.List)2 Optional (java.util.Optional)2 Assert.assertEquals (org.junit.Assert.assertEquals)2 Assert.assertNotNull (org.junit.Assert.assertNotNull)2