Search in sources :

Example 1 with DeadlockCycle

use of com.creditease.uav.threadanalysis.server.da.DeadlockCycle in project uavstack by uavorg.

the class ThreadAnalyser method queryDumpInfo.

/**
 * 查询快照概况
 *
 * @param records
 *            进程快照信息
 * @return json: {cpu: '50', threadCount: '123', runnableCount: '23', blockedCount: '34', waitingCount: '45',
 *         deadlock: []}
 */
public Map<String, Object> queryDumpInfo(List<Map<String, Object>> records) {
    List<ThreadObject> threads = parseThreads(records);
    float cpu = 0;
    int threadCount = threads.size();
    int runnableCount = 0;
    int blockedCount = 0;
    int waitingCount = 0;
    for (ThreadObject to : threads) {
        cpu += to.getCpu();
        if (to.getThreadState() == Thread.State.RUNNABLE) {
            runnableCount++;
        } else if (to.getThreadState() == Thread.State.BLOCKED) {
            blockedCount++;
        } else if (to.getThreadState() == Thread.State.WAITING || to.getThreadState() == Thread.State.TIMED_WAITING) {
            waitingCount++;
        }
    }
    Map<String, Object> map = new HashMap<>();
    map.put("cpu", cpu);
    map.put("threadCount", threadCount);
    map.put("runnableCount", runnableCount);
    map.put("blockedCount", blockedCount);
    map.put("waitingCount", waitingCount);
    ThreadDigraph digraph = new ThreadDigraph(parseThreads(records));
    DeadlockCycle cycle = new DeadlockCycle(digraph);
    if (cycle.hasCycle()) {
        List<String> list = new ArrayList<>();
        for (Integer i : cycle.cycle()) {
            list.add(digraph.thread(i).getInfo());
        }
        if (list.size() > 1) {
            list.remove(list.size() - 1);
        }
        map.put("deadlock", list);
    } else {
        map.put("deadlock", Collections.emptyList());
    }
    return map;
}
Also used : ThreadObject(com.creditease.uav.threadanalysis.server.da.ThreadObject) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ThreadDigraph(com.creditease.uav.threadanalysis.server.da.ThreadDigraph) DeadlockCycle(com.creditease.uav.threadanalysis.server.da.DeadlockCycle) MonitorObject(com.creditease.uav.threadanalysis.server.da.MonitorObject) ThreadObject(com.creditease.uav.threadanalysis.server.da.ThreadObject)

Aggregations

DeadlockCycle (com.creditease.uav.threadanalysis.server.da.DeadlockCycle)1 MonitorObject (com.creditease.uav.threadanalysis.server.da.MonitorObject)1 ThreadDigraph (com.creditease.uav.threadanalysis.server.da.ThreadDigraph)1 ThreadObject (com.creditease.uav.threadanalysis.server.da.ThreadObject)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1