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 2014/05/28 00:10:10 UTC

git commit: Uninlined large function from usage.hpp.

Repository: mesos
Updated Branches:
  refs/heads/master 10bc2b923 -> 3dd88aa1c


Uninlined large function from usage.hpp.

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


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

Branch: refs/heads/master
Commit: 3dd88aa1c784fcaac86c46e654650a1dd095d683
Parents: 10bc2b9
Author: Dominic Hamon <dh...@twopensource.com>
Authored: Tue May 27 15:09:56 2014 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Tue May 27 15:09:56 2014 -0700

----------------------------------------------------------------------
 src/Makefile.am     |  1 +
 src/usage/usage.cpp | 84 ++++++++++++++++++++++++++++++++++++++++++++++++
 src/usage/usage.hpp | 59 ++--------------------------------
 3 files changed, 87 insertions(+), 57 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3dd88aa1/src/Makefile.am
----------------------------------------------------------------------
diff --git a/src/Makefile.am b/src/Makefile.am
index 86fd0a4..ffde59b 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -228,6 +228,7 @@ libmesos_no_3rdparty_la_SOURCES =					\
 	common/values.cpp						\
 	files/files.cpp							\
 	logging/logging.cpp						\
+	usage/usage.cpp							\
 	zookeeper/contender.cpp						\
 	zookeeper/detector.cpp						\
 	zookeeper/zookeeper.cpp						\

http://git-wip-us.apache.org/repos/asf/mesos/blob/3dd88aa1/src/usage/usage.cpp
----------------------------------------------------------------------
diff --git a/src/usage/usage.cpp b/src/usage/usage.cpp
new file mode 100644
index 0000000..29014d1
--- /dev/null
+++ b/src/usage/usage.cpp
@@ -0,0 +1,84 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <unistd.h> // For pid_t.
+
+#include <deque>
+
+#include <process/clock.hpp>
+
+#include <stout/foreach.hpp>
+#include <stout/os.hpp>
+
+#include "usage/usage.hpp"
+
+namespace mesos {
+namespace internal {
+
+ResourceStatistics usage(pid_t pid, bool mem, bool cpus)
+{
+  Try<os::ProcessTree> pstree = os::pstree(pid);
+
+  if (pstree.isError()) {
+    return ResourceStatistics();
+  }
+
+  ResourceStatistics statistics;
+
+  // The timestamp is the only required field.
+  statistics.set_timestamp(process::Clock::now().secs());
+
+  std::deque<os::ProcessTree> trees;
+  trees.push_back(pstree.get());
+
+  while (!trees.empty()) {
+    const os::ProcessTree& tree = trees.front();
+
+    if (mem) {
+      if (tree.process.rss.isSome()) {
+        statistics.set_mem_rss_bytes(
+            statistics.mem_rss_bytes() + tree.process.rss.get().bytes());
+      }
+    }
+
+    // We only show utime and stime when both are available, otherwise
+    // we're exposing a partial view of the CPU times.
+    if (cpus) {
+      if (tree.process.utime.isSome() && tree.process.stime.isSome()) {
+        statistics.set_cpus_user_time_secs(
+            statistics.cpus_user_time_secs() +
+            tree.process.utime.get().secs());
+
+        statistics.set_cpus_system_time_secs(
+            statistics.cpus_system_time_secs() +
+            tree.process.stime.get().secs());
+      }
+    }
+
+    foreach (const os::ProcessTree& child, tree.children) {
+      trees.push_back(child);
+    }
+
+    trees.pop_front();
+  }
+
+  return statistics;
+}
+
+} // namespace internal {
+} // namespace mesos {

http://git-wip-us.apache.org/repos/asf/mesos/blob/3dd88aa1/src/usage/usage.hpp
----------------------------------------------------------------------
diff --git a/src/usage/usage.hpp b/src/usage/usage.hpp
index af04a6a..5a76746 100644
--- a/src/usage/usage.hpp
+++ b/src/usage/usage.hpp
@@ -21,14 +21,7 @@
 
 #include <unistd.h> // For pid_t.
 
-#include <deque>
-
-#include <mesos/mesos.hpp>
-
-#include <process/clock.hpp>
-
-#include <stout/foreach.hpp>
-#include <stout/os.hpp>
+#include "mesos/mesos.hpp"
 
 namespace mesos {
 namespace internal {
@@ -36,55 +29,7 @@ namespace internal {
 // Collects resource usage of a process tree rooted at 'pid'. Only
 // collects the 'mem_*' values if 'mem' is true and the 'cpus_*'
 // values if 'cpus' is true.
-ResourceStatistics usage(pid_t pid, bool mem = true, bool cpus = true)
-{
-  Try<os::ProcessTree> pstree = os::pstree(pid);
-
-  if (pstree.isError()) {
-    return ResourceStatistics();
-  }
-
-  ResourceStatistics statistics;
-
-  // The timestamp is the only required field.
-  statistics.set_timestamp(process::Clock::now().secs());
-
-  std::deque<os::ProcessTree> trees;
-  trees.push_back(pstree.get());
-
-  while (!trees.empty()) {
-    const os::ProcessTree& tree = trees.front();
-
-    if (mem) {
-      if (tree.process.rss.isSome()) {
-        statistics.set_mem_rss_bytes(
-            statistics.mem_rss_bytes() + tree.process.rss.get().bytes());
-      }
-    }
-
-    // We only show utime and stime when both are available, otherwise
-    // we're exposing a partial view of the CPU times.
-    if (cpus) {
-      if (tree.process.utime.isSome() && tree.process.stime.isSome()) {
-        statistics.set_cpus_user_time_secs(
-            statistics.cpus_user_time_secs() +
-            tree.process.utime.get().secs());
-
-        statistics.set_cpus_system_time_secs(
-            statistics.cpus_system_time_secs() +
-            tree.process.stime.get().secs());
-      }
-    }
-
-    foreach (const os::ProcessTree& child, tree.children) {
-      trees.push_back(child);
-    }
-
-    trees.pop_front();
-  }
-
-  return statistics;
-}
+ResourceStatistics usage(pid_t pid, bool mem = true, bool cpus = true);
 
 } // namespace internal {
 } // namespace mesos {