Search in sources :

Example 1 with FileLogSource

use of com.insightfullogic.honest_profiler.ports.sources.FileLogSource in project honest-profiler by jvm-profiling-tools.

the class AgentIntegrationTest method discoverVirtualMachines.

private AtomicReference<Profile> discoverVirtualMachines() {
    AtomicReference<Profile> lastProfile = new AtomicReference<>();
    parkNanos(SECONDS.toNanos(1));
    new LocalMachineSource(logger, new MachineListener() {

        @Override
        public void onNewMachine(final VirtualMachine machine) {
            if (machine.isAgentLoaded()) {
                final FileLogSource logSource = (FileLogSource) machine.getLogSource();
                file.set(logSource);
                Monitor.pipeFile(logSource, lastProfile::set);
            }
        }

        @Override
        public void onClosedMachine(final VirtualMachine machine) {
        }
    }).discoverVirtualMachines();
    return lastProfile;
}
Also used : FileLogSource(com.insightfullogic.honest_profiler.ports.sources.FileLogSource) LocalMachineSource(com.insightfullogic.honest_profiler.ports.sources.LocalMachineSource) AtomicReference(java.util.concurrent.atomic.AtomicReference) MachineListener(com.insightfullogic.honest_profiler.core.MachineListener) Profile(com.insightfullogic.honest_profiler.core.profiles.Profile) VirtualMachine(com.insightfullogic.honest_profiler.core.sources.VirtualMachine)

Example 2 with FileLogSource

use of com.insightfullogic.honest_profiler.ports.sources.FileLogSource in project honest-profiler by jvm-profiling-tools.

the class ConsoleApplication method displayLogFile.

private void displayLogFile() {
    try {
        if (!logLocation.exists() || !logLocation.canRead()) {
            error.stream().println("Unable to find log file at: " + logLocation);
            return;
        }
        ProfileListener listener = ui;
        if (filterDescription != null) {
            ProfileFilter filter = new ProfileFilter();
            filter.updateFilters(filterDescription);
            listener = profile -> {
                filter.accept(profile);
                ui.accept(profile);
            };
        }
        output.stream().println("Printing Profile for: " + logLocation.getAbsolutePath());
        Monitor.consumeFile(new FileLogSource(logLocation), listener);
    } catch (Exception e) {
        // TODO: better error handling
        e.printStackTrace(error.stream());
    }
}
Also used : ProfileListener(com.insightfullogic.honest_profiler.core.profiles.ProfileListener) FileLogSource(com.insightfullogic.honest_profiler.ports.sources.FileLogSource) ProfileFilter(com.insightfullogic.honest_profiler.core.filters.ProfileFilter) CmdLineException(org.kohsuke.args4j.CmdLineException)

Example 3 with FileLogSource

use of com.insightfullogic.honest_profiler.ports.sources.FileLogSource in project honest-profiler by jvm-profiling-tools.

the class FlameGraphDumperApplication method main.

public static void main(String[] args) throws Exception {
    if (args.length < 2) {
        System.out.print("Usage: java com.insightfullogic.honest_profiler.ports.console.FlameGraphApplication <profile.hpl> <profile.txt>\n" + "\n" + "The output needs to be processed with the tools at https://github.com/brendangregg/FlameGraph to produce the actual flamegraph\n");
        System.exit(1);
    }
    String in = args[0], out = args[1];
    LogSource source = new FileLogSource(new File(in));
    try (Writer output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(out)))) {
        FlameGraph data = FlameGraphCollector.readFlamegraph(source);
        for (FlameTrace trace : data.getTraces()) {
            writeTrace(output, trace);
        }
    }
}
Also used : FileLogSource(com.insightfullogic.honest_profiler.ports.sources.FileLogSource) LogSource(com.insightfullogic.honest_profiler.core.sources.LogSource) FileLogSource(com.insightfullogic.honest_profiler.ports.sources.FileLogSource) FlameTrace(com.insightfullogic.honest_profiler.core.profiles.FlameTrace) FlameGraph(com.insightfullogic.honest_profiler.core.profiles.FlameGraph)

Example 4 with FileLogSource

use of com.insightfullogic.honest_profiler.ports.sources.FileLogSource 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 5 with FileLogSource

use of com.insightfullogic.honest_profiler.ports.sources.FileLogSource in project honest-profiler by jvm-profiling-tools.

the class VirtualMachine method getLogSourceFromVmArgs.

public LogSource getLogSourceFromVmArgs() throws CantReadFromSourceException {
    // Bail out if agentpath is not defined.
    if (vmArgs.indexOf(OPT_AGENT) < 0) {
        return getLogSource();
    }
    // Extract the value of the agentpath parameter
    int agentPathStart = vmArgs.indexOf(OPT_AGENT) + OPT_AGENT.length();
    // TODO FIX : if the logPath contains spaces, this will cause trouble.
    int agentPathEnd = vmArgs.indexOf(' ', agentPathStart);
    // If the agentpath is the last parameter in the VM Args, no space would be found.
    agentPathEnd = (agentPathEnd < 0) ? vmArgs.length() : agentPathEnd;
    String agentPath = vmArgs.substring(agentPathStart, agentPathEnd);
    // Bail out if logPath is not defined.
    if (agentPath.indexOf(OPT_LOG) < 0) {
        return getLogSource();
    }
    // Extract the value of the logPath parameter
    int logPathStart = agentPath.indexOf(OPT_LOG) + OPT_LOG.length();
    int commaPos = agentPath.indexOf(",", logPathStart);
    int spacePos = agentPath.indexOf(' ', logPathStart);
    int logPathEnd = commaPos > 0 ? commaPos : (spacePos > 0 ? spacePos : agentPath.length());
    File result = new File(agentPath.substring(logPathStart, logPathEnd));
    return result.exists() ? new FileLogSource(result) : getLogSource();
}
Also used : FileLogSource(com.insightfullogic.honest_profiler.ports.sources.FileLogSource) File(java.io.File)

Aggregations

FileLogSource (com.insightfullogic.honest_profiler.ports.sources.FileLogSource)5 File (java.io.File)2 CmdLineException (org.kohsuke.args4j.CmdLineException)2 MachineListener (com.insightfullogic.honest_profiler.core.MachineListener)1 Monitor (com.insightfullogic.honest_profiler.core.Monitor)1 ProfileFilter (com.insightfullogic.honest_profiler.core.filters.ProfileFilter)1 LogEventListener (com.insightfullogic.honest_profiler.core.parser.LogEventListener)1 Method (com.insightfullogic.honest_profiler.core.parser.Method)1 StackFrame (com.insightfullogic.honest_profiler.core.parser.StackFrame)1 ThreadMeta (com.insightfullogic.honest_profiler.core.parser.ThreadMeta)1 TraceStart (com.insightfullogic.honest_profiler.core.parser.TraceStart)1 FlameGraph (com.insightfullogic.honest_profiler.core.profiles.FlameGraph)1 FlameTrace (com.insightfullogic.honest_profiler.core.profiles.FlameTrace)1 Profile (com.insightfullogic.honest_profiler.core.profiles.Profile)1 ProfileListener (com.insightfullogic.honest_profiler.core.profiles.ProfileListener)1 LogSource (com.insightfullogic.honest_profiler.core.sources.LogSource)1 VirtualMachine (com.insightfullogic.honest_profiler.core.sources.VirtualMachine)1 LocalMachineSource (com.insightfullogic.honest_profiler.ports.sources.LocalMachineSource)1 PrintStream (java.io.PrintStream)1 HashMap (java.util.HashMap)1