Search in sources :

Example 6 with ThreadObject

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;
}
Also used : ThreadObject(com.creditease.uav.threadanalysis.server.da.ThreadObject)

Example 7 with ThreadObject

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;
}
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) MonitorObject(com.creditease.uav.threadanalysis.server.da.MonitorObject) ThreadObject(com.creditease.uav.threadanalysis.server.da.ThreadObject) HashMap(java.util.HashMap) Map(java.util.Map) MonitorObject(com.creditease.uav.threadanalysis.server.da.MonitorObject)

Aggregations

ThreadObject (com.creditease.uav.threadanalysis.server.da.ThreadObject)7 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 ThreadDigraph (com.creditease.uav.threadanalysis.server.da.ThreadDigraph)4 Map (java.util.Map)4 MonitorObject (com.creditease.uav.threadanalysis.server.da.MonitorObject)3 ThreadChain (com.creditease.uav.threadanalysis.server.da.ThreadChain)2 ThreadAnalyser (com.creditease.uav.threadanalysis.server.ThreadAnalyser)1 DeadlockCycle (com.creditease.uav.threadanalysis.server.da.DeadlockCycle)1 SearchResponse (org.elasticsearch.action.search.SearchResponse)1 BoolQueryBuilder (org.elasticsearch.index.query.BoolQueryBuilder)1 QueryBuilder (org.elasticsearch.index.query.QueryBuilder)1 RangeQueryBuilder (org.elasticsearch.index.query.RangeQueryBuilder)1