You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2022/10/26 02:21:59 UTC

[GitHub] [pulsar] hangc0276 commented on a diff in pull request #17820: [Bugfix] [LinuxInfoUtils] incorrect CPU usage collected by pulsar #17815

hangc0276 commented on code in PR #17820:
URL: https://github.com/apache/pulsar/pull/17820#discussion_r1005146105


##########
pulsar-broker/src/main/java/org/apache/pulsar/broker/loadbalance/LinuxInfoUtils.java:
##########
@@ -72,6 +73,26 @@ public static boolean isCGroupEnabled() {
         }
     }
 
+    /**
+     *  Get total cpu count.
+     * @return Total cpu count
+     */
+    public static int getTotalCpuCount() throws IOException {
+        int totalCpuCount = 0;
+        String[] ranges = readTrimStringFromFile(Paths.get(CGROUPS_CPU_CPUSET_CPUS)).split(",");
+        for (String range : ranges) {
+            if (!range.contains("-")) {
+                totalCpuCount++;
+            } else {
+                int dashIndex = range.indexOf('-');
+                int left = Integer.parseInt(range.substring(0, dashIndex));

Review Comment:
   It may throw `IndexOutOfBoundsException` and `NumberFormatException`, and can't be caught by line#113



-- 
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-unsubscribe@pulsar.apache.org

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