Search in sources :

Example 1 with ThreadVO

use of com.shulie.instrument.simulator.perf.entity.ThreadVO in project LinkAgent by shulieTech.

the class PerfResponseBuilder method build.

public static PerfResponse build(List<ThreadInfo> threadInfoList, GcInfo gcInfo, MemoryInfo memoryInfo) {
    PerfResponse response = new PerfResponse();
    response.setAgentId(Pradar.AGENT_ID_NOT_CONTAIN_USER_INFO);
    response.setAppIp(PradarCoreUtils.getLocalAddress());
    response.setAppName(AppNameUtils.appName());
    response.setProcessId(RuntimeUtils.getPid());
    response.setTimestamp(System.currentTimeMillis());
    if (gcInfo != null) {
        response.setFullGcCost(gcInfo.getOldGcTime());
        response.setFullGcCount(gcInfo.getOldGcCount());
        response.setYoungGcCost(gcInfo.getYoungGcTime());
        response.setYoungGcCount(gcInfo.getYoungGcCount());
    }
    if (memoryInfo != null) {
        response.setTotalMemory(memoryInfo.getHeapMemory().getTotal() + memoryInfo.getNonheapMemory().getTotal());
        long youngMemoryUsed = 0L;
        long youngMemoryTotal = 0L;
        long oldMemoryUsed = 0L;
        long oldMemoryTotal = 0L;
        // TODO 目前这块兼容的是 jdk8及以上版本,还需要兼容 jdk8以下版本和其他版本的 jdk
        for (MemoryEntry memoryEntry : memoryInfo.getHeapMemories()) {
            String poolName = beautifyName(memoryEntry.getName());
            if (poolName.equals("ps_eden_space") || poolName.equals("ps_survivor_space") || poolName.equals("eden_space") || poolName.equals("survivor_space") || poolName.equals("g1_eden_space") || poolName.equals("g1_survivor_space") || poolName.equals("par_eden_space") || poolName.equals("par_survivor_space")) {
                youngMemoryUsed = youngMemoryUsed + memoryEntry.getUsed();
                youngMemoryTotal = youngMemoryTotal + memoryEntry.getMax();
            } else if (poolName.equals("ps_old_gen") || poolName.equals("tenured_gen") || poolName.equals("g1_old_gen") || poolName.equals("cms_old_gen")) {
                oldMemoryUsed = oldMemoryUsed + memoryEntry.getUsed();
                oldMemoryTotal = oldMemoryTotal + memoryEntry.getMax();
            } else {
                LOGGER.warn("unknown poolname is {}", poolName);
            }
        }
        response.setYoungMemory(youngMemoryUsed);
        response.setTotalYoung(youngMemoryTotal);
        response.setOldMemory(oldMemoryUsed);
        response.setTotalOld(oldMemoryTotal);
        response.setTotalNonHeapMemory(memoryInfo.getNonheapMemory() == null ? 0L : memoryInfo.getNonheapMemory().getTotal());
        long totalBufferPoolMemory = 0L;
        for (MemoryEntry entry : memoryInfo.getBufferPoolMemories()) {
            totalBufferPoolMemory += entry.getTotal();
        }
        response.setTotalBufferPoolMemory(totalBufferPoolMemory);
        long permMemoryUsed = 0L;
        long permMemoryTotal = 0L;
        for (MemoryEntry memoryEntry : memoryInfo.getNonheapMemories()) {
            String poolName = beautifyName(memoryEntry.getName());
            // TODO 目前这块兼容的是 jdk8及以上版本,还需要兼容 jdk8以下版本和其他版本的 jdk
            if (StringUtils.equalsIgnoreCase(poolName, "metaspace")) {
                permMemoryTotal = memoryEntry.getMax();
                permMemoryUsed = memoryEntry.getUsed();
            }
        }
        response.setPermMemory(permMemoryUsed);
        response.setTotalPerm(permMemoryTotal);
        response.setHeapMemory(memoryInfo.getHeapMemory());
        response.setHeapMemories(memoryInfo.getHeapMemories());
        response.setNonheapMemory(memoryInfo.getNonheapMemory());
        response.setNonheapMemories(memoryInfo.getNonheapMemories());
        response.setBufferPoolMemories(memoryInfo.getBufferPoolMemories());
    }
    if (CollectionUtils.isNotEmpty(threadInfoList)) {
        List<ThreadVO> threadVOS = new ArrayList<ThreadVO>(threadInfoList.size());
        for (ThreadInfo threadInfo : threadInfoList) {
            ThreadVO threadVO = new ThreadVO();
            threadVO.setThreadId(threadInfo.getId());
            threadVO.setThreadName(threadInfo.getName());
            threadVO.setGroupName(threadInfo.getGroupName());
            threadVO.setThreadCpuUsage(threadInfo.getCpuUsage());
            threadVO.setCpuTime(threadInfo.getCpuTime());
            threadVO.setInterrupted(threadInfo.isInterrupted());
            threadVO.setThreadStatus(threadInfo.getState());
            threadVO.setLockName(threadInfo.getLockName());
            threadVO.setLockOwnerName(threadInfo.getLockOwnerName());
            threadVO.setLockOwnerId(threadInfo.getLockOwnerId());
            threadVO.setSuspended(threadInfo.isSuspended());
            threadVO.setInNative(threadInfo.isInNative());
            threadVO.setDaemon(threadInfo.isDaemon());
            threadVO.setPriority(threadInfo.getPriority());
            threadVO.setBlockedTime(threadInfo.getBlockedTime());
            threadVO.setBlockedCount(threadInfo.getBlockedCount());
            threadVO.setWaitedCount(threadInfo.getWaitedCount());
            threadVO.setWaitedTime(threadInfo.getWaitedTime());
            threadVO.setThreadStack(getThreadStackInfo(threadInfo.getThreadStacks()));
            threadVO.setLockIdentityHashCode(threadInfo.getLockIdentityHashCode());
            threadVO.setBlockingThreadCount(threadInfo.getBlockingThreadCount());
            threadVO.setTraceId(threadInfo.getTraceId());
            threadVO.setRpcId(threadInfo.getRpcId());
            threadVO.setClusterTest(threadInfo.isClusterTest());
            threadVOS.add(threadVO);
        }
        response.setThreadDataList(threadVOS);
    }
    return response;
}
Also used : PerfResponse(com.shulie.instrument.simulator.perf.entity.PerfResponse) ThreadVO(com.shulie.instrument.simulator.perf.entity.ThreadVO) ThreadInfo(com.shulie.instrument.simulator.module.model.thread.ThreadInfo) MemoryEntry(com.shulie.instrument.simulator.module.model.memory.MemoryEntry) ArrayList(java.util.ArrayList)

Aggregations

MemoryEntry (com.shulie.instrument.simulator.module.model.memory.MemoryEntry)1 ThreadInfo (com.shulie.instrument.simulator.module.model.thread.ThreadInfo)1 PerfResponse (com.shulie.instrument.simulator.perf.entity.PerfResponse)1 ThreadVO (com.shulie.instrument.simulator.perf.entity.ThreadVO)1 ArrayList (java.util.ArrayList)1