Search in sources :

Example 1 with ThreadState

use of com.navercorp.pinpoint.common.server.bo.event.ThreadState in project pinpoint by naver.

the class ThreadDumpUtils method createDumpMessage.

public static String createDumpMessage(ThreadDumpBo threadDump) {
    ThreadState threadState = getThreadState(threadDump.getThreadState());
    // set threadName
    StringBuilder message = new StringBuilder("\"" + threadDump.getThreadName() + "\"");
    // set threadId
    String hexStringThreadId = Long.toHexString(threadDump.getThreadId());
    message.append(" Id=0x" + hexStringThreadId);
    // set threadState
    message.append(" " + threadState.name());
    if (!StringUtils.isBlank(threadDump.getLockName())) {
        message.append(" on ").append(threadDump.getLockName());
    }
    if (!StringUtils.isBlank(threadDump.getLockOwnerName())) {
        message.append(" owned by \"").append(threadDump.getLockOwnerName()).append("\" Id=").append(threadDump.getLockOwnerId());
    }
    if (threadDump.isSuspended()) {
        message.append(" (suspended)");
    }
    if (threadDump.isInNative()) {
        message.append(" (in native)");
    }
    message.append(LINE_SEPARATOR);
    // set StackTrace
    final int stackTraceSize = threadDump.getStackTraceList().size();
    for (int i = 0; i < stackTraceSize; i++) {
        final String stackTrace = threadDump.getStackTraceList().get(i);
        message.append(TAB_SEPARATOR + "at ").append(stackTrace);
        message.append(LINE_SEPARATOR);
        if (i == 0 && !StringUtils.isBlank(threadDump.getLockName())) {
            switch(threadState) {
                case BLOCKED:
                    message.append(TAB_SEPARATOR + "-  blocked on ").append(threadDump.getLockName());
                    message.append(LINE_SEPARATOR);
                    break;
                case WAITING:
                    message.append(TAB_SEPARATOR + "-  waiting on ").append(threadDump.getLockName());
                    message.append(LINE_SEPARATOR);
                    break;
                case TIMED_WAITING:
                    message.append(TAB_SEPARATOR + "-  waiting on ").append(threadDump.getLockName());
                    message.append(LINE_SEPARATOR);
                    break;
                default:
            }
        }
        if (CollectionUtils.hasLength(threadDump.getLockedMonitorInfoList())) {
            for (MonitorInfoBo lockedMonitor : threadDump.getLockedMonitorInfoList()) {
                if (lockedMonitor.getStackDepth() == i) {
                    message.append(TAB_SEPARATOR + "-  locked ").append(lockedMonitor.getStackFrame());
                    message.append(LINE_SEPARATOR);
                }
            }
        }
    }
    // set Locks
    List<String> lockedSynchronizerList = threadDump.getLockedSynchronizerList();
    if (CollectionUtils.hasLength(lockedSynchronizerList)) {
        message.append(LINE_SEPARATOR + TAB_SEPARATOR + "Number of locked synchronizers = ").append(lockedSynchronizerList.size());
        message.append(LINE_SEPARATOR);
        for (String lockedSynchronizer : lockedSynchronizerList) {
            message.append(TAB_SEPARATOR + "- ").append(lockedSynchronizer);
            message.append(LINE_SEPARATOR);
        }
    }
    message.append(LINE_SEPARATOR);
    return message.toString();
}
Also used : MonitorInfoBo(com.navercorp.pinpoint.common.server.bo.event.MonitorInfoBo) TThreadState(com.navercorp.pinpoint.thrift.dto.command.TThreadState) ThreadState(com.navercorp.pinpoint.common.server.bo.event.ThreadState)

Aggregations

MonitorInfoBo (com.navercorp.pinpoint.common.server.bo.event.MonitorInfoBo)1 ThreadState (com.navercorp.pinpoint.common.server.bo.event.ThreadState)1 TThreadState (com.navercorp.pinpoint.thrift.dto.command.TThreadState)1