You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by GitBox <gi...@apache.org> on 2020/12/19 09:45:03 UTC

[GitHub] [incubator-doris] Dam1029 commented on a change in pull request #5110: [Enhancement] Add more comprehensive prometheus jvm thread metrics on fe

Dam1029 commented on a change in pull request #5110:
URL: https://github.com/apache/incubator-doris/pull/5110#discussion_r546217812



##########
File path: fe/fe-core/src/main/java/org/apache/doris/monitor/jvm/JvmStats.java
##########
@@ -82,7 +83,27 @@ public static JvmStats jvmStats() {
         }
         Mem mem = new Mem(heapCommitted, heapUsed, heapMax, nonHeapCommitted, nonHeapUsed,
                 Collections.unmodifiableList(pools));
-        Threads threads = new Threads(threadMXBean.getThreadCount(), threadMXBean.getPeakThreadCount());
+
+        int threadsNew = 0;
+        int threadsRunnable = 0;
+        int threadsBlocked = 0;
+        int threadsWaiting = 0;
+        int threadsTimedWaiting = 0;
+        int threadsTerminated = 0;
+        long threadIds[] = threadMXBean.getAllThreadIds();
+        for (ThreadInfo threadInfo : threadMXBean.getThreadInfo(threadIds, 0)) {
+            if (threadInfo == null) continue; // race protection
+            switch (threadInfo.getThreadState()) {
+                case NEW:           threadsNew++;           break;
+                case RUNNABLE:      threadsRunnable++;      break;
+                case BLOCKED:       threadsBlocked++;       break;
+                case WAITING:       threadsWaiting++;       break;
+                case TIMED_WAITING: threadsTimedWaiting++;  break;
+                case TERMINATED:    threadsTerminated++;    break;

Review comment:
       ```java
       public enum State {
           /**
            * Thread state for a thread which has not yet started.
            */
           NEW,
   
           /**
            * Thread state for a runnable thread.  A thread in the runnable
            * state is executing in the Java virtual machine but it may
            * be waiting for other resources from the operating system
            * such as processor.
            */
           RUNNABLE,
   
           /**
            * Thread state for a thread blocked waiting for a monitor lock.
            * A thread in the blocked state is waiting for a monitor lock
            * to enter a synchronized block/method or
            * reenter a synchronized block/method after calling
            * {@link Object#wait() Object.wait}.
            */
           BLOCKED,
   
           /**
            * Thread state for a waiting thread.
            * A thread is in the waiting state due to calling one of the
            * following methods:
            * <ul>
            *   <li>{@link Object#wait() Object.wait} with no timeout</li>
            *   <li>{@link #join() Thread.join} with no timeout</li>
            *   <li>{@link LockSupport#park() LockSupport.park}</li>
            * </ul>
            *
            * <p>A thread in the waiting state is waiting for another thread to
            * perform a particular action.
            *
            * For example, a thread that has called <tt>Object.wait()</tt>
            * on an object is waiting for another thread to call
            * <tt>Object.notify()</tt> or <tt>Object.notifyAll()</tt> on
            * that object. A thread that has called <tt>Thread.join()</tt>
            * is waiting for a specified thread to terminate.
            */
           WAITING,
   
           /**
            * Thread state for a waiting thread with a specified waiting time.
            * A thread is in the timed waiting state due to calling one of
            * the following methods with a specified positive waiting time:
            * <ul>
            *   <li>{@link #sleep Thread.sleep}</li>
            *   <li>{@link Object#wait(long) Object.wait} with timeout</li>
            *   <li>{@link #join(long) Thread.join} with timeout</li>
            *   <li>{@link LockSupport#parkNanos LockSupport.parkNanos}</li>
            *   <li>{@link LockSupport#parkUntil LockSupport.parkUntil}</li>
            * </ul>
            */
           TIMED_WAITING,
   
           /**
            * Thread state for a terminated thread.
            * The thread has completed execution.
            */
           TERMINATED;
       }
   ```
   
   Thread.State is enum type. A thread can be in only one state at a given point in time. These states are virtual machine states which do not reflect any operating system thread states. So I think may be there is no need to add default clause in the code.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org