This is an automated email from the ASF dual-hosted git repository.

wangbo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new b9015f57fdd [Improment]add be avail cpu num metric (#45284)
b9015f57fdd is described below

commit b9015f57fddd95c8b1ee57e303ce2dde0353fae7
Author: wangbo <wan...@selectdb.com>
AuthorDate: Fri Dec 13 11:33:11 2024 +0800

    [Improment]add be avail cpu num metric (#45284)
---
 be/src/common/config.cpp                           |   2 +-
 be/src/common/config.h                             |   2 +-
 be/src/common/daemon.cpp                           |   2 +
 be/src/util/cgroup_util.cpp                        | 167 +++++++++++++++++++++
 be/src/util/cgroup_util.h                          |  22 +++
 be/src/util/cpu_info.cpp                           |  55 +------
 be/src/util/system_metrics.cpp                     |  13 ++
 be/src/util/system_metrics.h                       |   2 +
 be/test/util/cgroup_util_test.cpp                  |  90 +++++++++++
 be/test/util/test_data/cgroup_cpu_data/cpuset1     |   1 +
 be/test/util/test_data/cgroup_cpu_data/cpuset2     |   1 +
 be/test/util/test_data/cgroup_cpu_data/cpuset3     |   1 +
 .../test_data/cgroup_cpu_data/test11/child/cpu.max |   1 +
 .../util/test_data/cgroup_cpu_data/test11/cpu.max  |   1 +
 .../test_data/cgroup_cpu_data/test12/child/cpu.max |   1 +
 .../util/test_data/cgroup_cpu_data/test12/cpu.max  |   1 +
 .../test_data/cgroup_cpu_data/test13/child/cpu.max |   1 +
 .../util/test_data/cgroup_cpu_data/test13/cpu.max  |   1 +
 .../test_data/cgroup_cpu_data/test14/child/cpu.max |   1 +
 .../util/test_data/cgroup_cpu_data/test14/cpu.max  |   1 +
 .../test21/child/cpuset.cpus.effective             |   1 +
 .../cgroup_cpu_data/test21/cpuset.cpus.effective   |   1 +
 .../test22/child/cpuset.cpus.effective             |   0
 .../cgroup_cpu_data/test22/cpuset.cpus.effective   |   1 +
 .../cgroup_cpu_data/test31/child/cpu.cfs_period_us |   1 +
 .../cgroup_cpu_data/test31/child/cpu.cfs_quota_us  |   1 +
 .../cgroup_cpu_data/test31/cpu.cfs_period_us       |   1 +
 .../cgroup_cpu_data/test31/cpu.cfs_quota_us        |   1 +
 .../cgroup_cpu_data/test32/child/cpu.cfs_period_us |   1 +
 .../cgroup_cpu_data/test32/child/cpu.cfs_quota_us  |   1 +
 .../cgroup_cpu_data/test32/cpu.cfs_period_us       |   1 +
 .../cgroup_cpu_data/test32/cpu.cfs_quota_us        |   1 +
 .../cgroup_cpu_data/test33/child/cpu.cfs_period_us |   1 +
 .../cgroup_cpu_data/test33/child/cpu.cfs_quota_us  |   1 +
 .../cgroup_cpu_data/test33/cpu.cfs_period_us       |   1 +
 .../cgroup_cpu_data/test33/cpu.cfs_quota_us        |   1 +
 .../test_data/cgroup_cpu_data/test41/cpuset.cpus   |   1 +
 37 files changed, 327 insertions(+), 55 deletions(-)

diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp
index 08f1ca7dd58..b70f492a29d 100644
--- a/be/src/common/config.cpp
+++ b/be/src/common/config.cpp
@@ -1211,7 +1211,7 @@ DEFINE_Bool(exit_on_exception, "false");
 DEFINE_Bool(enable_flush_file_cache_async, "true");
 
 // cgroup
-DEFINE_mString(doris_cgroup_cpu_path, "");
+DEFINE_String(doris_cgroup_cpu_path, "");
 
 DEFINE_mBool(enable_be_proc_monitor, "false");
 DEFINE_mInt32(be_proc_monitor_interval_ms, "10000");
diff --git a/be/src/common/config.h b/be/src/common/config.h
index c0b2e19b49a..984024cab7c 100644
--- a/be/src/common/config.h
+++ b/be/src/common/config.h
@@ -1292,7 +1292,7 @@ DECLARE_mInt32(tablet_schema_cache_capacity);
 DECLARE_mBool(exit_on_exception);
 
 // cgroup
-DECLARE_mString(doris_cgroup_cpu_path);
+DECLARE_String(doris_cgroup_cpu_path);
 DECLARE_mBool(enable_be_proc_monitor);
 DECLARE_mInt32(be_proc_monitor_interval_ms);
 DECLARE_Int32(workload_group_metrics_interval_ms);
diff --git a/be/src/common/daemon.cpp b/be/src/common/daemon.cpp
index 73035ecf395..12bf1749a56 100644
--- a/be/src/common/daemon.cpp
+++ b/be/src/common/daemon.cpp
@@ -437,6 +437,8 @@ void Daemon::calculate_metrics_thread() {
                 // update lst map
                 
DorisMetrics::instance()->system_metrics()->get_network_traffic(
                         &lst_net_send_bytes, &lst_net_receive_bytes);
+
+                
DorisMetrics::instance()->system_metrics()->update_be_avail_cpu_num();
             }
             update_rowsets_and_segments_num_metrics();
         }
diff --git a/be/src/util/cgroup_util.cpp b/be/src/util/cgroup_util.cpp
index 8f64fe699c6..fc35be3dc35 100644
--- a/be/src/util/cgroup_util.cpp
+++ b/be/src/util/cgroup_util.cpp
@@ -218,6 +218,10 @@ std::optional<std::string> 
CGroupUtil::get_cgroupsv2_path(const std::string& sub
 Status CGroupUtil::read_int_line_from_cgroup_file(const std::filesystem::path& 
file_path,
                                                   int64_t* val) {
     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()) {
@@ -264,4 +268,167 @@ 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) {
+    if (physical_cores <= 0) {
+        return physical_cores;
+    }
+    int ret = physical_cores;
+#if defined(OS_LINUX)
+    // For cgroup v2
+    // Child cgroup's cpu.max may bigger than parent group's cpu.max,
+    //      so it should look up from current cgroup to top group.
+    // For cpuset, child cgroup's cpuset.cpus could not bigger thant parent's 
cpuset.cpus.
+    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);
+        ret = get_cgroup_v2_cpu_quota_number(current_cgroup_path, 
default_cgroups_mount, ret);
+
+        current_cgroup_path = (default_cgroups_mount / cgroupv2_process_path);
+        ret = get_cgroup_v2_cpuset_number(current_cgroup_path, 
default_cgroups_mount, ret);
+    } else if (CGroupUtil::cgroupsv1_enable()) {
+        // cpu quota, should find first not empty config from current path to 
top.
+        // because if a process attach to current cgroup, its cpu quota may 
not be set.
+        std::string cpu_quota_path = "";
+        Status cpu_quota_ret = CGroupUtil::find_abs_cgroupv1_path("cpu", 
&cpu_quota_path);
+        if (cpu_quota_ret.ok() && !cpu_quota_path.empty()) {
+            std::filesystem::path current_cgroup_path = cpu_quota_path;
+            ret = get_cgroup_v1_cpu_quota_number(current_cgroup_path, 
default_cgroups_mount, ret);
+        }
+
+        //cpuset
+        // just lookup current process cgroup path is enough
+        // because if a process attach to current cgroup, its cpuset.cpus must 
be set.
+        std::string cpuset_path = "";
+        Status cpuset_ret = CGroupUtil::find_abs_cgroupv1_path("cpuset", 
&cpuset_path);
+        if (cpuset_ret.ok() && !cpuset_path.empty()) {
+            std::filesystem::path current_path = cpuset_path;
+            ret = get_cgroup_v1_cpuset_number(current_path, ret);
+        }
+    }
+#endif
+    return ret;
+}
+
+int CGroupUtil::get_cgroup_v2_cpu_quota_number(std::filesystem::path& 
current_path,
+                                               const std::filesystem::path& 
default_cg_mout_path,
+                                               int cpu_num) {
+    int ret = cpu_num;
+    while (current_path != default_cg_mout_path.parent_path()) {
+        std::ifstream cpu_max_file(current_path / "cpu.max");
+        if (cpu_max_file.is_open()) {
+            std::string cpu_limit_str;
+            double cpu_period;
+            cpu_max_file >> cpu_limit_str >> cpu_period;
+            if (cpu_limit_str != "max" && cpu_period != 0) {
+                double cpu_limit = std::stod(cpu_limit_str);
+                ret = std::min(static_cast<int>(std::ceil(cpu_limit / 
cpu_period)), ret);
+            }
+        }
+        current_path = current_path.parent_path();
+    }
+    return ret;
+}
+
+int CGroupUtil::get_cgroup_v2_cpuset_number(std::filesystem::path& 
current_path,
+                                            const std::filesystem::path& 
default_cg_mout_path,
+                                            int cpu_num) {
+    int ret = cpu_num;
+    while (current_path != default_cg_mout_path.parent_path()) {
+        std::ifstream cpuset_cpus_file(current_path / "cpuset.cpus.effective");
+        current_path = current_path.parent_path();
+        if (cpuset_cpus_file.is_open()) {
+            std::string cpuset_line;
+            cpuset_cpus_file >> cpuset_line;
+            if (cpuset_line.empty()) {
+                continue;
+            }
+            int cpus_count = 0;
+            static_cast<void>(CGroupUtil::parse_cpuset_line(cpuset_line, 
&cpus_count));
+            ret = std::min(cpus_count, ret);
+            break;
+        }
+    }
+    return ret;
+}
+
+int CGroupUtil::get_cgroup_v1_cpu_quota_number(std::filesystem::path& 
current_path,
+                                               const std::filesystem::path& 
default_cg_mout_path,
+                                               int cpu_num) {
+    int ret = cpu_num;
+    while (current_path != default_cg_mout_path.parent_path()) {
+        std::ifstream cpu_quota_file(current_path / "cpu.cfs_quota_us");
+        std::ifstream cpu_period_file(current_path / "cpu.cfs_period_us");
+        if (cpu_quota_file.is_open() && cpu_period_file.is_open()) {
+            double cpu_quota_value;
+            double cpu_period_value;
+            cpu_quota_file >> cpu_quota_value;
+            cpu_period_file >> cpu_period_value;
+            if (cpu_quota_value > 0 && cpu_period_value > 0) {
+                ret = std::min(ret,
+                               static_cast<int>(std::ceil(cpu_quota_value / 
cpu_period_value)));
+                break;
+            }
+        }
+        current_path = current_path.parent_path();
+    }
+    return ret;
+}
+
+int CGroupUtil::get_cgroup_v1_cpuset_number(std::filesystem::path& 
current_path, int cpu_num) {
+    int ret = cpu_num;
+    std::string cpuset_line = "";
+    Status cpuset_ret = CGroupUtil::read_string_line_from_cgroup_file(
+            (current_path / "cpuset.cpus"), &cpuset_line);
+    if (cpuset_ret.ok() && !cpuset_line.empty()) {
+        int cpuset_count = 0;
+        static_cast<void>(CGroupUtil::parse_cpuset_line(cpuset_line, 
&cpuset_count));
+        if (cpuset_count > 0) {
+            ret = std::min(ret, cpuset_count);
+        }
+    }
+    return ret;
+}
+
 } // namespace doris
diff --git a/be/src/util/cgroup_util.h b/be/src/util/cgroup_util.h
index bc1417453f4..54fc9494599 100644
--- a/be/src/util/cgroup_util.h
+++ b/be/src/util/cgroup_util.h
@@ -104,5 +104,27 @@ public:
     static void read_int_metric_from_cgroup_file(
             const std::filesystem::path& file_path,
             std::unordered_map<std::string, int64_t>& metrics_map);
+
+    static Status read_string_line_from_cgroup_file(const 
std::filesystem::path& file_path,
+                                                    std::string* line_ptr);
+
+    // cpuset_line: 0-4,6,8-10
+    static Status parse_cpuset_line(std::string cpuset_line, int* 
cpu_count_ptr);
+
+    static int get_cgroup_limited_cpu_number(int physical_cores);
+
+    static int get_cgroup_v2_cpu_quota_number(std::filesystem::path& 
current_path,
+                                              const std::filesystem::path& 
default_cg_mout_path,
+                                              int cpu_num);
+
+    static int get_cgroup_v2_cpuset_number(std::filesystem::path& current_path,
+                                           const std::filesystem::path& 
default_cg_mout_path,
+                                           int cpu_num);
+
+    static int get_cgroup_v1_cpu_quota_number(std::filesystem::path& 
current_path,
+                                              const std::filesystem::path& 
default_cg_mout_path,
+                                              int cpu_num);
+
+    static int get_cgroup_v1_cpuset_number(std::filesystem::path& 
current_path, int cpu_num);
 };
 } // namespace doris
diff --git a/be/src/util/cpu_info.cpp b/be/src/util/cpu_info.cpp
index 116dacb8da7..b49985cdc06 100644
--- a/be/src/util/cpu_info.cpp
+++ b/be/src/util/cpu_info.cpp
@@ -59,6 +59,7 @@
 #include "gflags/gflags.h"
 #include "gutil/stringprintf.h"
 #include "gutil/strings/substitute.h"
+#include "util/cgroup_util.h"
 #include "util/pretty_printer.h"
 
 using boost::algorithm::contains;
@@ -109,58 +110,6 @@ static struct {
         {"popcnt", CpuInfo::POPCNT}, {"avx", CpuInfo::AVX},       {"avx2", 
CpuInfo::AVX2},
 };
 
-int cgroup_bandwidth_quota(int physical_cores) {
-    namespace fs = std::filesystem;
-    fs::path cpu_max = "/sys/fs/cgroup/cpu.max";
-    fs::path cfs_quota = "/sys/fs/cgroup/cpu/cpu.cfs_quota_us";
-    fs::path cfs_period = "/sys/fs/cgroup/cpu/cpu.cfs_period_us";
-
-    int64_t quota, period;
-    char byte_buffer[1000];
-    int64_t read_bytes;
-
-    if (fs::exists(cpu_max)) {
-        // cgroup v2
-        // https://www.kernel.org/doc/html/latest/admin-guide/cgroup-v2.html
-        std::ifstream file(cpu_max);
-        file.read(byte_buffer, 999);
-        read_bytes = file.gcount();
-        byte_buffer[read_bytes] = '\0';
-        if (sscanf(byte_buffer, "%" SCNd64 " %" SCNd64 "", &quota, &period) != 
2) {
-            return physical_cores;
-        }
-    } else if (fs::exists(cfs_quota) && fs::exists(cfs_period)) {
-        // cgroup v1
-        // 
https://www.kernel.org/doc/html/latest/scheduler/sched-bwc.html#management
-
-        // Read the quota, this indicates how many microseconds the CPU can be 
utilized by this cgroup per period
-        std::ifstream quota_file(cfs_quota);
-        quota_file.read(byte_buffer, 999);
-        read_bytes = quota_file.gcount();
-        byte_buffer[read_bytes] = '\0';
-        if (sscanf(byte_buffer, "%" SCNd64 "", &quota) != 1) {
-            return physical_cores;
-        }
-
-        // Read the time period, a cgroup can utilize the CPU up to quota 
microseconds every period
-        std::ifstream period_file(cfs_period);
-        period_file.read(byte_buffer, 999);
-        read_bytes = period_file.gcount();
-        byte_buffer[read_bytes] = '\0';
-        if (sscanf(byte_buffer, "%" SCNd64 "", &period) != 1) {
-            return physical_cores;
-        }
-    } else {
-        // No cgroup quota
-        return physical_cores;
-    }
-    if (quota > 0 && period > 0) {
-        return int64_t(ceil(double(quota) / double(period)));
-    } else {
-        return physical_cores;
-    }
-}
-
 // Helper function to parse for hardware flags.
 // values contains a list of space-separated flags.  check to see if the flags 
we
 // care about are present.
@@ -212,7 +161,7 @@ void CpuInfo::init() {
         }
     }
 
-    int num_cores = cgroup_bandwidth_quota(physical_num_cores);
+    int num_cores = 
CGroupUtil::get_cgroup_limited_cpu_number(physical_num_cores);
     if (max_mhz != 0) {
         cycles_per_ms_ = int64_t(max_mhz) * 1000;
     } else {
diff --git a/be/src/util/system_metrics.cpp b/be/src/util/system_metrics.cpp
index 973f461d8de..fc2cdcc9262 100644
--- a/be/src/util/system_metrics.cpp
+++ b/be/src/util/system_metrics.cpp
@@ -33,18 +33,23 @@
 
 #include "gutil/strings/split.h" // for string split
 #include "gutil/strtoint.h"      //  for atoi64
+#include "util/cgroup_util.h"
 #include "util/mem_info.h"
 #include "util/perf_counters.h"
 
 namespace doris {
 
+DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(avail_cpu_num, MetricUnit::NOUNIT);
+
 DEFINE_COUNTER_METRIC_PROTOTYPE_2ARG(host_cpu_num, MetricUnit::NOUNIT);
 struct CpuNumberMetrics {
     CpuNumberMetrics(MetricEntity* ent) : entity(ent) {
         INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, host_cpu_num);
+        INT_ATOMIC_COUNTER_METRIC_REGISTER(entity, avail_cpu_num);
     }
 
     IntAtomicCounter* host_cpu_num {nullptr};
+    IntAtomicCounter* avail_cpu_num {nullptr};
     MetricEntity* entity = nullptr;
 };
 
@@ -1004,6 +1009,14 @@ void SystemMetrics::_update_proc_metrics() {
     fclose(fp);
 }
 
+void SystemMetrics::update_be_avail_cpu_num() {
+    int64_t physical_cpu_num = _cpu_num_metrics->host_cpu_num->value();
+    if (physical_cpu_num > 0) {
+        physical_cpu_num = 
CGroupUtil::get_cgroup_limited_cpu_number(physical_cpu_num);
+        _cpu_num_metrics->avail_cpu_num->set_value(physical_cpu_num);
+    }
+}
+
 void SystemMetrics::get_metrics_from_proc_vmstat() {
 #ifdef BE_TEST
     FILE* fp = fopen(k_ut_vmstat_path, "r");
diff --git a/be/src/util/system_metrics.h b/be/src/util/system_metrics.h
index 29ce8c9c02b..2c5446b81f4 100644
--- a/be/src/util/system_metrics.h
+++ b/be/src/util/system_metrics.h
@@ -66,6 +66,8 @@ public:
     void update_max_network_receive_bytes_rate(int64_t max_receive_bytes_rate);
     void update_allocator_metrics();
 
+    void update_be_avail_cpu_num();
+
 private:
     void _install_cpu_metrics();
     // On Intel(R) Xeon(R) CPU E5-2450 0 @ 2.10GHz;
diff --git a/be/test/util/cgroup_util_test.cpp 
b/be/test/util/cgroup_util_test.cpp
index 92102120327..4cc5c601b28 100644
--- a/be/test/util/cgroup_util_test.cpp
+++ b/be/test/util/cgroup_util_test.cpp
@@ -87,4 +87,94 @@ TEST_F(CGroupUtilTest, memlimit) {
     }
 }
 
+TEST_F(CGroupUtilTest, readcpu) {
+    std::string dir_path = GetCurrentRunningDir();
+
+    std::string cpuset_1_path(dir_path + 
"/util/test_data/cgroup_cpu_data/cpuset1");
+    std::string cpuset_1_str = "";
+    Status ret1 = CGroupUtil::read_string_line_from_cgroup_file(cpuset_1_path, 
&cpuset_1_str);
+    EXPECT_TRUE(ret1.ok());
+    int cpu_count1 = 0;
+    static_cast<void>(CGroupUtil::parse_cpuset_line(cpuset_1_str, 
&cpu_count1));
+    EXPECT_TRUE(cpu_count1 == 3);
+
+    std::string cpuset_2_path(dir_path + 
"/util/test_data/cgroup_cpu_data/cpuset2");
+    std::string cpuset_2_str = "";
+    Status ret2 = CGroupUtil::read_string_line_from_cgroup_file(cpuset_2_path, 
&cpuset_2_str);
+    EXPECT_TRUE(ret2.ok());
+    int cpu_count2 = 0;
+    static_cast<void>(CGroupUtil::parse_cpuset_line(cpuset_2_str, 
&cpu_count2));
+    EXPECT_TRUE(cpu_count2 == 11);
+
+    std::string cpuset_3_path(dir_path + 
"/util/test_data/cgroup_cpu_data/cpuset3");
+    std::string cpuset_3_str = "";
+    Status ret3 = CGroupUtil::read_string_line_from_cgroup_file(cpuset_3_path, 
&cpuset_3_str);
+    EXPECT_TRUE(ret3.ok());
+    int cpu_count3 = 0;
+    static_cast<void>(CGroupUtil::parse_cpuset_line(cpuset_3_str, 
&cpu_count3));
+    EXPECT_TRUE(cpu_count3 == 10);
+
+    int ret = CGroupUtil::get_cgroup_limited_cpu_number(16);
+    EXPECT_TRUE(ret > 0);
+
+    // 1 read cgroup v2 quota
+    // 1.1 read default value
+    std::filesystem::path path11 = dir_path + 
"/util/test_data/cgroup_cpu_data/test11/child";
+    std::filesystem::path default_path_11 = dir_path + 
"/util/test_data/cgroup_cpu_data/test11";
+    int ret11 = CGroupUtil::get_cgroup_v2_cpu_quota_number(path11, 
default_path_11, 96);
+    EXPECT_TRUE(ret11 == 96);
+
+    // 1.2 read from child to parent
+    std::filesystem::path path12 = dir_path + 
"/util/test_data/cgroup_cpu_data/test12/child";
+    std::filesystem::path default_path_12 = dir_path + 
"/util/test_data/cgroup_cpu_data/test12";
+    int ret12 = CGroupUtil::get_cgroup_v2_cpu_quota_number(path12, 
default_path_12, 96);
+    EXPECT_TRUE(ret12 == 2);
+
+    // 1.3 read parent
+    std::filesystem::path path13 = dir_path + 
"/util/test_data/cgroup_cpu_data/test13/child";
+    std::filesystem::path default_path_13 = dir_path + 
"/util/test_data/cgroup_cpu_data/test13";
+    int ret13 = CGroupUtil::get_cgroup_v2_cpu_quota_number(path13, 
default_path_13, 96);
+    EXPECT_TRUE(ret13 == 2);
+
+    // 1.4 read child
+    std::filesystem::path path14 = dir_path + 
"/util/test_data/cgroup_cpu_data/test14/child";
+    std::filesystem::path default_path_14 = dir_path + 
"/util/test_data/cgroup_cpu_data/test14";
+    int ret14 = CGroupUtil::get_cgroup_v2_cpu_quota_number(path14, 
default_path_14, 96);
+    EXPECT_TRUE(ret14 == 3);
+
+    // 2 read cgroup v2 cpuset
+    // 2.1 read child
+    std::filesystem::path path21 = dir_path + 
"/util/test_data/cgroup_cpu_data/test21/child";
+    std::filesystem::path default_path_21 = dir_path + 
"/util/test_data/cgroup_cpu_data/test21";
+    int ret21 = CGroupUtil::get_cgroup_v2_cpuset_number(path21, 
default_path_21, 96);
+    EXPECT_TRUE(ret21 == 2);
+    // 2.2 read parent
+    std::filesystem::path path22 = dir_path + 
"/util/test_data/cgroup_cpu_data/test22/child";
+    std::filesystem::path default_path_22 = dir_path + 
"/util/test_data/cgroup_cpu_data/test22";
+    int ret22 = CGroupUtil::get_cgroup_v2_cpuset_number(path22, 
default_path_22, 96);
+    EXPECT_TRUE(ret22 == 7);
+
+    // 3 read cgroup v1 quota
+    // 3.1 read child
+    std::filesystem::path path31 = dir_path + 
"/util/test_data/cgroup_cpu_data/test31/child";
+    std::filesystem::path default_path_31 = dir_path + 
"/util/test_data/cgroup_cpu_data/test31";
+    int ret31 = CGroupUtil::get_cgroup_v1_cpu_quota_number(path31, 
default_path_31, 96);
+    EXPECT_TRUE(ret31 == 5);
+    // 3.2 read parent
+    std::filesystem::path path32 = dir_path + 
"/util/test_data/cgroup_cpu_data/test32/child";
+    std::filesystem::path default_path_32 = dir_path + 
"/util/test_data/cgroup_cpu_data/test32";
+    int ret32 = CGroupUtil::get_cgroup_v1_cpu_quota_number(path32, 
default_path_32, 96);
+    EXPECT_TRUE(ret32 == 6);
+    // 3.3 read default
+    std::filesystem::path path33 = dir_path + 
"/util/test_data/cgroup_cpu_data/test33/child";
+    std::filesystem::path default_path_33 = dir_path + 
"/util/test_data/cgroup_cpu_data/test33";
+    int ret33 = CGroupUtil::get_cgroup_v1_cpu_quota_number(path33, 
default_path_33, 96);
+    EXPECT_TRUE(ret33 == 96);
+
+    // 4 read cgroup v1 cpuset
+    std::filesystem::path path41 = dir_path + 
"/util/test_data/cgroup_cpu_data/test41";
+    int ret41 = CGroupUtil::get_cgroup_v1_cpuset_number(path41, 96);
+    EXPECT_TRUE(ret41 == 3);
+}
+
 } // namespace doris
diff --git a/be/test/util/test_data/cgroup_cpu_data/cpuset1 
b/be/test/util/test_data/cgroup_cpu_data/cpuset1
new file mode 100644
index 00000000000..f2fdae292d6
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/cpuset1
@@ -0,0 +1 @@
+1,4,6
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/cpuset2 
b/be/test/util/test_data/cgroup_cpu_data/cpuset2
new file mode 100644
index 00000000000..9528de88c0a
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/cpuset2
@@ -0,0 +1 @@
+1-5,7-10,20-21
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/cpuset3 
b/be/test/util/test_data/cgroup_cpu_data/cpuset3
new file mode 100644
index 00000000000..02c93d74ecd
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/cpuset3
@@ -0,0 +1 @@
+4,11-15,20,31-33
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test11/child/cpu.max 
b/be/test/util/test_data/cgroup_cpu_data/test11/child/cpu.max
new file mode 100644
index 00000000000..b22d43b0084
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test11/child/cpu.max
@@ -0,0 +1 @@
+max 100000 0
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test11/cpu.max 
b/be/test/util/test_data/cgroup_cpu_data/test11/cpu.max
new file mode 100644
index 00000000000..b22d43b0084
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test11/cpu.max
@@ -0,0 +1 @@
+max 100000 0
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test12/child/cpu.max 
b/be/test/util/test_data/cgroup_cpu_data/test12/child/cpu.max
new file mode 100644
index 00000000000..434d117ae1c
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test12/child/cpu.max
@@ -0,0 +1 @@
+300000 100000
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test12/cpu.max 
b/be/test/util/test_data/cgroup_cpu_data/test12/cpu.max
new file mode 100644
index 00000000000..20b625d5126
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test12/cpu.max
@@ -0,0 +1 @@
+200000 100000
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test13/child/cpu.max 
b/be/test/util/test_data/cgroup_cpu_data/test13/child/cpu.max
new file mode 100644
index 00000000000..b22d43b0084
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test13/child/cpu.max
@@ -0,0 +1 @@
+max 100000 0
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test13/cpu.max 
b/be/test/util/test_data/cgroup_cpu_data/test13/cpu.max
new file mode 100644
index 00000000000..20b625d5126
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test13/cpu.max
@@ -0,0 +1 @@
+200000 100000
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test14/child/cpu.max 
b/be/test/util/test_data/cgroup_cpu_data/test14/child/cpu.max
new file mode 100644
index 00000000000..434d117ae1c
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test14/child/cpu.max
@@ -0,0 +1 @@
+300000 100000
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test14/cpu.max 
b/be/test/util/test_data/cgroup_cpu_data/test14/cpu.max
new file mode 100644
index 00000000000..4199eb01a27
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test14/cpu.max
@@ -0,0 +1 @@
+400000 100000
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test21/child/cpuset.cpus.effective 
b/be/test/util/test_data/cgroup_cpu_data/test21/child/cpuset.cpus.effective
new file mode 100644
index 00000000000..fb00853f18d
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test21/child/cpuset.cpus.effective
@@ -0,0 +1 @@
+0-1
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test21/cpuset.cpus.effective 
b/be/test/util/test_data/cgroup_cpu_data/test21/cpuset.cpus.effective
new file mode 100644
index 00000000000..745f3eb7203
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test21/cpuset.cpus.effective
@@ -0,0 +1 @@
+0-6
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test22/child/cpuset.cpus.effective 
b/be/test/util/test_data/cgroup_cpu_data/test22/child/cpuset.cpus.effective
new file mode 100644
index 00000000000..e69de29bb2d
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test22/cpuset.cpus.effective 
b/be/test/util/test_data/cgroup_cpu_data/test22/cpuset.cpus.effective
new file mode 100644
index 00000000000..745f3eb7203
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test22/cpuset.cpus.effective
@@ -0,0 +1 @@
+0-6
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test31/child/cpu.cfs_period_us 
b/be/test/util/test_data/cgroup_cpu_data/test31/child/cpu.cfs_period_us
new file mode 100644
index 00000000000..483fb82b6dd
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test31/child/cpu.cfs_period_us
@@ -0,0 +1 @@
+100000
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test31/child/cpu.cfs_quota_us 
b/be/test/util/test_data/cgroup_cpu_data/test31/child/cpu.cfs_quota_us
new file mode 100644
index 00000000000..516a58aff39
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test31/child/cpu.cfs_quota_us
@@ -0,0 +1 @@
+500000
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test31/cpu.cfs_period_us 
b/be/test/util/test_data/cgroup_cpu_data/test31/cpu.cfs_period_us
new file mode 100644
index 00000000000..483fb82b6dd
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test31/cpu.cfs_period_us
@@ -0,0 +1 @@
+100000
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test31/cpu.cfs_quota_us 
b/be/test/util/test_data/cgroup_cpu_data/test31/cpu.cfs_quota_us
new file mode 100644
index 00000000000..212f56fce5d
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test31/cpu.cfs_quota_us
@@ -0,0 +1 @@
+600000
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test32/child/cpu.cfs_period_us 
b/be/test/util/test_data/cgroup_cpu_data/test32/child/cpu.cfs_period_us
new file mode 100644
index 00000000000..483fb82b6dd
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test32/child/cpu.cfs_period_us
@@ -0,0 +1 @@
+100000
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test32/child/cpu.cfs_quota_us 
b/be/test/util/test_data/cgroup_cpu_data/test32/child/cpu.cfs_quota_us
new file mode 100644
index 00000000000..d7d17fcbef9
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test32/child/cpu.cfs_quota_us
@@ -0,0 +1 @@
+-1
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test32/cpu.cfs_period_us 
b/be/test/util/test_data/cgroup_cpu_data/test32/cpu.cfs_period_us
new file mode 100644
index 00000000000..483fb82b6dd
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test32/cpu.cfs_period_us
@@ -0,0 +1 @@
+100000
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test32/cpu.cfs_quota_us 
b/be/test/util/test_data/cgroup_cpu_data/test32/cpu.cfs_quota_us
new file mode 100644
index 00000000000..212f56fce5d
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test32/cpu.cfs_quota_us
@@ -0,0 +1 @@
+600000
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test33/child/cpu.cfs_period_us 
b/be/test/util/test_data/cgroup_cpu_data/test33/child/cpu.cfs_period_us
new file mode 100644
index 00000000000..483fb82b6dd
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test33/child/cpu.cfs_period_us
@@ -0,0 +1 @@
+100000
\ No newline at end of file
diff --git 
a/be/test/util/test_data/cgroup_cpu_data/test33/child/cpu.cfs_quota_us 
b/be/test/util/test_data/cgroup_cpu_data/test33/child/cpu.cfs_quota_us
new file mode 100644
index 00000000000..d7d17fcbef9
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test33/child/cpu.cfs_quota_us
@@ -0,0 +1 @@
+-1
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test33/cpu.cfs_period_us 
b/be/test/util/test_data/cgroup_cpu_data/test33/cpu.cfs_period_us
new file mode 100644
index 00000000000..483fb82b6dd
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test33/cpu.cfs_period_us
@@ -0,0 +1 @@
+100000
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test33/cpu.cfs_quota_us 
b/be/test/util/test_data/cgroup_cpu_data/test33/cpu.cfs_quota_us
new file mode 100644
index 00000000000..d7d17fcbef9
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test33/cpu.cfs_quota_us
@@ -0,0 +1 @@
+-1
\ No newline at end of file
diff --git a/be/test/util/test_data/cgroup_cpu_data/test41/cpuset.cpus 
b/be/test/util/test_data/cgroup_cpu_data/test41/cpuset.cpus
new file mode 100644
index 00000000000..b62d3ca93d6
--- /dev/null
+++ b/be/test/util/test_data/cgroup_cpu_data/test41/cpuset.cpus
@@ -0,0 +1 @@
+1-3
\ No newline at end of file


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

Reply via email to