Updated Branches:
  refs/heads/master caa3c301f -> 6fcc6b935

Added timeval retrieval from sysctl.

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


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

Branch: refs/heads/master
Commit: 83e1547fe57ba1ff58630a615f2670657a6340d1
Parents: caa3c30
Author: Benjamin Mahler <bmah...@twitter.com>
Authored: Tue Dec 17 14:56:51 2013 -0800
Committer: Benjamin Mahler <bmah...@twitter.com>
Committed: Thu Dec 19 14:12:24 2013 -0800

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/os/sysctl.hpp  | 21 +++++++++++++++++---
 .../3rdparty/stout/tests/os_tests.cpp           | 17 ++++++++++++++++
 2 files changed, 35 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/83e1547f/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp 
b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp
index 065aada..05b0678 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/sysctl.hpp
@@ -9,6 +9,7 @@
 #include <string>
 #include <vector>
 
+#include <sys/time.h>
 #include <sys/types.h>
 #include <sys/sysctl.h>
 
@@ -29,8 +30,8 @@ namespace os {
 //   os::sysctl(CTL_KERN, KERN_MAXPROC)
 //
 // To _retrieve_ the value you need to use one of the 'integer',
-// 'string', or 'table' methods to indicate the type of the value
-// being retrieved. For example:
+// 'string', 'table', or 'time' methods to indicate the type of the
+// value being retrieved. For example:
 //
 //   Try<int> maxproc = os::sysctl(CTL_KERN, KERN_MAXPROC).integer();
 //
@@ -65,9 +66,12 @@ public:
   // Get system information as a string.
   Try<std::string> string() const;
 
+  // Get system information as a timeval.
+  Try<timeval> time() const;
+
   // Get system information as a table, optionally specifying a
   // length. Note that this function is lazy and will not actually
-  // perform the syscall until you cast (implicitely or explicitly) a
+  // perform the syscall until you cast (implicitly or explicitly) a
   // 'Table' to a std::vector<T>. For example, to get the first 10
   // processes in the process table you can do:
   //
@@ -194,6 +198,17 @@ inline Try<std::string> sysctl::string() const
 }
 
 
+inline Try<timeval> sysctl::time() const
+{
+  timeval result;
+  size_t size = sizeof(result);
+  if (::sysctl(name, levels, &result, &size, NULL, 0) == -1) {
+    return ErrnoError();
+  }
+  return result;
+}
+
+
 inline sysctl::Table sysctl::table(const Option<size_t>& length) const
 {
   return Table(levels, name, length);

http://git-wip-us.apache.org/repos/asf/mesos/blob/83e1547f/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp 
b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
index a0b624b..33c2ee1 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os_tests.cpp
@@ -2,6 +2,10 @@
 
 #include <gtest/gtest.h>
 
+#ifndef __linux__
+#include <sys/time.h> // For gettimeofday.
+#endif
+
 #include <cstdlib> // For rand.
 #include <list>
 #include <set>
@@ -225,6 +229,7 @@ TEST_F(OsTest, sleep)
 #ifdef __APPLE__
 TEST_F(OsTest, sysctl)
 {
+  // String test.
   Try<os::UTSInfo> uname = os::uname();
 
   ASSERT_SOME(uname);
@@ -239,10 +244,12 @@ TEST_F(OsTest, sysctl)
   ASSERT_SOME(type);
   EXPECT_EQ(uname.get().sysname, type.get());
 
+  // Integer test.
   Try<int> maxproc = os::sysctl(CTL_KERN, KERN_MAXPROC).integer();
 
   ASSERT_SOME(maxproc);
 
+  // Table test.
   Try<std::vector<kinfo_proc> > processes =
     os::sysctl(CTL_KERN, KERN_PROC, KERN_PROC_ALL).table(maxproc.get());
 
@@ -255,6 +262,16 @@ TEST_F(OsTest, sysctl)
   }
 
   EXPECT_EQ(1, pids.count(getpid()));
+
+  // Timeval test.
+  Try<timeval> bootTime = os::sysctl(CTL_KERN, KERN_BOOTTIME).time();
+  ASSERT_SOME(bootTime);
+
+  timeval time;
+  gettimeofday(&time, NULL);
+
+  EXPECT_GT(Seconds(bootTime.get().tv_sec), Seconds(0));
+  EXPECT_LT(Seconds(bootTime.get().tv_sec), Seconds(time.tv_sec));
 }
 #endif // __APPLE__
 

Reply via email to