Search in sources :

Example 1 with MemoryInfo

use of com.shulie.instrument.simulator.module.model.memory.MemoryInfo 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);
    }
}
Also used : MemoryInfo(com.shulie.instrument.simulator.module.model.memory.MemoryInfo) PerfResponse(com.shulie.instrument.simulator.perf.entity.PerfResponse) ThreadInfo(com.shulie.instrument.simulator.module.model.thread.ThreadInfo) GcInfo(com.shulie.instrument.simulator.module.model.gc.GcInfo) List(java.util.List) Command(com.shulie.instrument.simulator.api.annotation.Command)

Example 2 with MemoryInfo

use of com.shulie.instrument.simulator.module.model.memory.MemoryInfo 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);
}
Also used : MemoryInfo(com.shulie.instrument.simulator.module.model.memory.MemoryInfo) PerfResponse(com.shulie.instrument.simulator.perf.entity.PerfResponse) ThreadInfo(com.shulie.instrument.simulator.module.model.thread.ThreadInfo) GcInfo(com.shulie.instrument.simulator.module.model.gc.GcInfo) List(java.util.List)

Example 3 with MemoryInfo

use of com.shulie.instrument.simulator.module.model.memory.MemoryInfo in project LinkAgent by shulieTech.

the class MemoryModule method info.

@Command(value = "info", description = "内存信息")
public CommandResponse info(final Map<String, String> args) {
    try {
        List<MemoryPoolMXBean> memoryPoolMXBeans = ManagementFactory.getMemoryPoolMXBeans();
        MemoryInfo memoryInfo = new MemoryInfo();
        // heap
        MemoryUsage heapMemoryUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
        memoryInfo.setHeapMemory(createMemoryEntry(TYPE_HEAP, heapMemoryUsage));
        List<MemoryEntry> heapMemEntries = new ArrayList<MemoryEntry>();
        for (MemoryPoolMXBean poolMXBean : memoryPoolMXBeans) {
            if (MemoryType.HEAP.equals(poolMXBean.getType())) {
                MemoryUsage usage = poolMXBean.getUsage();
                heapMemEntries.add(createMemoryEntry(poolMXBean.getName(), usage));
            }
        }
        memoryInfo.setHeapMemories(heapMemEntries);
        // non-heap
        MemoryUsage nonHeapMemoryUsage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();
        List<MemoryEntry> nonheapMemEntries = new ArrayList<MemoryEntry>();
        memoryInfo.setNonheapMemory(createMemoryEntry(TYPE_NON_HEAP, nonHeapMemoryUsage));
        for (MemoryPoolMXBean poolMXBean : memoryPoolMXBeans) {
            if (MemoryType.NON_HEAP.equals(poolMXBean.getType())) {
                MemoryUsage usage = poolMXBean.getUsage();
                nonheapMemEntries.add(createMemoryEntry(poolMXBean.getName(), usage));
            }
        }
        memoryInfo.setNonheapMemories(nonheapMemEntries);
        memoryInfo.setBufferPoolMemories(getBufferPoolMemoryInfo());
        return CommandResponse.success(memoryInfo);
    } catch (Throwable e) {
        return CommandResponse.failure(e);
    }
}
Also used : MemoryInfo(com.shulie.instrument.simulator.module.model.memory.MemoryInfo) MemoryEntry(com.shulie.instrument.simulator.module.model.memory.MemoryEntry) ArrayList(java.util.ArrayList) Command(com.shulie.instrument.simulator.api.annotation.Command)

Aggregations

MemoryInfo (com.shulie.instrument.simulator.module.model.memory.MemoryInfo)3 Command (com.shulie.instrument.simulator.api.annotation.Command)2 GcInfo (com.shulie.instrument.simulator.module.model.gc.GcInfo)2 ThreadInfo (com.shulie.instrument.simulator.module.model.thread.ThreadInfo)2 PerfResponse (com.shulie.instrument.simulator.perf.entity.PerfResponse)2 List (java.util.List)2 MemoryEntry (com.shulie.instrument.simulator.module.model.memory.MemoryEntry)1 ArrayList (java.util.ArrayList)1