Search in sources :

Example 1 with TThreadState

use of com.navercorp.pinpoint.thrift.dto.command.TThreadState in project pinpoint by naver.

the class AgentActiveThreadDumpFactory method createDumpMessage.

public String createDumpMessage(TThreadDump threadDump) {
    TThreadState 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
    for (int i = 0; i < threadDump.getStackTraceSize(); i++) {
        String stackTrace = threadDump.getStackTrace().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 (threadDump.getLockedMonitors() != null) {
            for (TMonitorInfo lockedMonitor : threadDump.getLockedMonitors()) {
                if (lockedMonitor.getStackDepth() == i) {
                    message.append(TAB_SEPARATOR + "-  locked ").append(lockedMonitor.getStackFrame());
                    message.append(LINE_SEPARATOR);
                }
            }
        }
    }
    // set Locks
    List<String> lockedSynchronizers = threadDump.getLockedSynchronizers();
    if (!CollectionUtils.isEmpty(lockedSynchronizers)) {
        message.append(LINE_SEPARATOR + TAB_SEPARATOR + "Number of locked synchronizers = ").append(lockedSynchronizers.size());
        message.append(LINE_SEPARATOR);
        for (String lockedSynchronizer : lockedSynchronizers) {
            message.append(TAB_SEPARATOR + "- ").append(lockedSynchronizer);
            message.append(LINE_SEPARATOR);
        }
    }
    message.append(LINE_SEPARATOR);
    return message.toString();
}
Also used : TThreadState(com.navercorp.pinpoint.thrift.dto.command.TThreadState) TMonitorInfo(com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)

Example 2 with TThreadState

use of com.navercorp.pinpoint.thrift.dto.command.TThreadState in project pinpoint by naver.

the class AgentActiveThreadDumpListSerializer method serialize.

@Override
public void serialize(AgentActiveThreadDumpList agentActiveThreadDumpList, JsonGenerator jgen, SerializerProvider serializers) throws IOException, JsonProcessingException {
    List<AgentActiveThreadDump> agentActiveThreadDumpRepository = agentActiveThreadDumpList.getSortOldestAgentActiveThreadDumpRepository();
    jgen.writeStartArray();
    for (AgentActiveThreadDump agentActiveThreadDump : agentActiveThreadDumpRepository) {
        jgen.writeStartObject();
        String hexStringThreadId = Long.toHexString(agentActiveThreadDump.getThreadId());
        jgen.writeStringField("threadId", "0x" + hexStringThreadId);
        jgen.writeStringField("threadName", agentActiveThreadDump.getThreadName());
        TThreadState threadState = agentActiveThreadDump.getThreadState();
        if (threadState == null) {
            jgen.writeStringField("threadState", TThreadState.UNKNOWN.name());
        } else {
            jgen.writeStringField("threadState", agentActiveThreadDump.getThreadState().name());
        }
        jgen.writeNumberField("startTime", agentActiveThreadDump.getStartTime());
        jgen.writeNumberField("execTime", agentActiveThreadDump.getExecTime());
        jgen.writeNumberField("localTraceId", agentActiveThreadDump.getLocalTraceId());
        jgen.writeBooleanField("sampled", agentActiveThreadDump.isSampled());
        jgen.writeStringField("transactionId", agentActiveThreadDump.getTransactionId());
        jgen.writeStringField("entryPoint", agentActiveThreadDump.getEntryPoint());
        jgen.writeStringField("detailMessage", agentActiveThreadDump.getDetailMessage());
        jgen.writeEndObject();
    }
    jgen.writeEndArray();
}
Also used : TThreadState(com.navercorp.pinpoint.thrift.dto.command.TThreadState) AgentActiveThreadDump(com.navercorp.pinpoint.web.vo.AgentActiveThreadDump)

Aggregations

TThreadState (com.navercorp.pinpoint.thrift.dto.command.TThreadState)2 TMonitorInfo (com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)1 AgentActiveThreadDump (com.navercorp.pinpoint.web.vo.AgentActiveThreadDump)1