Repository: mesos Updated Branches: refs/heads/master 89ffe695c -> 0e101e266
Collect throttle related cpu.stat for Docker Containerizer. Review: https://reviews.apache.org/r/51009/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/0e101e26 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/0e101e26 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/0e101e26 Branch: refs/heads/master Commit: 0e101e2662be6f4fecd15502b116b5d413aa48b2 Parents: 89ffe69 Author: Zhitao Li <zhitaoli...@gmail.com> Authored: Wed Oct 12 23:04:22 2016 -0700 Committer: Jie Yu <yujie....@gmail.com> Committed: Wed Oct 12 23:04:22 2016 -0700 ---------------------------------------------------------------------- src/slave/containerizer/docker.cpp | 65 +++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 11 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/0e101e26/src/slave/containerizer/docker.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/docker.cpp b/src/slave/containerizer/docker.cpp index d713860..9a1a871 100644 --- a/src/slave/containerizer/docker.cpp +++ b/src/slave/containerizer/docker.cpp @@ -1705,13 +1705,13 @@ Try<ResourceStatistics> DockerContainerizerProcess::cgroupsStatistics( #ifndef __linux__ return Error("Does not support cgroups on non-linux platform"); #else - const Result<string> cpuHierarchy = cgroups::hierarchy("cpuacct"); + const Result<string> cpuacctHierarchy = cgroups::hierarchy("cpuacct"); const Result<string> memHierarchy = cgroups::hierarchy("memory"); - if (cpuHierarchy.isError()) { + if (cpuacctHierarchy.isError()) { return Error( - "Failed to determine the cgroup 'cpu' subsystem hierarchy: " + - cpuHierarchy.error()); + "Failed to determine the cgroup 'cpuacct' subsystem hierarchy: " + + cpuacctHierarchy.error()); } if (memHierarchy.isError()) { @@ -1720,13 +1720,13 @@ Try<ResourceStatistics> DockerContainerizerProcess::cgroupsStatistics( memHierarchy.error()); } - const Result<string> cpuCgroup = cgroups::cpuacct::cgroup(pid); - if (cpuCgroup.isError()) { + const Result<string> cpuacctCgroup = cgroups::cpuacct::cgroup(pid); + if (cpuacctCgroup.isError()) { return Error( - "Failed to determine cgroup for the 'cpu' subsystem: " + - cpuCgroup.error()); - } else if (cpuCgroup.isNone()) { - return Error("Unable to find 'cpu' cgroup subsystem"); + "Failed to determine cgroup for the 'cpuacct' subsystem: " + + cpuacctCgroup.error()); + } else if (cpuacctCgroup.isNone()) { + return Error("Unable to find 'cpuacct' cgroup subsystem"); } const Result<string> memCgroup = cgroups::memory::cgroup(pid); @@ -1739,7 +1739,7 @@ Try<ResourceStatistics> DockerContainerizerProcess::cgroupsStatistics( } const Try<cgroups::cpuacct::Stats> cpuAcctStat = - cgroups::cpuacct::stat(cpuHierarchy.get(), cpuCgroup.get()); + cgroups::cpuacct::stat(cpuacctHierarchy.get(), cpuacctCgroup.get()); if (cpuAcctStat.isError()) { return Error("Failed to get cpu.stat: " + cpuAcctStat.error()); @@ -1764,6 +1764,49 @@ Try<ResourceStatistics> DockerContainerizerProcess::cgroupsStatistics( result.set_cpus_user_time_secs(cpuAcctStat.get().user.secs()); result.set_mem_rss_bytes(memStats.get().at("rss")); + // Add the cpu.stat information only if CFS is enabled. + if (flags.cgroups_enable_cfs) { + const Result<string> cpuHierarchy = cgroups::hierarchy("cpu"); + + if (cpuHierarchy.isError()) { + return Error( + "Failed to determine the cgroup 'cpu' subsystem hierarchy: " + + cpuHierarchy.error()); + } + + const Result<string> cpuCgroup = cgroups::cpu::cgroup(pid); + if (cpuCgroup.isError()) { + return Error( + "Failed to determine cgroup for the 'cpu' subsystem: " + + cpuCgroup.error()); + } else if (cpuCgroup.isNone()) { + return Error("Unable to find 'cpu' cgroup subsystem"); + } + + const Try<hashmap<string, uint64_t>> stat = + cgroups::stat(cpuHierarchy.get(), cpuCgroup.get(), "cpu.stat"); + + if (stat.isError()) { + return Error("Failed to read cpu.stat: " + stat.error()); + } + + Option<uint64_t> nr_periods = stat.get().get("nr_periods"); + if (nr_periods.isSome()) { + result.set_cpus_nr_periods(nr_periods.get()); + } + + Option<uint64_t> nr_throttled = stat.get().get("nr_throttled"); + if (nr_throttled.isSome()) { + result.set_cpus_nr_throttled(nr_throttled.get()); + } + + Option<uint64_t> throttled_time = stat.get().get("throttled_time"); + if (throttled_time.isSome()) { + result.set_cpus_throttled_time_secs( + Nanoseconds(throttled_time.get()).secs()); + } + } + return result; #endif // __linux__ }