Search in sources :

Example 56 with MonitorInfo

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

the class ThreadUtil method toString.

/**
 * Copy of ThreadInfo#toString() without the hardcoded MAX_FRAMES = 8 restriction on thread stack depth.
 *
 * Returns a string representation of this thread info.
 * The format of this string depends on the implementation.
 * The returned string will typically include
 * the thread name, the getThreadId thread ID, its state,
 * and a stack trace if any.
 *
 * @return a string representation of this thread info.
 */
private static String toString(ThreadInfo info) {
    StringBuilder sb = new StringBuilder("\"" + info.getThreadName() + "\"" + " Id=" + info.getThreadId() + " " + info.getThreadState());
    if (info.getLockName() != null) {
        sb.append(" on " + info.getLockName());
    }
    if (info.getLockOwnerName() != null) {
        sb.append(" owned by \"" + info.getLockOwnerName() + "\" Id=" + info.getLockOwnerId());
    }
    if (info.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (info.isInNative()) {
        sb.append(" (in native)");
    }
    sb.append('\n');
    int i = 0;
    for (; i < info.getStackTrace().length; i++) {
        StackTraceElement ste = info.getStackTrace()[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && info.getLockInfo() != null) {
            Thread.State ts = info.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + info.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on " + info.getLockInfo());
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + info.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : info.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
    if (i < info.getStackTrace().length) {
        sb.append("\t...");
        sb.append('\n');
    }
    LockInfo[] locks = info.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)

Example 57 with MonitorInfo

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

the class SynchronizationTest method printStacktrace.

private static void printStacktrace(ThreadInfo info, StringBuilder sb) {
    StackTraceElement[] stackTrace = info.getStackTrace();
    int i = 0;
    // This is a copy of ThreadInfo::toString but with an unlimited number of frames shown.
    for (; i < stackTrace.length; i++) {
        StackTraceElement ste = stackTrace[i];
        sb.append("\tat " + ste.toString());
        sb.append('\n');
        if (i == 0 && info.getLockInfo() != null) {
            Thread.State ts = info.getThreadState();
            switch(ts) {
                case BLOCKED:
                    sb.append("\t-  blocked on " + info.getLockInfo());
                    sb.append('\n');
                    break;
                case WAITING:
                    sb.append("\t-  waiting on " + info.getLockInfo());
                    sb.append('\n');
                    break;
                case TIMED_WAITING:
                    sb.append("\t-  waiting on " + info.getLockInfo());
                    sb.append('\n');
                    break;
                default:
            }
        }
        for (MonitorInfo mi : info.getLockedMonitors()) {
            if (mi.getLockedStackDepth() == i) {
                sb.append("\t-  locked " + mi);
                sb.append('\n');
            }
        }
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo)

Example 58 with MonitorInfo

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

the class ThreadDumpUtils method setMonitorInfo.

private static void setMonitorInfo(ThreadDumpMetricSnapshot threadDump, ThreadInfo threadInfo) {
    MonitorInfo[] monitorInfos = threadInfo.getLockedMonitors();
    if (monitorInfos != null) {
        for (MonitorInfo each : monitorInfos) {
            if (each == null) {
                continue;
            }
            MonitorInfoMetricSnapshot monitorInfoMetricSnapshot = new MonitorInfoMetricSnapshot();
            monitorInfoMetricSnapshot.setStackDepth(each.getLockedStackDepth());
            monitorInfoMetricSnapshot.setStackFrame(each.getLockedStackFrame().toString());
            threadDump.addLockedMonitor(monitorInfoMetricSnapshot);
        }
    } else {
        threadDump.setLockedMonitors(Collections.<MonitorInfoMetricSnapshot>emptyList());
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) MonitorInfoMetricSnapshot(com.navercorp.pinpoint.profiler.monitor.metric.deadlock.MonitorInfoMetricSnapshot)

Example 59 with MonitorInfo

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

the class ThreadDumpService method toTThreadDump.

private TThreadDump toTThreadDump(ThreadInfo info) {
    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());
    }
    return dump;
}
Also used : TMonitorInfo(com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo) MonitorInfo(java.lang.management.MonitorInfo) TMonitorInfo(com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo) TThreadDump(com.navercorp.pinpoint.thrift.dto.command.TThreadDump) LockInfo(java.lang.management.LockInfo)

Example 60 with MonitorInfo

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

the class AgentEventMessageSerDesTest method createTThreadDump.

private TThreadDump createTThreadDump(ThreadInfo info) {
    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());
    }
    return dump;
}
Also used : TMonitorInfo(com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo) MonitorInfo(java.lang.management.MonitorInfo) TMonitorInfo(com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo) TThreadDump(com.navercorp.pinpoint.thrift.dto.command.TThreadDump) LockInfo(java.lang.management.LockInfo)

Aggregations

MonitorInfo (java.lang.management.MonitorInfo)78 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