Search in sources :

Example 1 with MonitorObject

use of com.creditease.uav.threadanalysis.server.da.MonitorObject in project uavstack by uavorg.

the class ThreadAnalyser method parseMonitor.

private MonitorObject parseMonitor(String monitor) {
    MonitorObject mo = new MonitorObject();
    Matcher matcher = PATTERN_LOCK.matcher(monitor);
    if (matcher.find()) {
        mo.setId(matcher.group(1));
        mo.setObj(monitor.substring(matcher.end(), monitor.length()).trim());
    }
    mo.setState(forMonitorState(monitor));
    return mo;
}
Also used : Matcher(java.util.regex.Matcher) MonitorObject(com.creditease.uav.threadanalysis.server.da.MonitorObject)

Example 2 with MonitorObject

use of com.creditease.uav.threadanalysis.server.da.MonitorObject in project uavstack by uavorg.

the class ThreadAnalyser method extractStackTrace.

private void extractStackTrace(String[] thread, ThreadObject to) {
    if (thread.length <= 1) {
        List<String> list = Collections.emptyList();
        to.setStackTrace(list);
        return;
    }
    if (thread[1].trim().startsWith("java.lang.Thread.State:")) {
        String line = thread[1].trim();
        int low = "java.lang.Thread.State: ".length();
        int high = line.indexOf(" ", low);
        if (high <= low) {
            high = line.length();
        }
        to.setThreadState(java.lang.Thread.State.valueOf(line.substring(low, high)));
    }
    List<String> stacktrace = new ArrayList<>();
    List<MonitorObject> ownMonitor = new ArrayList<>();
    for (int i = 2; i < thread.length; i++) {
        String method = thread[i].trim();
        if (method.startsWith("-")) {
            MonitorObject mo = parseMonitor(method);
            switch(mo.getState()) {
                case LOCKING:
                    ownMonitor.add(mo);
                    break;
                case BLOCKING:
                case WAITING:
                case PARKING:
                    to.setPendingMonitor(mo);
                    break;
                default:
                    break;
            }
            continue;
        }
        stacktrace.add(method);
    }
    to.setLockedMonitors(ownMonitor);
    to.setStackTrace(stacktrace);
}
Also used : ArrayList(java.util.ArrayList) MonitorObject(com.creditease.uav.threadanalysis.server.da.MonitorObject)

Example 3 with MonitorObject

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

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