use of com.creditease.uav.threadanalysis.server.da.ThreadObject in project uavstack by uavorg.
the class ThreadAnalyser method findThreadChain.
/**
* 查找线程依赖
*
* @param record
* @param threadId
* @return
*/
public List<ThreadObject> findThreadChain(List<Map<String, Object>> record, String threadId) {
ThreadDigraph digraph = new ThreadDigraph(parseThreads(record));
ThreadChain chain = new ThreadChain(digraph);
ThreadObject thread = digraph.thread(threadId);
return chain.getChain(thread);
}
use of com.creditease.uav.threadanalysis.server.da.ThreadObject in project uavstack by uavorg.
the class ThreadAnalyser method queryMutilDumpGraph.
/**
* @param threadIds
* @param records
* @return
*/
public Map<String, Object> queryMutilDumpGraph(List<String> threadIds, List<List<Map<String, Object>>> records) {
List<ThreadDigraph> dumps = new ArrayList<>();
for (List<Map<String, Object>> record : records) {
List<ThreadObject> threads = parseThreads(record);
dumps.add(new ThreadDigraph(threads));
}
List<Map<String, Object>> nodes = new ArrayList<>();
List<Map<String, Object>> edges = new ArrayList<>();
for (String threadId : threadIds) {
String timeSeries = null;
for (ThreadDigraph tg : dumps) {
ThreadChain threadChain = new ThreadChain(tg);
ThreadObject thread = tg.thread(threadId);
List<ThreadObject> chain = threadChain.getChain(thread);
if (chain == null) {
continue;
}
String from = null;
for (ThreadObject to : chain) {
String id = to.getId() + "_" + to.getTime();
Map<String, Object> node = new HashMap<>();
node.put("id", id);
node.put("name", DateTimeHelper.toStandardDateFormat(to.getTime()) + "\n" + to.getName());
node.put("type", "Thread");
node.put("tip", to.getInfo().split("\n")[0]);
node.put("msg", to.getInfo());
if (to.getThreadState() != null) {
node.put("state", to.getThreadState().toString());
}
nodes.add(node);
if (from != null) {
Map<String, Object> edge = new HashMap<>();
edge.put("from", from);
edge.put("to", id);
edges.add(edge);
}
from = id;
}
ThreadObject ts = chain.get(0);
if (timeSeries == null) {
timeSeries = ts.getId() + "_" + ts.getTime();
} else {
String nextTimeSeries = ts.getId() + "_" + ts.getTime();
Map<String, Object> edge = new HashMap<>();
edge.put("from", timeSeries);
edge.put("to", nextTimeSeries);
edge.put("dashes", true);
edges.add(edge);
timeSeries = nextTimeSeries;
}
}
}
Map<String, Object> graph = new HashMap<>();
graph.put("nodes", nodes);
graph.put("edges", edges);
return graph;
}
use of com.creditease.uav.threadanalysis.server.da.ThreadObject in project uavstack by uavorg.
the class ThreadAnalyser method queryMutilDumpInfo.
/**
* @param head
* @param records
* @return
*/
public List<Map<String, String>> queryMutilDumpInfo(List<String> head, List<List<Map<String, Object>>> records) {
List<Map<String, String>> list = new ArrayList<>();
Map<String, ThreadObject> base = parseThreadMapping(parseThreads(records.get(0)));
List<Map<String, ThreadObject>> subsequents = new ArrayList<>();
for (int i = 1; i < records.size(); i++) {
subsequents.add(parseThreadMapping(parseThreads(records.get(i))));
}
Map<String, String> line = null;
for (Map.Entry<String, ThreadObject> entry : base.entrySet()) {
line = new HashMap<>();
String threadId = entry.getKey();
line.put("thread", threadId);
line.put(head.get(0), JSONHelper.toString(entry.getValue()));
int headIdx = 1;
for (Map<String, ThreadObject> subsequent : subsequents) {
ThreadObject thread = subsequent.get(threadId);
if (thread == null) {
line.put(head.get(headIdx), "");
} else {
line.put(head.get(headIdx), JSONHelper.toString(thread));
}
headIdx++;
}
list.add(line);
}
return list;
}
use of com.creditease.uav.threadanalysis.server.da.ThreadObject in project uavstack by uavorg.
the class ThreadAnalysisQueryHandler method queryThreadChain.
/**
* 查找线程依赖
*
* @param data
*/
private void queryThreadChain(UAVHttpMessage data) {
QueryBuilder query = buildQuery(data);
if (query == null) {
return;
}
SearchResponse sr = query(data, query, null, buildSorts(data));
List<Map<String, Object>> records = getRecords(sr);
String threadId = data.getRequest("threadId");
ThreadAnalyser ta = (ThreadAnalyser) getConfigManager().getComponent(feature, "ThreadAnalyser");
List<ThreadObject> chain = ta.findThreadChain(records, threadId);
List<String> infoChain = new ArrayList<>();
for (ThreadObject to : chain) {
infoChain.add(to.getInfo());
}
data.putResponse("rs", JSONHelper.toString(infoChain));
}
use of com.creditease.uav.threadanalysis.server.da.ThreadObject 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