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


##########
be/src/util/cgroup_util.cpp:
##########
@@ -264,4 +268,126 @@ void CGroupUtil::read_int_metric_from_cgroup_file(
     }
 }
 
+Status CGroupUtil::read_string_line_from_cgroup_file(const 
std::filesystem::path& file_path,
+                                                     std::string* line_ptr) {
+    std::ifstream file_stream(file_path, std::ios::in);
+    if (!file_stream.is_open()) {
+        return Status::CgroupError("Error open {}", file_path.string());
+    }
+    string line;
+    getline(file_stream, line);
+    if (file_stream.fail() || file_stream.bad()) {
+        return Status::CgroupError("Error reading {}: {}", file_path.string(), 
get_str_err_msg());
+    }
+    *line_ptr = line;
+    return Status::OK();
+}
+
+Status CGroupUtil::parse_cpuset_line(std::string cpuset_line, int* 
cpu_count_ptr) {
+    if (cpuset_line.empty()) {
+        return Status::CgroupError("cpuset line is empty");
+    }
+    std::vector<string> ranges;
+    boost::split(ranges, cpuset_line, boost::is_any_of(","));
+    int cpu_count = 0;
+
+    for (const std::string& range : ranges) {
+        std::vector<std::string> cpu_values;
+        boost::split(cpu_values, range, boost::is_any_of("-"));
+
+        if (cpu_values.size() == 2) {
+            int start = std::stoi(cpu_values[0]);
+            int end = std::stoi(cpu_values[1]);
+            cpu_count += (end - start) + 1;
+        } else {
+            cpu_count++;
+        }
+    }
+    *cpu_count_ptr = cpu_count;
+    return Status::OK();
+}
+
+int CGroupUtil::get_cgroup_limited_cpu_number(int physical_cores) {

Review Comment:
   warning: function 'get_cgroup_limited_cpu_number' exceeds recommended 
size/complexity thresholds [readability-function-size]
   ```cpp
   int CGroupUtil::get_cgroup_limited_cpu_number(int physical_cores) {
                   ^
   ```
   <details>
   <summary>Additional context</summary>
   
   **be/src/util/cgroup_util.cpp:309:** 81 lines including whitespace and 
comments (threshold 80)
   ```cpp
   int CGroupUtil::get_cgroup_limited_cpu_number(int physical_cores) {
                   ^
   ```
   
   </details>
   



##########
be/src/util/cgroup_util.cpp:
##########
@@ -264,4 +268,126 @@
     }
 }
 
+Status CGroupUtil::read_string_line_from_cgroup_file(const 
std::filesystem::path& file_path,
+                                                     std::string* line_ptr) {
+    std::ifstream file_stream(file_path, std::ios::in);
+    if (!file_stream.is_open()) {
+        return Status::CgroupError("Error open {}", file_path.string());
+    }
+    string line;
+    getline(file_stream, line);
+    if (file_stream.fail() || file_stream.bad()) {
+        return Status::CgroupError("Error reading {}: {}", file_path.string(), 
get_str_err_msg());
+    }
+    *line_ptr = line;
+    return Status::OK();
+}
+
+Status CGroupUtil::parse_cpuset_line(std::string cpuset_line, int* 
cpu_count_ptr) {
+    if (cpuset_line.empty()) {
+        return Status::CgroupError("cpuset line is empty");
+    }
+    std::vector<string> ranges;
+    boost::split(ranges, cpuset_line, boost::is_any_of(","));
+    int cpu_count = 0;
+
+    for (const std::string& range : ranges) {
+        std::vector<std::string> cpu_values;
+        boost::split(cpu_values, range, boost::is_any_of("-"));
+
+        if (cpu_values.size() == 2) {
+            int start = std::stoi(cpu_values[0]);
+            int end = std::stoi(cpu_values[1]);
+            cpu_count += (end - start) + 1;
+        } else {
+            cpu_count++;
+        }
+    }
+    *cpu_count_ptr = cpu_count;
+    return Status::OK();
+}
+
+int CGroupUtil::get_cgroup_limited_cpu_number(int physical_cores) {
+    if (physical_cores <= 0) {
+        return physical_cores;
+    }
+    int ret = physical_cores;
+#if defined(OS_LINUX)
+    if (CGroupUtil::cgroupsv2_enable()) {
+        std::string cgroupv2_process_path = CGroupUtil::cgroupv2_of_process();
+        if (cgroupv2_process_path.empty()) {
+            return ret;
+        }
+        std::filesystem::path current_cgroup_path = (default_cgroups_mount / 
cgroupv2_process_path);
+        while (current_cgroup_path != default_cgroups_mount.parent_path()) {
+            std::ifstream cpu_max_file(current_cgroup_path / "cpu.max");
+            if (cpu_max_file.is_open()) {
+                std::string cpu_limit_str;
+                float cpu_period;
+                cpu_max_file >> cpu_limit_str >> cpu_period;
+                if (cpu_limit_str != "max" && cpu_period != 0) {
+                    float cpu_limit = std::stof(cpu_limit_str);
+                    ret = std::min(static_cast<int>(ceil(cpu_limit / 
cpu_period)), ret);

Review Comment:
   warning: call to 'ceil' promotes float to double 
[performance-type-promotion-in-math-fn]
   
   be/src/util/cgroup_util.cpp:20:
   ```diff
   - #include <fstream>
   + #include <cmath>
   + #include <fstream>
   ```
   
   ```suggestion
                       ret = std::min(static_cast<int>(std::ceil(cpu_limit / 
cpu_period)), ret);
   ```
   



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