Search in sources :

Example 1 with ThreadObject

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);
}
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 ThreadObject

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

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

Example 4 with ThreadObject

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));
}
Also used : ThreadObject(com.creditease.uav.threadanalysis.server.da.ThreadObject) ArrayList(java.util.ArrayList) ThreadAnalyser(com.creditease.uav.threadanalysis.server.ThreadAnalyser) QueryBuilder(org.elasticsearch.index.query.QueryBuilder) RangeQueryBuilder(org.elasticsearch.index.query.RangeQueryBuilder) BoolQueryBuilder(org.elasticsearch.index.query.BoolQueryBuilder) HashMap(java.util.HashMap) Map(java.util.Map) SearchResponse(org.elasticsearch.action.search.SearchResponse)

Example 5 with ThreadObject

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

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