private static void parseThreadInfo()

in src/main/java/org/opensearch/performanceanalyzer/jvm/ThreadList.java [250:308]


    private static void parseThreadInfo(final ThreadInfo info) {
        long id = info.getThreadId();
        String name = info.getThreadName();
        Thread.State state = info.getThreadState();

        // following captures cumulative allocated bytes + TLAB used bytes
        // and it is cumulative
        long mem = ((com.sun.management.ThreadMXBean) threadBean).getThreadAllocatedBytes(id);

        ThreadState t = jTidMap.get(id);
        if (t == null) {
            return;
        }
        t.heapUsage = mem;
        t.state = state;
        t.blockedCount = info.getBlockedCount();
        t.blockedTime = info.getBlockedTime();
        t.waitedCount = info.getWaitedCount();
        t.waitedTime = info.getWaitedTime();
        ThreadHistory.addBlocked(
                t.nativeTid, (state == Thread.State.BLOCKED) ? samplingInterval : 0);
        ThreadHistory.addWaited(
                t.nativeTid,
                (state == Thread.State.WAITING || state == Thread.State.TIMED_WAITING)
                        ? samplingInterval
                        : 0);

        long curRunTime = System.currentTimeMillis();
        ThreadState oldt = oldNativeTidMap.get(t.nativeTid);
        if (curRunTime > lastRunTime && oldt != null) {
            t.heapAllocRate =
                    Math.max(t.heapUsage - oldt.heapUsage, 0) * 1.0e3 / (curRunTime - lastRunTime);
            if (t.blockedTime != -1 && t.blockedCount > oldt.blockedCount) {
                t.avgBlockedTime =
                        1.0e-3
                                * (t.blockedTime - oldt.blockedTime)
                                / (t.blockedCount - oldt.blockedCount);
            } else {
                CircularLongArray arr = ThreadHistory.blockedTidHistoryMap.get(t.nativeTid);
                // NOTE: this is an upper bound
                if (arr != null) {
                    t.avgBlockedTime = 1.0 * arr.getAvgValue() / samplingInterval;
                }
            }
            if (t.waitedTime != -1 && t.waitedCount > oldt.waitedCount) {
                t.avgWaitedTime =
                        1.0e-3
                                * (t.waitedTime - oldt.waitedTime)
                                / (t.waitedCount - oldt.waitedCount);
            } else {
                CircularLongArray arr = ThreadHistory.waitedTidHistoryMap.get(t.nativeTid);
                // NOTE: this is an upper bound
                if (arr != null) {
                    t.avgWaitedTime = 1.0 * arr.getAvgValue() / samplingInterval;
                }
            }
        }
        jTidNameMap.put(id, name);
    }