Search in sources :

Example 36 with MonitorInfo

use of java.lang.management.MonitorInfo in project knime-core by knime.

the class ThreadUtils method fillStackFromThread.

private static void fillStackFromThread(final ThreadInfo ti, final StringBuilder buf) {
    buf.append("\"" + ti.getThreadName() + "\" Id=" + ti.getThreadId() + " " + ti.getThreadState());
    if (ti.getLockName() != null) {
        buf.append(" on " + ti.getLockName());
    }
    if (ti.getLockOwnerName() != null) {
        buf.append(" owned by \"" + ti.getLockOwnerName() + "\" Id=" + ti.getLockOwnerId());
    }
    if (ti.isSuspended()) {
        buf.append(" (suspended)");
    }
    if (ti.isInNative()) {
        buf.append(" (in native)");
    }
    buf.append('\n');
    int i = 0;
    for (StackTraceElement ste : ti.getStackTrace()) {
        buf.append("\tat " + ste.toString());
        buf.append('\n');
        if ((i == 0) && (ti.getLockInfo() != null)) {
            Thread.State ts = ti.getThreadState();
            switch(ts) {
                case BLOCKED:
                    buf.append("\t-  blocked on " + ti.getLockInfo());
                    buf.append('\n');
                    break;
                case WAITING:
                    buf.append("\t-  waiting on " + ti.getLockInfo());
                    buf.append('\n');
                    break;
                case TIMED_WAITING:
                    buf.append("\t-  waiting on " + ti.getLockInfo());
                    buf.append('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : ti.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                buf.append("\t-  locked " + mi);
                buf.append('\n');
            }
        }
        i++;
    }
    LockInfo[] locks = ti.getLockedSynchronizers();
    if (locks.length > 0) {
        buf.append("\n\tNumber of locked synchronizers = " + locks.length);
        buf.append('\n');
        for (LockInfo li : locks) {
            buf.append("\t- " + li);
            buf.append('\n');
        }
    }
    buf.append('\n');
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Example 37 with MonitorInfo

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

the class TimedOutTestsListener method printThreadInfo.

private static void printThreadInfo(ThreadInfo ti, PrintWriter out) {
    // print thread information
    printThread(ti, out);
    // print stack trace with locks
    StackTraceElement[] stacktrace = ti.getStackTrace();
    MonitorInfo[] monitors = ti.getLockedMonitors();
    for (int i = 0; i < stacktrace.length; i++) {
        StackTraceElement ste = stacktrace[i];
        out.println(INDENT + "at " + ste.toString());
        for (MonitorInfo mi : monitors) {
            if (mi.getLockedStackDepth() == i) {
                out.println(INDENT + "  - locked " + mi);
            }
        }
    }
    out.println();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo)

Example 38 with MonitorInfo

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

the class ThreadDumpService method requestCommandService.

@Override
public TBase<?, ?> requestCommandService(TBase tbase) {
    logger.info("{} execute {}.", this, tbase);
    TCommandThreadDump param = (TCommandThreadDump) tbase;
    TThreadDumpType type = param.getType();
    List<ThreadInfo> threadInfoList = null;
    if (TThreadDumpType.TARGET == type) {
        threadInfoList = getThreadInfo(param.getName());
    } else if (TThreadDumpType.PENDING == type) {
        threadInfoList = getThreadInfo(param.getPendingTimeMillis());
    } else {
        threadInfoList = Arrays.asList(getAllThreadInfo());
    }
    TCommandThreadDumpResponse response = new TCommandThreadDumpResponse();
    for (ThreadInfo info : threadInfoList) {
        TThreadDump dump = new TThreadDump();
        dump.setThreadName(info.getThreadName());
        dump.setThreadId(info.getThreadId());
        dump.setBlockedTime(info.getBlockedTime());
        dump.setBlockedCount(info.getBlockedCount());
        dump.setWaitedTime(info.getWaitedTime());
        dump.setWaitedCount(info.getWaitedCount());
        dump.setLockName(info.getLockName());
        dump.setLockOwnerId(info.getLockOwnerId());
        dump.setLockOwnerName(info.getLockOwnerName());
        dump.setInNative(info.isInNative());
        dump.setSuspended(info.isSuspended());
        dump.setThreadState(getThreadState(info));
        StackTraceElement[] stackTraceElements = info.getStackTrace();
        for (StackTraceElement each : stackTraceElements) {
            dump.addToStackTrace(each.toString());
        }
        MonitorInfo[] monitorInfos = info.getLockedMonitors();
        for (MonitorInfo each : monitorInfos) {
            TMonitorInfo tMonitorInfo = new TMonitorInfo();
            tMonitorInfo.setStackDepth(each.getLockedStackDepth());
            tMonitorInfo.setStackFrame(each.getLockedStackFrame().toString());
            dump.addToLockedMonitors(tMonitorInfo);
        }
        LockInfo[] lockInfos = info.getLockedSynchronizers();
        for (LockInfo lockInfo : lockInfos) {
            dump.addToLockedSynchronizers(lockInfo.toString());
        }
        response.addToThreadDumps(dump);
    }
    return response;
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) ThreadInfo(java.lang.management.ThreadInfo) LockInfo(java.lang.management.LockInfo)

Example 39 with MonitorInfo

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

the class LocalThread method generateThreadStack.

private String generateThreadStack(ThreadInfo info) {
    // This is annoying, but the to string method on info sucks.
    StringBuilder result = new StringBuilder();
    result.append(info.getThreadName()).append(" ID=0x").append(Long.toHexString(info.getThreadId())).append("(").append(info.getThreadId()).append(") state=").append(info.getThreadState());
    if (info.getLockInfo() != null) {
        result.append("\n\twaiting to lock <" + info.getLockInfo() + ">");
    }
    for (StackTraceElement element : info.getStackTrace()) {
        result.append("\n\tat " + element);
        for (MonitorInfo monitor : info.getLockedMonitors()) {
            if (element.equals(monitor.getLockedStackFrame())) {
                result.append("\n\tlocked <" + monitor + ">");
            }
        }
    }
    if (info.getLockedSynchronizers().length > 0) {
        result.append("\nLocked synchronizers:");
        for (LockInfo sync : info.getLockedSynchronizers()) {
            result.append("\n" + sync.getClassName() + "@" + Integer.toHexString(sync.getIdentityHashCode()));
        }
    }
    return result.toString();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Example 40 with MonitorInfo

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

the class ThreadDumpProvider method getDumpThreadString.

protected String getDumpThreadString(ThreadInfo threadInfo) {
    StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState());
    if (threadInfo.getLockName() != null) {
        sb.append(" on " + threadInfo.getLockName());
    }
    if (threadInfo.getLockOwnerName() != null) {
        sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId());
    }
    if (threadInfo.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (threadInfo.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    int i = 0;
    StackTraceElement[] stackTrace = threadInfo.getStackTrace();
    for (; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && threadInfo.getLockInfo() != null) {
            Thread.State ts = threadInfo.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on " + threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + threadInfo.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : threadInfo.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    if (i < stackTrace.length) {
        sb.append("\t...");
        sb.append('\n');
    }
    LockInfo[] locks = threadInfo.getLockedSynchronizers();
    if (locks.length > 0) {
        sb.append("\n\tNumber of locked synchronizers = " + locks.length);
        sb.append('\n');
        for (LockInfo li : locks) {
            sb.append("\t- " + li);
            sb.append('\n');
        }
    }
    sb.append('\n');
    return sb.toString();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) 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