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/05/06 22:57:12 UTC

[3/3] git commit: Fixed os::memory() and fs::available() to return Bytes.

Fixed os::memory() and fs::available() to return Bytes.

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


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

Branch: refs/heads/master
Commit: dc4c10a0b97f552c7b8d43f88c4105087f6e5680
Parents: 1647e68
Author: Vinod Kone <vi...@twitter.com>
Authored: Fri Apr 26 19:46:09 2013 -0700
Committer: Vinod Kone <vi...@twitter.com>
Committed: Mon May 6 13:55:44 2013 -0700

----------------------------------------------------------------------
 .../third_party/stout/include/stout/bytes.hpp      |   28 ++++++++++++++-
 .../third_party/stout/include/stout/fs.hpp         |    5 ++-
 .../third_party/stout/include/stout/os.hpp         |   11 +++---
 3 files changed, 36 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/dc4c10a0/third_party/libprocess/third_party/stout/include/stout/bytes.hpp
----------------------------------------------------------------------
diff --git a/third_party/libprocess/third_party/stout/include/stout/bytes.hpp b/third_party/libprocess/third_party/stout/include/stout/bytes.hpp
index 6a068f0..754fbb2 100644
--- a/third_party/libprocess/third_party/stout/include/stout/bytes.hpp
+++ b/third_party/libprocess/third_party/stout/include/stout/bytes.hpp
@@ -71,7 +71,17 @@ public:
   bool operator == (const Bytes& that) const { return value == that.value; }
   bool operator != (const Bytes& that) const { return value != that.value; }
 
-  // TODO(bmahler): Overload arithmetic operators..
+  Bytes& operator += (const Bytes& that)
+  {
+    value += that.value;
+    return *this;
+  }
+
+  Bytes& operator -= (const Bytes& that)
+  {
+    value -= that.value;
+    return *this;
+  }
 
 protected:
   static const uint64_t BYTES = 1;
@@ -131,4 +141,20 @@ inline std::ostream& operator << (std::ostream& stream, const Bytes& bytes)
   }
 }
 
+
+inline Bytes operator + (const Bytes& lhs, const Bytes& rhs)
+{
+  Bytes sum = lhs;
+  sum += rhs;
+  return sum;
+}
+
+
+inline Bytes operator - (const Bytes& lhs, const Bytes& rhs)
+{
+  Bytes diff = lhs;
+  diff -= rhs;
+  return diff;
+}
+
 #endif // __STOUT_BYTES_HPP__

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/dc4c10a0/third_party/libprocess/third_party/stout/include/stout/fs.hpp
----------------------------------------------------------------------
diff --git a/third_party/libprocess/third_party/stout/include/stout/fs.hpp b/third_party/libprocess/third_party/stout/include/stout/fs.hpp
index ef9fb18..c1a05b5 100644
--- a/third_party/libprocess/third_party/stout/include/stout/fs.hpp
+++ b/third_party/libprocess/third_party/stout/include/stout/fs.hpp
@@ -7,6 +7,7 @@
 
 #include <string>
 
+#include "bytes.hpp"
 #include "error.hpp"
 #include "nothing.hpp"
 #include "try.hpp"
@@ -15,13 +16,13 @@
 namespace fs {
 
 // Returns the total available disk size in bytes.
-inline Try<uint64_t> available(const std::string& path = "/")
+inline Try<Bytes> available(const std::string& path = "/")
 {
   struct statvfs buf;
   if (::statvfs(path.c_str(), &buf) < 0) {
     return ErrnoError();
   }
-  return buf.f_bavail * buf.f_frsize;
+  return Bytes(buf.f_bavail * buf.f_frsize);
 }
 
 

http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/dc4c10a0/third_party/libprocess/third_party/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/third_party/libprocess/third_party/stout/include/stout/os.hpp b/third_party/libprocess/third_party/stout/include/stout/os.hpp
index c71ae9e..29f6fbd 100644
--- a/third_party/libprocess/third_party/stout/include/stout/os.hpp
+++ b/third_party/libprocess/third_party/stout/include/stout/os.hpp
@@ -38,6 +38,7 @@
 #include <sstream>
 #include <string>
 
+#include "bytes.hpp"
 #include "duration.hpp"
 #include "error.hpp"
 #include "foreach.hpp"
@@ -933,8 +934,8 @@ inline Try<long> cpus()
 }
 
 
-// Returns the total size of main memory in bytes.
-inline Try<uint64_t> memory()
+// Returns the total size of main memory.
+inline Try<Bytes> memory()
 {
 #ifdef __linux__
   struct sysinfo info;
@@ -942,9 +943,9 @@ inline Try<uint64_t> memory()
     return ErrnoError();
   }
 # if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 3, 23)
-  return info.totalram * info.mem_unit;
+  return Bytes(info.totalram * info.mem_unit);
 # else
-  return info.totalram;
+  return Bytes(info.totalram);
 # endif
 #elif defined __APPLE__
   const size_t NAME_SIZE = 2;
@@ -958,7 +959,7 @@ inline Try<uint64_t> memory()
   if (sysctl(name, NAME_SIZE, &memory, &length, NULL, 0) < 0) {
     return ErrnoError("Failed to get sysctl of HW_MEMSIZE");
   }
-  return memory;
+  return Bytes(memory);
 #else
   return Error("Cannot determine the size of main memory");
 #endif