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;
}
Aggregations