Search in sources :

Example 1 with ThreadDigraph

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

Example 2 with ThreadDigraph

use of com.creditease.uav.threadanalysis.server.da.ThreadDigraph 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;
}
Also used : ThreadObject(com.creditease.uav.threadanalysis.server.da.ThreadObject) ThreadChain(com.creditease.uav.threadanalysis.server.da.ThreadChain) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MonitorObject(com.creditease.uav.threadanalysis.server.da.MonitorObject) ThreadObject(com.creditease.uav.threadanalysis.server.da.ThreadObject) ThreadDigraph(com.creditease.uav.threadanalysis.server.da.ThreadDigraph) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with ThreadDigraph

use of com.creditease.uav.threadanalysis.server.da.ThreadDigraph 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)

Example 4 with ThreadDigraph

use of com.creditease.uav.threadanalysis.server.da.ThreadDigraph 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

ThreadDigraph (com.creditease.uav.threadanalysis.server.da.ThreadDigraph)4 ThreadObject (com.creditease.uav.threadanalysis.server.da.ThreadObject)4 MonitorObject (com.creditease.uav.threadanalysis.server.da.MonitorObject)3 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ThreadChain (com.creditease.uav.threadanalysis.server.da.ThreadChain)2 Map (java.util.Map)2 DeadlockCycle (com.creditease.uav.threadanalysis.server.da.DeadlockCycle)1