You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by vi...@apache.org on 2013/02/25 20:45:31 UTC
svn commit: r1449842 -
/incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp
Author: vinodkone
Date: Mon Feb 25 19:45:31 2013
New Revision: 1449842
URL: http://svn.apache.org/r1449842
Log:
Resource Monitoring 9: Implemented process based resource collection
for linux.
From: Ben Mahler <be...@gmail.com>
Review: https://reviews.apache.org/r/9146
Modified:
incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp
Modified: incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp?rev=1449842&r1=1449841&r2=1449842&view=diff
==============================================================================
--- incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp (original)
+++ incubator/mesos/trunk/src/slave/process_based_isolation_module.cpp Mon Feb 25 19:45:31 2013
@@ -23,6 +23,7 @@
#include <map>
+#include <process/clock.hpp>
#include <process/dispatch.hpp>
#include <process/id.hpp>
@@ -32,6 +33,10 @@
#include "common/type_utils.hpp"
#include "common/process_utils.hpp"
+#ifdef __linux__
+#include "linux/proc.hpp"
+#endif
+
#include "slave/flags.hpp"
#include "slave/process_based_isolation_module.hpp"
@@ -270,8 +275,44 @@ Future<ResourceStatistics> ProcessBasedI
const FrameworkID& frameworkId,
const ExecutorID& executorId)
{
+ if (!infos.contains(frameworkId) ||
+ !infos[frameworkId].contains(executorId)) {
+ return Future<ResourceStatistics>::failed("Unknown executor");
+ }
+
+ ProcessInfo* info = infos[frameworkId][executorId];
+
ResourceStatistics result;
- // TODO(bmahler): Compute resource usage.
+
+ result.set_timestamp(Clock::now());
+
+#ifdef __linux__
+ // Get the page size, used for memory accounting.
+ // NOTE: This is more portable than using getpagesize().
+ long pageSize = sysconf(_SC_PAGESIZE);
+
+ // Get the number of clock ticks, used for cpu accounting.
+ long ticks = sysconf(_SC_CLK_TCK);
+
+ Try<proc::ProcessStatistics> stat = proc::stat(info->pid);
+
+ if (stat.isSome() && pageSize > 0) {
+ result.set_memory_rss(stat.get().rss * pageSize);
+ }
+
+ if (stat.isSome() && ticks > 0) {
+ result.set_cpu_user_time((double) stat.get().utime / (double) ticks);
+ result.set_cpu_system_time((double) stat.get().stime / (double) ticks);
+ }
+#elif defined __APPLE__
+ // TODO(bmahler): Using mach interfaces is messy and subject to change,
+ // but I'm unable to find another method to do it on OSX.
+ // See here for a clean example:
+ // http://stackoverflow.com/questions/1543157/
+ // how-can-i-find-out-how-much-memory-my-c-app-is-using-on-the-mac
+ // NOTE: Need to confirm that root is not needed for child processes.
+#endif
+
return result;
}