github-actions[bot] commented on code in PR #35764:
URL: https://github.com/apache/doris/pull/35764#discussion_r1623244525


##########
be/src/util/jvm_metrics.cpp:
##########
@@ -117,11 +132,58 @@ JvmMetrics::JvmMetrics(MetricRegistry* registry, JNIEnv* 
env) : _jvm_stats(env)
 }
 
 void JvmMetrics::update() {
-    _jvm_stats.refresh(this);
+    static long fail_count = 0;
+    bool have_exception = false;
+    try {
+        _jvm_stats.refresh(this);
+    } catch (...) {
+        have_exception = true;
+        LOG(WARNING) << "JVM MONITOR UPDATE FAIL!";
+        fail_count++;
+    }
+
+    //When 30 consecutive exceptions occur, turn off jvm information 
collection.
+    if (!have_exception) {
+        fail_count = 0;
+    }
+    if (fail_count >= 30) {
+        LOG(WARNING) << "JVM MONITOR CLOSE!";
+        _jvm_stats.set_complete(false);
+        _server_entity->deregister_hook(_s_hook_name);
+
+        jvm_heap_size_bytes_max->set_value(0);
+        jvm_heap_size_bytes_committed->set_value(0);
+        jvm_heap_size_bytes_used->set_value(0);
+
+        jvm_non_heap_size_bytes_used->set_value(0);
+        jvm_non_heap_size_bytes_committed->set_value(0);
+
+        jvm_young_size_bytes_used->set_value(0);
+        jvm_young_size_bytes_peak_used->set_value(0);
+        jvm_young_size_bytes_max->set_value(0);
+
+        jvm_old_size_bytes_used->set_value(0);
+        jvm_old_size_bytes_peak_used->set_value(0);
+        jvm_old_size_bytes_max->set_value(0);
+
+        jvm_thread_count->set_value(0);
+        jvm_thread_peak_count->set_value(0);
+        jvm_thread_new_count->set_value(0);
+        jvm_thread_runnable_count->set_value(0);
+        jvm_thread_blocked_count->set_value(0);
+        jvm_thread_waiting_count->set_value(0);
+        jvm_thread_timed_waiting_count->set_value(0);
+        jvm_thread_terminated_count->set_value(0);
+
+        jvm_gc_g1_young_generation_count->set_value(0);
+        jvm_gc_g1_young_generation_time_ms->set_value(0);
+        jvm_gc_g1_old_generation_count->set_value(0);
+        jvm_gc_g1_old_generation_time_ms->set_value(0);
+    }
 }
-#include <util/jni-util.h>
 
-jvmStats::jvmStats(JNIEnv* ENV) : env(ENV) {
+void JvmStats::init(JNIEnv* ENV) {

Review Comment:
   warning: function 'init' exceeds recommended size/complexity thresholds 
[readability-function-size]
   ```cpp
   void JvmStats::init(JNIEnv* ENV) {
                  ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/util/jvm_metrics.cpp:184:** 125 lines including whitespace and 
comments (threshold 80)
   ```cpp
   void JvmStats::init(JNIEnv* ENV) {
                  ^
   ```
   
   </details>
   



##########
be/src/util/jvm_metrics.cpp:
##########
@@ -244,15 +306,19 @@
     LOG(INFO) << "Start JVM monitoring.";
 
     _init_complete = true;
+    return;
 }

Review Comment:
   warning: redundant return statement at the end of a function with a void 
return type [readability-redundant-control-flow]
   
   ```suggestion
   }
   ```
   



##########
be/src/util/jvm_metrics.cpp:
##########
@@ -244,15 +306,19 @@
     LOG(INFO) << "Start JVM monitoring.";
 
     _init_complete = true;
+    return;
 }
 
-#include "jni.h"
-
-void jvmStats::refresh(JvmMetrics* jvm_metrics) {
+void JvmStats::refresh(JvmMetrics* jvm_metrics) {

Review Comment:
   warning: method 'refresh' can be made const 
[readability-make-member-function-const]
   
   be/src/util/jvm_metrics.h:102:
   ```diff
   -     void refresh(JvmMetrics* jvm_metrics);
   +     void refresh(JvmMetrics* jvm_metrics) const;
   ```
   
   ```suggestion
   void JvmStats::refresh(JvmMetrics* jvm_metrics) const {
   ```
   



##########
be/src/util/jvm_metrics.cpp:
##########
@@ -244,15 +306,19 @@
     LOG(INFO) << "Start JVM monitoring.";
 
     _init_complete = true;
+    return;
 }
 
-#include "jni.h"
-
-void jvmStats::refresh(JvmMetrics* jvm_metrics) {
+void JvmStats::refresh(JvmMetrics* jvm_metrics) {

Review Comment:
   warning: function 'refresh' exceeds recommended size/complexity thresholds 
[readability-function-size]
   ```cpp
   void JvmStats::refresh(JvmMetrics* jvm_metrics) {
                  ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/util/jvm_metrics.cpp:311:** 164 lines including whitespace and 
comments (threshold 80)
   ```cpp
   void JvmStats::refresh(JvmMetrics* jvm_metrics) {
                  ^
   ```
   
   </details>
   



##########
be/src/util/jvm_metrics.cpp:
##########
@@ -244,15 +306,19 @@
     LOG(INFO) << "Start JVM monitoring.";
 
     _init_complete = true;
+    return;
 }
 
-#include "jni.h"
-
-void jvmStats::refresh(JvmMetrics* jvm_metrics) {
+void JvmStats::refresh(JvmMetrics* jvm_metrics) {

Review Comment:
   warning: function 'refresh' has cognitive complexity of 66 (threshold 50) 
[readability-function-cognitive-complexity]
   ```cpp
   void JvmStats::refresh(JvmMetrics* jvm_metrics) {
                  ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/util/jvm_metrics.cpp:312:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       if (!_init_complete) {
       ^
   ```
   **be/src/util/jvm_metrics.cpp:317:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       if (!st.ok()) {
       ^
   ```
   **be/src/util/jvm_metrics.cpp:332:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_heap_size_bytes_used->set_value(heapMemoryUsed < 0 ? 0 
: heapMemoryUsed);
                                                                           ^
   ```
   **be/src/util/jvm_metrics.cpp:334:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
               heapMemoryCommitted < 0 ? 0 : heapMemoryCommitted);
                                       ^
   ```
   **be/src/util/jvm_metrics.cpp:335:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_heap_size_bytes_max->set_value(heapMemoryMax < 0 ? 0 : 
heapMemoryMax);
                                                                         ^
   ```
   **be/src/util/jvm_metrics.cpp:345:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
               nonHeapMemoryCommitted < 0 ? 0 : nonHeapMemoryCommitted);
                                          ^
   ```
   **be/src/util/jvm_metrics.cpp:346:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_non_heap_size_bytes_used->set_value(nonHeapMemoryUsed < 
0 ? 0
                                                                                
  ^
   ```
   **be/src/util/jvm_metrics.cpp:354:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       for (int i = 0; i < size; ++i) {
       ^
   ```
   **be/src/util/jvm_metrics.cpp:371:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           if (nameStr != nullptr) {
           ^
   ```
   **be/src/util/jvm_metrics.cpp:373:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (it == _memoryPoolName.end()) {
               ^
   ```
   **be/src/util/jvm_metrics.cpp:376:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (it->second == memoryPoolNameEnum::YOUNG) {
               ^
   ```
   **be/src/util/jvm_metrics.cpp:377:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
                   jvm_metrics->jvm_young_size_bytes_used->set_value(used < 0 ? 
0 : used);
                                                                              ^
   ```
   **be/src/util/jvm_metrics.cpp:378:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
                   
jvm_metrics->jvm_young_size_bytes_peak_used->set_value(peakUsed < 0 ? 0 : 
peakUsed);
                                                                                
       ^
   ```
   **be/src/util/jvm_metrics.cpp:379:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
                   jvm_metrics->jvm_young_size_bytes_max->set_value(max < 0 ? 0 
: max);
                                                                            ^
   ```
   **be/src/util/jvm_metrics.cpp:381:** +1, nesting level increased to 3
   ```cpp
               } else if (it->second == memoryPoolNameEnum::OLD) {
                      ^
   ```
   **be/src/util/jvm_metrics.cpp:382:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
                   jvm_metrics->jvm_old_size_bytes_used->set_value(used < 0 ? 0 
: used);
                                                                            ^
   ```
   **be/src/util/jvm_metrics.cpp:383:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
                   
jvm_metrics->jvm_old_size_bytes_peak_used->set_value(peakUsed < 0 ? 0 : 
peakUsed);
                                                                                
     ^
   ```
   **be/src/util/jvm_metrics.cpp:384:** +4, including nesting penalty of 3, 
nesting level increased to 4
   ```cpp
                   jvm_metrics->jvm_old_size_bytes_max->set_value(max < 0 ? 0 : 
max);
                                                                          ^
   ```
   **be/src/util/jvm_metrics.cpp:407:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_thread_peak_count->set_value(peakThreadCount < 0 ? 0 : 
peakThreadCount);
                                                                         ^
   ```
   **be/src/util/jvm_metrics.cpp:408:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_thread_count->set_value(threadCount < 0 ? 0 : 
threadCount);
                                                                ^
   ```
   **be/src/util/jvm_metrics.cpp:410:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       for (int i = 0; i < threadCount; i++) {
       ^
   ```
   **be/src/util/jvm_metrics.cpp:412:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           if (threadInfo == nullptr) {
           ^
   ```
   **be/src/util/jvm_metrics.cpp:417:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           if (env->IsSameObject(threadState, _newThreadStateObj)) {
           ^
   ```
   **be/src/util/jvm_metrics.cpp:419:** +1, nesting level increased to 2
   ```cpp
           } else if (env->IsSameObject(threadState, _runnableThreadStateObj)) {
                  ^
   ```
   **be/src/util/jvm_metrics.cpp:421:** +1, nesting level increased to 2
   ```cpp
           } else if (env->IsSameObject(threadState, _blockedThreadStateObj)) {
                  ^
   ```
   **be/src/util/jvm_metrics.cpp:423:** +1, nesting level increased to 2
   ```cpp
           } else if (env->IsSameObject(threadState, _waitingThreadStateObj)) {
                  ^
   ```
   **be/src/util/jvm_metrics.cpp:425:** +1, nesting level increased to 2
   ```cpp
           } else if (env->IsSameObject(threadState, 
_timedWaitingThreadStateObj)) {
                  ^
   ```
   **be/src/util/jvm_metrics.cpp:427:** +1, nesting level increased to 2
   ```cpp
           } else if (env->IsSameObject(threadState, 
_terminatedThreadStateObj)) {
                  ^
   ```
   **be/src/util/jvm_metrics.cpp:434:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_thread_new_count->set_value(threadsNew < 0 ? 0 : 
threadsNew);
                                                                   ^
   ```
   **be/src/util/jvm_metrics.cpp:435:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_thread_runnable_count->set_value(threadsRunnable < 0 ? 
0 : threadsRunnable);
                                                                             ^
   ```
   **be/src/util/jvm_metrics.cpp:436:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_thread_blocked_count->set_value(threadsBlocked < 0 ? 0 
: threadsBlocked);
                                                                           ^
   ```
   **be/src/util/jvm_metrics.cpp:437:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_thread_waiting_count->set_value(threadsWaiting < 0 ? 0 
: threadsWaiting);
                                                                           ^
   ```
   **be/src/util/jvm_metrics.cpp:439:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
               threadsTimedWaiting < 0 ? 0 : threadsTimedWaiting);
                                       ^
   ```
   **be/src/util/jvm_metrics.cpp:440:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       jvm_metrics->jvm_thread_terminated_count->set_value(threadsTerminated < 
0 ? 0
                                                                                
 ^
   ```
   **be/src/util/jvm_metrics.cpp:448:** +1, including nesting penalty of 0, 
nesting level increased to 1
   ```cpp
       for (int i = 0; i < numCollectors; i++) {
       ^
   ```
   **be/src/util/jvm_metrics.cpp:455:** +2, including nesting penalty of 1, 
nesting level increased to 2
   ```cpp
           if (gcNameStr != nullptr) {
           ^
   ```
   **be/src/util/jvm_metrics.cpp:456:** +3, including nesting penalty of 2, 
nesting level increased to 3
   ```cpp
               if (strcmp(gcNameStr, "G1 Young Generation") == 0) {
               ^
   ```
   **be/src/util/jvm_metrics.cpp:460:** +1, nesting level increased to 3
   ```cpp
               } else {
                 ^
   ```
   
   </details>
   



##########
be/src/util/jvm_metrics.h:
##########
@@ -17,8 +17,6 @@
 
 #pragma once
 
-#include <jni.h>
-
 #include "jni.h"

Review Comment:
   warning: 'jni.h' file not found [clang-diagnostic-error]
   ```cpp
   #include "jni.h"
            ^
   ```
   



-- 
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.

To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org

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


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

Reply via email to