Move metrics time helpers to metrics_utils.
The metrics module reports metrics periodically, for which it needs to
keep track of the duration since some events (for example, the update
finished). These helpers were in the common/utils.h, but they rely on
the global SystemState to access both Prefs and Clock.
Since these helpers are specific to the metric reporting, this CL moves
them to the metrics_utils.h module.
Bug: 25197634
TEST=FEATURES=test emerge-link update_engine; mmma system/update_engine
Change-Id: Ia48091adbdc56c339c69c86c91c5c01aa58c54fb
diff --git a/metrics.cc b/metrics.cc
index 626897a..b8ebcbf 100644
--- a/metrics.cc
+++ b/metrics.cc
@@ -19,11 +19,13 @@
#include <string>
#include <base/logging.h>
+#include <metrics/metrics_library.h>
#include "update_engine/common/clock_interface.h"
#include "update_engine/common/constants.h"
#include "update_engine/common/prefs_interface.h"
#include "update_engine/common/utils.h"
+#include "update_engine/metrics_utils.h"
#include "update_engine/system_state.h"
using std::string;
@@ -149,9 +151,10 @@
}
base::TimeDelta time_since_last;
- if (utils::WallclockDurationHelper(system_state,
- kPrefsMetricsCheckLastReportingTime,
- &time_since_last)) {
+ if (metrics_utils::WallclockDurationHelper(
+ system_state,
+ kPrefsMetricsCheckLastReportingTime,
+ &time_since_last)) {
metric = kMetricCheckTimeSinceLastCheckMinutes;
LOG(INFO) << "Sending " << utils::FormatTimeDelta(time_since_last)
<< " for metric " << metric;
@@ -165,9 +168,9 @@
base::TimeDelta uptime_since_last;
static int64_t uptime_since_last_storage = 0;
- if (utils::MonotonicDurationHelper(system_state,
- &uptime_since_last_storage,
- &uptime_since_last)) {
+ if (metrics_utils::MonotonicDurationHelper(system_state,
+ &uptime_since_last_storage,
+ &uptime_since_last)) {
metric = kMetricCheckTimeSinceLastCheckUptimeMinutes;
LOG(INFO) << "Sending " << utils::FormatTimeDelta(uptime_since_last)
<< " for metric " << metric;
@@ -308,9 +311,10 @@
}
base::TimeDelta time_since_last;
- if (utils::WallclockDurationHelper(system_state,
- kPrefsMetricsAttemptLastReportingTime,
- &time_since_last)) {
+ if (metrics_utils::WallclockDurationHelper(
+ system_state,
+ kPrefsMetricsAttemptLastReportingTime,
+ &time_since_last)) {
metric = kMetricAttemptTimeSinceLastAttemptMinutes;
LOG(INFO) << "Sending " << utils::FormatTimeDelta(time_since_last)
<< " for metric " << metric;
@@ -324,9 +328,9 @@
static int64_t uptime_since_last_storage = 0;
base::TimeDelta uptime_since_last;
- if (utils::MonotonicDurationHelper(system_state,
- &uptime_since_last_storage,
- &uptime_since_last)) {
+ if (metrics_utils::MonotonicDurationHelper(system_state,
+ &uptime_since_last_storage,
+ &uptime_since_last)) {
metric = kMetricAttemptTimeSinceLastAttemptUptimeMinutes;
LOG(INFO) << "Sending " << utils::FormatTimeDelta(uptime_since_last)
<< " for metric " << metric;