ronyang1985 commented on a change in pull request #8390:
URL: https://github.com/apache/dolphinscheduler/pull/8390#discussion_r806499571



##########
File path: 
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
##########
@@ -134,7 +135,11 @@ public static double loadAverage() {
      */
     public static double cpuUsage() {
         CentralProcessor processor = hal.getProcessor();
-        double cpuUsage = processor.getSystemCpuLoad();
+
+        long[] preTicks = processor.getSystemCpuLoadTicks();
+        Util.sleep(1000);

Review comment:
       According to the method annotation, getSystemCpuLoadTicks() method  
returns the "recent cpu usage" for the whole system by counting ticks between 
the user-provided value from a previous call. If not sleeping, it will always 
return value with 0.0D
   `
       /**
        * Returns the "recent cpu usage" for the whole system by counting ticks 
from
        * {@link #getSystemCpuLoadTicks()} between the user-provided value from 
a
        * previous call.
        *
        * @param oldTicks
        *            A tick array from a previous call to
        *            {@link #getSystemCpuLoadTicks()}
        * @return CPU load between 0 and 1 (100%)
        */
       double getSystemCpuLoadBetweenTicks(long[] oldTicks);`

##########
File path: 
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
##########
@@ -134,7 +135,11 @@ public static double loadAverage() {
      */
     public static double cpuUsage() {
         CentralProcessor processor = hal.getProcessor();
-        double cpuUsage = processor.getSystemCpuLoad();
+
+        long[] preTicks = processor.getSystemCpuLoadTicks();
+        Util.sleep(1000);

Review comment:
       According to the method annotation, getSystemCpuLoadTicks() method  
returns the "recent cpu usage" for the whole system by counting ticks between 
the user-provided value from a previous call. If not sleeping, it will always 
return value with 0.0D
   ```
       /**
        * Returns the "recent cpu usage" for the whole system by counting ticks 
from
        * {@link #getSystemCpuLoadTicks()} between the user-provided value from 
a
        * previous call.
        *
        * @param oldTicks
        *            A tick array from a previous call to
        *            {@link #getSystemCpuLoadTicks()}
        * @return CPU load between 0 and 1 (100%)
        */
       double getSystemCpuLoadBetweenTicks(long[] oldTicks);
   ```

##########
File path: 
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
##########
@@ -134,7 +135,11 @@ public static double loadAverage() {
      */
     public static double cpuUsage() {
         CentralProcessor processor = hal.getProcessor();
-        double cpuUsage = processor.getSystemCpuLoad();
+
+        long[] preTicks = processor.getSystemCpuLoadTicks();
+        Util.sleep(1000);

Review comment:
       According to the method annotation, getSystemCpuLoadBetweenTicks() 
method  returns the "recent cpu usage" for the whole system by counting ticks 
between the user-provided value from a previous call. If not sleeping, it will 
always return value with 0.0D
   ```
       /**
        * Returns the "recent cpu usage" for the whole system by counting ticks 
from
        * {@link #getSystemCpuLoadTicks()} between the user-provided value from 
a
        * previous call.
        *
        * @param oldTicks
        *            A tick array from a previous call to
        *            {@link #getSystemCpuLoadTicks()}
        * @return CPU load between 0 and 1 (100%)
        */
       double getSystemCpuLoadBetweenTicks(long[] oldTicks);
   ```

##########
File path: pom.xml
##########
@@ -86,7 +86,7 @@
         <postgresql.version>42.2.5</postgresql.version>
         <hive.jdbc.version>2.1.0</hive.jdbc.version>
         <commons.io.version>2.4</commons.io.version>
-        <oshi.core.version>3.9.1</oshi.core.version>
+        <oshi.core.version>6.1.1</oshi.core.version>

Review comment:
       Hi , i checked and updated the relevant license files

##########
File path: 
dolphinscheduler-common/src/main/java/org/apache/dolphinscheduler/common/utils/OSUtils.java
##########
@@ -134,7 +135,11 @@ public static double loadAverage() {
      */
     public static double cpuUsage() {
         CentralProcessor processor = hal.getProcessor();
-        double cpuUsage = processor.getSystemCpuLoad();
+
+        long[] preTicks = processor.getSystemCpuLoadTicks();
+        Util.sleep(1000);

Review comment:
       According to the method annotation, getSystemCpuLoadBetweenTicks(long[] 
oldTicks)) method  returns the "recent cpu usage" for the whole system by 
counting ticks between the user-provided value from a previous call. If not 
sleeping, it will always return value with 0.0D
   ```
       /**
        * Returns the "recent cpu usage" for the whole system by counting ticks 
from
        * {@link #getSystemCpuLoadTicks()} between the user-provided value from 
a
        * previous call.
        *
        * @param oldTicks
        *            A tick array from a previous call to
        *            {@link #getSystemCpuLoadTicks()}
        * @return CPU load between 0 and 1 (100%)
        */
       double getSystemCpuLoadBetweenTicks(long[] oldTicks);
   ```




-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to