bmahler commented on code in PR #531:
URL: https://github.com/apache/mesos/pull/531#discussion_r1540108310
##########
src/linux/cgroups2.cpp:
##########
@@ -465,6 +465,53 @@ const std::string UCLAMP_MIN = "cpu.uclamp.min";
const std::string WEIGHT = "cpu.weight";
const std::string WEIGHT_NICE = "cpu.weight.nice";
+namespace stat {
+
+Try<Stats> parse(const string& content)
+{
+ const vector<string>& lines = strings::split(content, "\n");
+ cpu::Stats stats;
+
+ foreach (const string& line, lines) {
+ const string trimmed = strings::trim(line);
+ if (trimmed.empty()) {
+ continue;
+ }
+
+ vector<string> tokens = strings::split(trimmed, " ");
+ if (tokens.size() != 2) {
+ return Error(
+ "Invalid line format in 'cpu.stat' expected "
+ "<key> <value> received: '" + trimmed + "'");
+ }
+
+ string field = tokens[0];
+ string value = tokens[1];
+
+ Try<Duration> duration = Duration::parse(value + "us");
Review Comment:
we can just construct Duration using `Duration d =
Microseconds(static_cast<int64_t>(*number))`
##########
src/linux/cgroups2.cpp:
##########
@@ -465,6 +465,53 @@ const std::string UCLAMP_MIN = "cpu.uclamp.min";
const std::string WEIGHT = "cpu.weight";
const std::string WEIGHT_NICE = "cpu.weight.nice";
+namespace stat {
+
+Try<Stats> parse(const string& content)
+{
+ const vector<string>& lines = strings::split(content, "\n");
+ cpu::Stats stats;
+
+ foreach (const string& line, lines) {
+ const string trimmed = strings::trim(line);
+ if (trimmed.empty()) {
+ continue;
+ }
+
+ vector<string> tokens = strings::split(trimmed, " ");
+ if (tokens.size() != 2) {
+ return Error(
+ "Invalid line format in 'cpu.stat' expected "
+ "<key> <value> received: '" + trimmed + "'");
+ }
+
+ string field = tokens[0];
+ string value = tokens[1];
Review Comment:
no need to copy these
##########
src/tests/containerizer/cgroups2_tests.cpp:
##########
@@ -134,6 +154,12 @@ TEST_F(Cgroups2Test, ROOT_CGROUPS2_AssignProcesses)
AWAIT_EXPECT_WTERMSIG_EQ(SIGKILL, process::reap(pid));
}
+
+TEST_F(Cgroups2CpuTest, ROOT_CGROUPS2_CpuStats)
+{
+ ASSERT_SOME(cgroups2::cpu::stats(TEST_CGROUP));
+}
+
Review Comment:
Instead of adding a new fixture, we can keep the same fixture but add a
function that:
* enables requested controllers
* remembers the side effect
* disables the controllers that were added, during TearDown
##########
src/linux/cgroups2.cpp:
##########
@@ -473,7 +520,7 @@ Try<Nothing> weight(const string& cgroup, uint64_t weight)
return Error("Operation not supported for the root cgroup");
}
- return cgroups2::write(cgroup, cpu::control::WEIGHT, weight);
+ return cgroups2::write<uint64_t>(cgroup, cpu::control::WEIGHT, weight);
Review Comment:
whoops?
--
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]