Merge "MediaMetrics: Unify Elem of TimeMachine with Elem of Item"
diff --git a/services/mediametrics/TimeMachine.h b/services/mediametrics/TimeMachine.h
index b3932de..8682360 100644
--- a/services/mediametrics/TimeMachine.h
+++ b/services/mediametrics/TimeMachine.h
@@ -35,6 +35,14 @@
return s;
}
+// define a way of printing a std::pair.
+template <typename T, typename U>
+std::ostream & operator<< (std::ostream& s,
+ const std::pair<T, U>& v) {
+ s << "{ " << v.first << ", " << v.second << " }";
+ return s;
+}
+
// define a way of printing a variant
// see https://en.cppreference.com/w/cpp/utility/variant/visit
template <typename T0, typename ... Ts>
@@ -53,10 +61,12 @@
* The TimeMachine is NOT thread safe.
*/
class TimeMachine {
-
- using Elem = std::variant<std::monostate, int32_t, int64_t, double, std::string>;
+public:
+ using Elem = Item::Prop::Elem; // use the Item property element.
using PropertyHistory = std::multimap<int64_t /* time */, Elem>;
+private:
+
// KeyHistory contains no lock.
// Access is through the TimeMachine, and a hash-striped lock is used
// before calling into KeyHistory.
@@ -102,7 +112,8 @@
void putProp(
const std::string &name, const mediametrics::Item::Prop &prop, int64_t time = 0) {
- prop.visit([&](auto value) { putValue(name, value, time); });
+ //alternatively: prop.visit([&](auto value) { putValue(name, value, time); });
+ putValue(name, prop.get(), time);
}
template <typename T>
@@ -119,13 +130,6 @@
}
}
- // Explicitly ignore rate properties - we don't expose them for now.
- void putValue(
- const std::string &property __unused,
- std::pair<int64_t, int64_t>& e __unused,
- int64_t time __unused) {
- }
-
std::pair<std::string, int32_t> dump(int32_t lines, int64_t time) const {
std::stringstream ss;
int32_t ll = lines;
@@ -358,10 +362,10 @@
std::stringstream ss;
int32_t ll = lines;
- for (const auto &keyPair : mHistory) {
- std::lock_guard lock(getLockForKey(keyPair.first));
+ for (const auto &[lkey, lhist] : mHistory) {
+ std::lock_guard lock(getLockForKey(lkey));
if (lines <= 0) break;
- auto [s, l] = keyPair.second->dump(ll, time);
+ auto [s, l] = lhist->dump(ll, time);
ss << s;
ll -= l;
}