You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2017/12/01 00:06:00 UTC

[06/10] mesos git commit: Windows: Added `os::get_job_mem` to stout.

Windows: Added `os::get_job_mem` to stout.

This function sums the working set size for each process in a job object
represented by the PID. The Windows API does not support this directly.
Instead, the list of processes in a job object must be obtained, and
then for each process, the memory usage must be queried.

Review: https://reviews.apache.org/r/63274


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b81784d8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b81784d8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b81784d8

Branch: refs/heads/master
Commit: b81784d8387e4cea7fde581527cc774ded36bd30
Parents: d11d6d2
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Oct 18 15:30:50 2017 -0700
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Thu Nov 30 15:54:53 2017 -0800

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/os.hpp | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b81784d8/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index b0b1b8d..3713eb6 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -18,10 +18,12 @@
 #include <list>
 #include <map>
 #include <memory>
+#include <numeric>
 #include <set>
 #include <string>
 #include <vector>
 
+#include <stout/bytes.hpp>
 #include <stout/duration.hpp>
 #include <stout/none.hpp>
 #include <stout/nothing.hpp>
@@ -846,6 +848,26 @@ inline Try<std::set<Process>> get_job_processes(pid_t pid)
 }
 
 
+inline Try<Bytes> get_job_mem(pid_t pid) {
+  const Try<std::set<Process>> processes = os::get_job_processes(pid);
+  if (processes.isError()) {
+    return Error(processes.error());
+  }
+
+  return std::accumulate(
+    processes.get().cbegin(),
+    processes.get().cend(),
+    Bytes(0),
+    [](const Bytes& bytes, const Process& process) {
+      if (process.rss.isNone()) {
+        return bytes;
+      }
+
+      return bytes + process.rss.get();
+    });
+}
+
+
 // `set_job_cpu_limit` sets a CPU limit for the process represented by
 // `pid`, assuming it is assigned to a job object. This function will fail
 // otherwise. This limit is a hard cap enforced by the OS.