use of com.shulie.instrument.simulator.module.model.thread.ThreadInfo in project LinkAgent by shulieTech.
the class PerfPlugin method info.
@Command("info")
public CommandResponse info(Map<String, String> args) {
try {
CommandResponse<List<ThreadInfo>> threadResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_THREAD, PerfConstants.MODULE_COMMAND_THREAD_INFO, threadParams);
CommandResponse<GcInfo> gcResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_GC, PerfConstants.MODULE_COMMAND_GC_INFO);
CommandResponse<MemoryInfo> memoryResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_MEMORY, PerfConstants.MODULE_COMMAND_MEMORY_INFO);
List<ThreadInfo> threadInfos = Collections.EMPTY_LIST;
if (!threadResp.isSuccess()) {
logger.error("Perf: collect perf thread info err! {}", threadResp.getMessage());
} else {
threadInfos = threadResp.getResult();
}
GcInfo gcInfo = null;
if (!gcResp.isSuccess()) {
logger.error("Perf: collect perf gc info err! {}", gcResp.getMessage());
} else {
gcInfo = gcResp.getResult();
}
MemoryInfo memoryInfo = null;
if (!memoryResp.isSuccess()) {
logger.error("Perf: collect perf memory info err! {}", memoryResp.getMessage());
} else {
memoryInfo = memoryResp.getResult();
}
PerfResponse response = PerfResponseBuilder.build(threadInfos, gcInfo, memoryInfo);
return CommandResponse.success(response);
} catch (Throwable e) {
logger.error("Perf: collect perf data occurred a unknow error. ", e);
return CommandResponse.failure(e);
}
}
use of com.shulie.instrument.simulator.module.model.thread.ThreadInfo in project LinkAgent by shulieTech.
the class PerfPlugin method collect.
private void collect() {
CommandResponse<List<ThreadInfo>> threadResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_THREAD, PerfConstants.MODULE_COMMAND_THREAD_INFO, threadParams);
CommandResponse<GcInfo> gcResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_GC, PerfConstants.MODULE_COMMAND_GC_INFO);
CommandResponse<MemoryInfo> memoryResp = moduleCommandInvoker.invokeCommand(PerfConstants.MODULE_ID_MEMORY, PerfConstants.MODULE_COMMAND_MEMORY_INFO);
List<ThreadInfo> threadInfos = Collections.EMPTY_LIST;
if (!threadResp.isSuccess()) {
logger.error("Perf: collect perf thread info err! {}", threadResp.getMessage());
} else {
threadInfos = threadResp.getResult();
}
GcInfo gcInfo = null;
if (!gcResp.isSuccess()) {
logger.error("Perf: collect perf gc info err! {}", gcResp.getMessage());
} else {
gcInfo = gcResp.getResult();
}
MemoryInfo memoryInfo = null;
if (!memoryResp.isSuccess()) {
logger.error("Perf: collect perf memory info err! {}", memoryResp.getMessage());
} else {
memoryInfo = memoryResp.getResult();
}
PerfResponse response = PerfResponseBuilder.build(threadInfos, gcInfo, memoryInfo);
push(response);
}
use of com.shulie.instrument.simulator.module.model.thread.ThreadInfo 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;
}
Aggregations