Search in sources :

Example 1 with MonitorInfo

use of java.lang.management.MonitorInfo in project pinpoint by naver.

the class ThreadDumpUtils method setMonitorInfo.

private static void setMonitorInfo(TThreadDump threadDump, ThreadInfo threadInfo) {
    MonitorInfo[] monitorInfos = threadInfo.getLockedMonitors();
    if (monitorInfos != null) {
        for (MonitorInfo each : monitorInfos) {
            if (each == null) {
                continue;
            }
            TMonitorInfo tMonitorInfo = new TMonitorInfo();
            tMonitorInfo.setStackDepth(each.getLockedStackDepth());
            tMonitorInfo.setStackFrame(each.getLockedStackFrame().toString());
            threadDump.addToLockedMonitors(tMonitorInfo);
        }
    } else {
        threadDump.setLockedMonitors(Collections.<TMonitorInfo>emptyList());
    }
}
Also used : TMonitorInfo(com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo) MonitorInfo(java.lang.management.MonitorInfo) TMonitorInfo(com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)

Example 2 with MonitorInfo

use of java.lang.management.MonitorInfo in project logging-log4j2 by apache.

the class ExtendedThreadInformation method printStack.

@Override
public void printStack(final StringBuilder sb, final StackTraceElement[] stack) {
    int i = 0;
    for (final StackTraceElement element : stack) {
        sb.append("\tat ").append(element.toString());
        sb.append('\n');
        if (i == 0 && threadInfo.getLockInfo() != null) {
            final Thread.State ts = threadInfo.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on ");
                    formatLock(sb, threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on ");
                    formatLock(sb, threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on ");
                    formatLock(sb, threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        for (final MonitorInfo mi : threadInfo.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked ");
                formatLock(sb, mi);
                sb.append('\n');
            }
        }
        ++i;
    }
    final LockInfo[] locks = threadInfo.getLockedSynchronizers();
    if (locks.length > 0) {
        sb.append("\n\tNumber of locked synchronizers = ").append(locks.length).append('\n');
        for (final LockInfo li : locks) {
            sb.append("\t- ");
            formatLock(sb, li);
            sb.append('\n');
        }
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Example 3 with MonitorInfo

use of java.lang.management.MonitorInfo in project bazel by bazelbuild.

the class StackTraces method dumpThreadInfo.

// Adopted from ThreadInfo.toString(), without MAX_FRAMES limit
private static void dumpThreadInfo(ThreadInfo t, Thread thread, PrintStream out) {
    out.print("\"" + t.getThreadName() + "\"" + " Id=" + t.getThreadId() + " " + t.getThreadState());
    if (t.getLockName() != null) {
        out.print(" on " + t.getLockName());
    }
    if (t.getLockOwnerName() != null) {
        out.print(" owned by \"" + t.getLockOwnerName() + "\" Id=" + t.getLockOwnerId());
    }
    if (t.isSuspended()) {
        out.print(" (suspended)");
    }
    if (t.isInNative()) {
        out.print(" (in native)");
    }
    if (thread.isDaemon()) {
        out.print(" (daemon)");
    }
    out.print('\n');
    StackTraceElement[] stackTrace = t.getStackTrace();
    MonitorInfo[] lockedMonitors = t.getLockedMonitors();
    for (int i = 0; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        out.print("\tat " + ste.toString());
        out.print('\n');
        if (i == 0 && t.getLockInfo() != null) {
            Thread.State ts = t.getThreadState();
            switch(ts) {
                case BLOCKED:
                    out.print("\t-  blocked on " + t.getLockInfo());
                    out.print('\n');
                    break;
                case WAITING:
                    out.print("\t-  waiting on " + t.getLockInfo());
                    out.print('\n');
                    break;
                case TIMED_WAITING:
                    out.print("\t-  waiting on " + t.getLockInfo());
                    out.print('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : lockedMonitors) {
            if (mi.getLockedStackDepth() == i) {
                out.print("\t-  locked " + mi);
                out.print('\n');
            }
        }
    }
    LockInfo[] locks = t.getLockedSynchronizers();
    if (locks.length > 0) {
        out.print("\n\tNumber of locked synchronizers = " + locks.length);
        out.print('\n');
        for (LockInfo li : locks) {
            out.print("\t- " + li);
            out.print('\n');
        }
    }
    out.print('\n');
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Example 4 with MonitorInfo

use of java.lang.management.MonitorInfo in project felix by apache.

the class Jdk16ThreadDumper method printStackTrace.

protected void printStackTrace(ThreadWriter threadWriter, ThreadInfo info) {
    StackTraceElement[] trace = info.getStackTrace();
    if (trace.length > 0) {
        MonitorInfo[] locks = info.getLockedMonitors();
        int currentLock = 0;
        for (int idx = 0; idx < trace.length; idx++) {
            threadWriter.printStackTraceElement(trace[idx]);
            if (idx == 0) {
                LockInfo locked = info.getLockInfo();
                if (locked != null) {
                    printLockInfo(threadWriter, BLOCKED, locked, info.getLockOwnerName(), info.getLockOwnerId());
                }
            }
            if (currentLock < locks.length && locks[currentLock].getLockedStackDepth() == idx) {
                printLockInfo(threadWriter, LOCKED, locks[currentLock]);
                currentLock++;
            }
        }
        // print synchronizers ...
        LockInfo[] syncs = info.getLockedSynchronizers();
        if (syncs != null && syncs.length > 0) {
            threadWriter.printEmptyLine();
            threadWriter.println("   Locked ownable synchronizers:");
            for (int j = 0; j < syncs.length; j++) {
                LockInfo sync = syncs[j];
                printLockInfo(threadWriter, LOCKED, sync);
            }
        }
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Example 5 with MonitorInfo

use of java.lang.management.MonitorInfo in project nifi by apache.

the class BootstrapListener method writeDump.

private static void writeDump(final OutputStream out) throws IOException {
    final ThreadMXBean mbean = ManagementFactory.getThreadMXBean();
    final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out));
    final ThreadInfo[] infos = mbean.dumpAllThreads(true, true);
    final long[] deadlockedThreadIds = mbean.findDeadlockedThreads();
    final long[] monitorDeadlockThreadIds = mbean.findMonitorDeadlockedThreads();
    final List<ThreadInfo> sortedInfos = new ArrayList<>(infos.length);
    for (final ThreadInfo info : infos) {
        sortedInfos.add(info);
    }
    Collections.sort(sortedInfos, new Comparator<ThreadInfo>() {

        @Override
        public int compare(ThreadInfo o1, ThreadInfo o2) {
            return o1.getThreadName().toLowerCase().compareTo(o2.getThreadName().toLowerCase());
        }
    });
    final StringBuilder sb = new StringBuilder();
    for (final ThreadInfo info : sortedInfos) {
        sb.append("\n");
        sb.append("\"").append(info.getThreadName()).append("\" Id=");
        sb.append(info.getThreadId()).append(" ");
        sb.append(info.getThreadState().toString()).append(" ");
        switch(info.getThreadState()) {
            case BLOCKED:
            case TIMED_WAITING:
            case WAITING:
                sb.append(" on ");
                sb.append(info.getLockInfo());
                break;
            default:
                break;
        }
        if (info.isSuspended()) {
            sb.append(" (suspended)");
        }
        if (info.isInNative()) {
            sb.append(" (in native code)");
        }
        if (deadlockedThreadIds != null && deadlockedThreadIds.length > 0) {
            for (final long id : deadlockedThreadIds) {
                if (id == info.getThreadId()) {
                    sb.append(" ** DEADLOCKED THREAD **");
                }
            }
        }
        if (monitorDeadlockThreadIds != null && monitorDeadlockThreadIds.length > 0) {
            for (final long id : monitorDeadlockThreadIds) {
                if (id == info.getThreadId()) {
                    sb.append(" ** MONITOR-DEADLOCKED THREAD **");
                }
            }
        }
        final StackTraceElement[] stackTraces = info.getStackTrace();
        for (final StackTraceElement element : stackTraces) {
            sb.append("\n\tat ").append(element);
            final MonitorInfo[] monitors = info.getLockedMonitors();
            for (final MonitorInfo monitor : monitors) {
                if (monitor.getLockedStackFrame().equals(element)) {
                    sb.append("\n\t- waiting on ").append(monitor);
                }
            }
        }
        final LockInfo[] lockInfos = info.getLockedSynchronizers();
        if (lockInfos.length > 0) {
            sb.append("\n\t");
            sb.append("Number of Locked Synchronizers: ").append(lockInfos.length);
            for (final LockInfo lockInfo : lockInfos) {
                sb.append("\n\t- ").append(lockInfo.toString());
            }
        }
        sb.append("\n");
    }
    if (deadlockedThreadIds != null && deadlockedThreadIds.length > 0) {
        sb.append("\n\nDEADLOCK DETECTED!");
        sb.append("\nThe following thread IDs are deadlocked:");
        for (final long id : deadlockedThreadIds) {
            sb.append("\n").append(id);
        }
    }
    if (monitorDeadlockThreadIds != null && monitorDeadlockThreadIds.length > 0) {
        sb.append("\n\nMONITOR DEADLOCK DETECTED!");
        sb.append("\nThe following thread IDs are deadlocked:");
        for (final long id : monitorDeadlockThreadIds) {
            sb.append("\n").append(id);
        }
    }
    writer.write(sb.toString());
    writer.flush();
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) MonitorInfo(java.lang.management.MonitorInfo) ArrayList(java.util.ArrayList) BufferedWriter(java.io.BufferedWriter) ThreadInfo(java.lang.management.ThreadInfo) OutputStreamWriter(java.io.OutputStreamWriter) LockInfo(java.lang.management.LockInfo)

Aggregations

MonitorInfo (java.lang.management.MonitorInfo)77 LockInfo (java.lang.management.LockInfo)41 ThreadInfo (java.lang.management.ThreadInfo)18 ThreadMXBean (java.lang.management.ThreadMXBean)10 Test (org.testng.annotations.Test)8 CompositeData (javax.management.openmbean.CompositeData)7 OutputStreamWriter (java.io.OutputStreamWriter)6 TMonitorInfo (com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)3 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 TThreadDump (com.navercorp.pinpoint.thrift.dto.command.TThreadDump)2 State (java.lang.Thread.State)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 OpenDataException (javax.management.openmbean.OpenDataException)2 MonitorInfoMetricSnapshot (com.navercorp.pinpoint.profiler.monitor.metric.deadlock.MonitorInfoMetricSnapshot)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CompositeType (javax.management.openmbean.CompositeType)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1