You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by bm...@apache.org on 2014/05/02 00:59:56 UTC
[1/3] git commit: Add 'value' and 'units' methods to Duration
subclasses.
Repository: mesos
Updated Branches:
refs/heads/master ef6423cdc -> d488357c5
Add 'value' and 'units' methods to Duration subclasses.
Review: https://reviews.apache.org/r/20922
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/00f70918
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/00f70918
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/00f70918
Branch: refs/heads/master
Commit: 00f7091856b811a45858b77af1ccafd9cfa8f3a3
Parents: ef6423c
Author: Dominic Hamon <dh...@twopensource.com>
Authored: Thu May 1 15:55:43 2014 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Thu May 1 15:55:43 2014 -0700
----------------------------------------------------------------------
.../3rdparty/stout/include/stout/duration.hpp | 62 +++++++++++++++-----
1 file changed, 47 insertions(+), 15 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/00f70918/3rdparty/libprocess/3rdparty/stout/include/stout/duration.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/duration.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/duration.hpp
index ea5017f..f344705 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/duration.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/duration.hpp
@@ -189,6 +189,10 @@ public:
: Duration(nanoseconds, NANOSECONDS) {}
Nanoseconds(const Duration& d) : Duration(d) {}
+
+ double value() const { return static_cast<double>(this->ns()); }
+
+ static std::string units() { return "ns"; }
};
@@ -199,6 +203,10 @@ public:
: Duration(microseconds, MICROSECONDS) {}
Microseconds(const Duration& d) : Duration(d) {}
+
+ double value() const { return this->us(); }
+
+ static std::string units() { return "us"; }
};
@@ -209,6 +217,10 @@ public:
: Duration(milliseconds, MILLISECONDS) {}
Milliseconds(const Duration& d) : Duration(d) {}
+
+ double value() const { return this->ms(); }
+
+ static std::string units() { return "ms"; }
};
@@ -219,6 +231,10 @@ public:
: Duration(seconds, SECONDS) {}
Seconds(const Duration& d) : Duration(d) {}
+
+ double value() const { return this->secs(); }
+
+ static std::string units() { return "secs"; }
};
@@ -229,6 +245,10 @@ public:
: Duration(minutes, MINUTES) {}
Minutes(const Duration& d) : Duration(d) {}
+
+ double value() const { return this->mins(); }
+
+ static std::string units() { return "mins"; }
};
@@ -239,6 +259,10 @@ public:
: Duration(hours, HOURS) {}
Hours(const Duration& d) : Duration(d) {}
+
+ double value() const { return this->hrs(); }
+
+ static std::string units() { return "hrs"; }
};
@@ -249,6 +273,10 @@ public:
: Duration(days, DAYS) {}
Days(const Duration& d) : Duration(d) {}
+
+ double value() const { return this->days(); }
+
+ static std::string units() { return "days"; }
};
@@ -258,6 +286,10 @@ public:
explicit Weeks(int32_t value) : Duration(value, WEEKS) {}
Weeks(const Duration& d) : Duration(d) {}
+
+ double value() const { return this->weeks(); }
+
+ static std::string units() { return "weeks"; }
};
@@ -291,56 +323,56 @@ inline std::ostream& operator << (
// instead of 'weeks' to output the duration.
int64_t nanoseconds = duration.ns();
if (duration < Microseconds(1)) {
- stream << duration.ns() << "ns";
+ stream << duration.ns() << Nanoseconds::units();
} else if (duration < Milliseconds(1)) {
if (nanoseconds % Duration::MICROSECONDS != 0) {
// We can't get a whole number using this unit but we can at
// one level down.
- stream << duration.ns() << "ns";
+ stream << duration.ns() << Nanoseconds::units();
} else {
- stream << duration.us() << "us";
+ stream << duration.us() << Microseconds::units();
}
} else if (duration < Seconds(1)) {
if (nanoseconds % Duration::MILLISECONDS != 0 &&
nanoseconds % Duration::MICROSECONDS == 0) {
- stream << duration.us() << "us";
+ stream << duration.us() << Microseconds::units();
} else {
- stream << duration.ms() << "ms";
+ stream << duration.ms() << Milliseconds::units();
}
} else if (duration < Minutes(1)) {
if (nanoseconds % Duration::SECONDS != 0 &&
nanoseconds % Duration::MILLISECONDS == 0) {
- stream << duration.ms() << "ms";
+ stream << duration.ms() << Milliseconds::units();
} else {
- stream << duration.secs() << "secs";
+ stream << duration.secs() << Seconds::units();
}
} else if (duration < Hours(1)) {
if (nanoseconds % Duration::MINUTES != 0 &&
nanoseconds % Duration::SECONDS == 0) {
- stream << duration.secs() << "secs";
+ stream << duration.secs() << Seconds::units();
} else {
- stream << duration.mins() << "mins";
+ stream << duration.mins() << Minutes::units();
}
} else if (duration < Days(1)) {
if (nanoseconds % Duration::HOURS != 0 &&
nanoseconds % Duration::MINUTES == 0) {
- stream << duration.mins() << "mins";
+ stream << duration.mins() << Minutes::units();
} else {
- stream << duration.hrs() << "hrs";
+ stream << duration.hrs() << Hours::units();
}
} else if (duration < Weeks(1)) {
if (nanoseconds % Duration::DAYS != 0 &&
nanoseconds % Duration::HOURS == 0) {
- stream << duration.hrs() << "hrs";
+ stream << duration.hrs() << Hours::units();
} else {
- stream << duration.days() << "days";
+ stream << duration.days() << Days::units();
}
} else {
if (nanoseconds % Duration::WEEKS != 0 &&
nanoseconds % Duration::DAYS == 0) {
- stream << duration.days() << "days";
+ stream << duration.days() << Days::units();
} else {
- stream << duration.weeks() << "weeks";
+ stream << duration.weeks() << Weeks::units();
}
}
[3/3] git commit: Added template parameter to Timer.
Posted by bm...@apache.org.
Added template parameter to Timer.
Review: https://reviews.apache.org/r/20925
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/d488357c
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/d488357c
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/d488357c
Branch: refs/heads/master
Commit: d488357c55b2fbacd791c98cd70a58c56f0ddd0a
Parents: 88c235a
Author: Dominic Hamon <dh...@twopensource.com>
Authored: Thu May 1 15:56:18 2014 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Thu May 1 15:56:18 2014 -0700
----------------------------------------------------------------------
src/master/registrar.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/d488357c/src/master/registrar.cpp
----------------------------------------------------------------------
diff --git a/src/master/registrar.cpp b/src/master/registrar.cpp
index e4b0b39..fecc314 100644
--- a/src/master/registrar.cpp
+++ b/src/master/registrar.cpp
@@ -152,8 +152,8 @@ private:
Gauge queued_operations;
- Timer state_fetch;
- Timer state_store;
+ Timer<Milliseconds> state_fetch;
+ Timer<Milliseconds> state_store;
} metrics;
// Gauge handlers
[2/3] git commit: Used Duration subclasses to allow Timer users to
specify units.
Posted by bm...@apache.org.
Used Duration subclasses to allow Timer users to specify units.
Review: https://reviews.apache.org/r/20923
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/88c235a8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/88c235a8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/88c235a8
Branch: refs/heads/master
Commit: 88c235a842c335f0f904d57798808106803faf23
Parents: 00f7091
Author: Dominic Hamon <dh...@twopensource.com>
Authored: Thu May 1 15:55:59 2014 -0700
Committer: Benjamin Mahler <bm...@twitter.com>
Committed: Thu May 1 15:55:59 2014 -0700
----------------------------------------------------------------------
.../libprocess/include/process/metrics/timer.hpp | 18 +++++++++---------
3rdparty/libprocess/src/tests/metrics_tests.cpp | 7 +++++--
2 files changed, 14 insertions(+), 11 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/88c235a8/3rdparty/libprocess/include/process/metrics/timer.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/metrics/timer.hpp b/3rdparty/libprocess/include/process/metrics/timer.hpp
index 26f997c..9236954 100644
--- a/3rdparty/libprocess/include/process/metrics/timer.hpp
+++ b/3rdparty/libprocess/include/process/metrics/timer.hpp
@@ -17,16 +17,18 @@
namespace process {
namespace metrics {
-// A Metric that represents a timed event in milliseconds.
+// A Metric that represents a timed event. It is templated on a Duration
+// subclass that specifies the unit to use for the Timer.
// TODO(dhamon): Allow the user to choose the unit of duration.
// We could do this by adding methods on Duration subclasses to return
// the double value and unit string directly.
+template<class T>
class Timer : public Metric
{
public:
- // The Timer name will have "_ms" as an implicit unit suffix.
+ // The Timer name will have a unit suffix added automatically.
Timer(const std::string& name, const Option<Duration>& window = None())
- : Metric(name + "_ms", window),
+ : Metric(name + "_" + T::units(), window),
data(new Data()) {}
Future<double> value() const
@@ -65,8 +67,7 @@ public:
{
data->stopwatch.stop();
- // Assume milliseconds for now.
- data->lastValue = data->stopwatch.elapsed().ms();
+ data->lastValue = T(data->stopwatch.elapsed()).value();
value = data->lastValue.get();
}
@@ -76,8 +77,8 @@ public:
}
// Time an asynchronous event.
- template<typename T>
- Future<T> time(const Future<T>& future)
+ template<typename U>
+ Future<U> time(const Future<U>& future)
{
Stopwatch stopwatch;
stopwatch.start();
@@ -107,8 +108,7 @@ private:
process::internal::acquire(&that.data->lock);
{
- // Assume milliseconds for now.
- that.data->lastValue = stopwatch.elapsed().ms();
+ that.data->lastValue = T(stopwatch.elapsed()).value();
value = that.data->lastValue.get();
}
process::internal::release(&that.data->lock);
http://git-wip-us.apache.org/repos/asf/mesos/blob/88c235a8/3rdparty/libprocess/src/tests/metrics_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/tests/metrics_tests.cpp b/3rdparty/libprocess/src/tests/metrics_tests.cpp
index 75f1f0e..9f04b9b 100644
--- a/3rdparty/libprocess/src/tests/metrics_tests.cpp
+++ b/3rdparty/libprocess/src/tests/metrics_tests.cpp
@@ -240,7 +240,8 @@ TEST(Metrics, SnapshotStatistics)
TEST(Metrics, Timer)
{
- metrics::Timer timer("test/timer");
+ metrics::Timer<Nanoseconds> timer("test/timer");
+ EXPECT_EQ("test/timer_ns", timer.name());
AWAIT_READY(metrics::add(timer));
@@ -267,7 +268,9 @@ TEST(Metrics, Timer)
// is correctly timing futures.
TEST(Metrics, AsyncTimer)
{
- metrics::Timer t("test/timer");
+ metrics::Timer<Microseconds> t("test/timer");
+ EXPECT_EQ("test/timer_us", t.name());
+
AWAIT_READY(metrics::add(t));
Future<int> result = 42;