github-actions[bot] commented on code in PR #45284:
URL: https://github.com/apache/doris/pull/45284#discussion_r1880079008
##########
be/src/util/cgroup_util.cpp:
##########
@@ -264,4 +268,136 @@ 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' has cognitive complexity
of 52 (threshold 50) [readability-function-cognitive-complexity]
```cpp
int CGroupUtil::get_cgroup_limited_cpu_number(int physical_cores) {
^
```
<details>
<summary>Additional context</summary>
**be/src/util/cgroup_util.cpp:310:** +1, including nesting penalty of 0,
nesting level increased to 1
```cpp
if (physical_cores <= 0) {
^
```
**be/src/util/cgroup_util.cpp:319:** +1, including nesting penalty of 0,
nesting level increased to 1
```cpp
if (CGroupUtil::cgroupsv2_enable()) {
^
```
**be/src/util/cgroup_util.cpp:321:** +2, including nesting penalty of 1,
nesting level increased to 2
```cpp
if (cgroupv2_process_path.empty()) {
^
```
**be/src/util/cgroup_util.cpp:325:** +2, including nesting penalty of 1,
nesting level increased to 2
```cpp
while (current_cgroup_path != default_cgroups_mount.parent_path()) {
^
```
**be/src/util/cgroup_util.cpp:327:** +3, including nesting penalty of 2,
nesting level increased to 3
```cpp
if (cpu_max_file.is_open()) {
^
```
**be/src/util/cgroup_util.cpp:331:** +4, including nesting penalty of 3,
nesting level increased to 4
```cpp
if (cpu_limit_str != "max" && cpu_period != 0) {
^
```
**be/src/util/cgroup_util.cpp:331:** +1
```cpp
if (cpu_limit_str != "max" && cpu_period != 0) {
^
```
**be/src/util/cgroup_util.cpp:340:** +2, including nesting penalty of 1,
nesting level increased to 2
```cpp
while (current_cgroup_path != default_cgroups_mount.parent_path()) {
^
```
**be/src/util/cgroup_util.cpp:343:** +3, including nesting penalty of 2,
nesting level increased to 3
```cpp
if (cpuset_cpus_file.is_open()) {
^
```
**be/src/util/cgroup_util.cpp:346:** +4, including nesting penalty of 3,
nesting level increased to 4
```cpp
if (cpuset_line.empty()) {
^
```
**be/src/util/cgroup_util.cpp:355:** +1, nesting level increased to 1
```cpp
} else if (CGroupUtil::cgroupsv1_enable()) {
^
```
**be/src/util/cgroup_util.cpp:360:** +2, including nesting penalty of 1,
nesting level increased to 2
```cpp
if (cpu_quota_ret.ok() && !cpu_quota_path.empty()) {
^
```
**be/src/util/cgroup_util.cpp:360:** +1
```cpp
if (cpu_quota_ret.ok() && !cpu_quota_path.empty()) {
^
```
**be/src/util/cgroup_util.cpp:362:** +3, including nesting penalty of 2,
nesting level increased to 3
```cpp
while (current_cgroup_path !=
default_cgroups_mount.parent_path()) {
^
```
**be/src/util/cgroup_util.cpp:365:** +4, including nesting penalty of 3,
nesting level increased to 4
```cpp
if (cpu_quota_file.is_open() && cpu_period_file.is_open()) {
^
```
**be/src/util/cgroup_util.cpp:365:** +1
```cpp
if (cpu_quota_file.is_open() && cpu_period_file.is_open()) {
^
```
**be/src/util/cgroup_util.cpp:370:** +5, including nesting penalty of 4,
nesting level increased to 5
```cpp
if (cpu_quota_value > 0 && cpu_period_value > 0) {
^
```
**be/src/util/cgroup_util.cpp:370:** +1
```cpp
if (cpu_quota_value > 0 && cpu_period_value > 0) {
^
```
**be/src/util/cgroup_util.cpp:386:** +2, including nesting penalty of 1,
nesting level increased to 2
```cpp
if (cpuset_ret.ok() && !cpuset_path.empty()) {
^
```
**be/src/util/cgroup_util.cpp:386:** +1
```cpp
if (cpuset_ret.ok() && !cpuset_path.empty()) {
^
```
**be/src/util/cgroup_util.cpp:390:** +3, including nesting penalty of 2,
nesting level increased to 3
```cpp
if (cpuset_ret.ok() && !cpuset_line.empty()) {
^
```
**be/src/util/cgroup_util.cpp:390:** +1
```cpp
if (cpuset_ret.ok() && !cpuset_line.empty()) {
^
```
**be/src/util/cgroup_util.cpp:392:** +4, including nesting penalty of 3,
nesting level increased to 4
```cpp
if (cpuset_count > 0) {
^
```
</details>
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]