use of com.creditease.uav.threadanalysis.server.da.ThreadObject in project uavstack by uavorg.
the class ThreadAnalyser method parseThread.
private ThreadObject parseThread(Map<String, Object> map) {
ThreadObject to = new ThreadObject();
String info = (String) map.get("info");
String[] thread = info.split("\n");
extractFromTitle(thread[0], to);
extractStackTrace(thread, to);
to.setInfo(info);
String percpu = map.get("percpu").toString();
to.setCpu(DataConvertHelper.toDouble(percpu, 0));
to.setTime(DataConvertHelper.toLong(map.get("time").toString(), 0));
return to;
}
use of com.creditease.uav.threadanalysis.server.da.ThreadObject in project uavstack by uavorg.
the class ThreadAnalyser method buildThreadDigraph.
/**
* 构建线程有向图
*
* @param record
* @return {nodes: [{id:0, name:'', type: '', state: ''}], edges: [{from:0, to:1}]}
*/
public Map<String, Object> buildThreadDigraph(List<Map<String, Object>> records) {
List<ThreadObject> threads = parseThreads(records);
ThreadDigraph digraph = new ThreadDigraph(threads);
List<String> tKeys = digraph.getThreadKeys();
List<String> mKeys = new ArrayList<>(digraph.getMonitorMapping().keySet());
Map<String, Integer> st = new HashMap<>(digraph.getThreadTable());
int idx = tKeys.size();
for (String mo : mKeys) {
st.put(mo, Integer.valueOf(idx++));
}
List<Map<String, Object>> nodes = new ArrayList<>();
List<Map<String, Integer>> edges = new ArrayList<>();
for (String tk : tKeys) {
ThreadObject t = digraph.getThreadMapping().get(tk);
Map<String, Object> node = new HashMap<>();
node.put("id", st.get(tk));
node.put("name", t.getName());
node.put("type", "Thread");
node.put("tip", t.getInfo().split("\n")[0]);
node.put("msg", t.getInfo());
if (t.getThreadState() != null) {
node.put("state", t.getThreadState());
}
nodes.add(node);
MonitorObject pm = t.getPendingMonitor();
if (pm != null) {
Map<String, Integer> edge = new HashMap<>();
edge.put("from", st.get(tk));
edge.put("to", st.get(pm.getId()));
// from thread to pending lock
edges.add(edge);
}
List<MonitorObject> oms = t.getLockedMonitors();
if (oms != null && !oms.isEmpty()) {
for (MonitorObject om : oms) {
Map<String, Integer> edge = new HashMap<>();
edge.put("from", st.get(om.getId()));
edge.put("to", st.get(tk));
// from own lock to thread
edges.add(edge);
}
}
}
for (String mk : mKeys) {
MonitorObject mo = digraph.getMonitorMapping().get(mk);
Map<String, Object> node = new HashMap<>();
node.put("id", st.get(mk));
node.put("name", mo.getObj());
node.put("type", "Lock");
node.put("tip", mo.getState() + " <" + mo.getId() + "> " + mo.getObj());
nodes.add(node);
}
Map<String, Object> map = new HashMap<>();
map.put("nodes", nodes);
map.put("edges", edges);
return map;
}
Aggregations