From 5ef2e3911957dada3c9e5e8d42d90d0dd56d1a29 Mon Sep 17 00:00:00 2001 From: Luigi Semenzato Date: Tue, 15 Apr 2014 15:15:02 -0700 Subject: [PATCH] metrics_daemon: report cumulative daily use. This had been lost in the previous changes. Also, the meaning of DailyUse changes: it is now cumulative daily use. But we should revise these stats so I think it's OK for now. BUG=chromium:339588 TEST=unit tests Change-Id: I4894fef0ffb237633abcf949c01dd7ea5f5e5d6e Reviewed-on: https://chromium-review.googlesource.com/195005 Reviewed-by: Daniel Erat Tested-by: Luigi Semenzato Commit-Queue: Luigi Semenzato --- metrics/metrics_daemon.cc | 19 +++++++++---------- metrics/metrics_daemon.h | 2 +- metrics/metrics_daemon_test.cc | 8 ++++---- 3 files changed, 14 insertions(+), 15 deletions(-) diff --git a/metrics/metrics_daemon.cc b/metrics/metrics_daemon.cc index b9d8cf0c4..1f20699ac 100644 --- a/metrics/metrics_daemon.cc +++ b/metrics/metrics_daemon.cc @@ -421,6 +421,7 @@ void MetricsDaemon::ReportStats(int64 active_use_seconds, Time now) { daily_cycle_->Set(day); // Daily stats. + ReportDailyUse(active_use_seconds); SendCrashFrequencySample(any_crashes_daily_count_); SendCrashFrequencySample(user_crashes_daily_count_); SendCrashFrequencySample(kernel_crashes_daily_count_); @@ -1125,18 +1126,16 @@ bool MetricsDaemon::ProcessMemuse(const string& meminfo_raw) { return true; } -// static -void MetricsDaemon::ReportDailyUse(void* handle, int count) { - if (count <= 0) +void MetricsDaemon::ReportDailyUse(int use_seconds) { + if (use_seconds <= 0) return; - MetricsDaemon* daemon = static_cast(handle); - int minutes = (count + kSecondsPerMinute / 2) / kSecondsPerMinute; - daemon->SendSample("Logging.DailyUseTime", - minutes, - 1, - kMinutesPerDay, - 50); + int minutes = (use_seconds + kSecondsPerMinute / 2) / kSecondsPerMinute; + SendSample("Logging.DailyUseTime", + minutes, + 1, + kMinutesPerDay * 30 * 2, // cumulative---two months worth + 50); } void MetricsDaemon::SendSample(const string& name, int sample, diff --git a/metrics/metrics_daemon.h b/metrics/metrics_daemon.h index 2805cb758..de9fd740a 100644 --- a/metrics/metrics_daemon.h +++ b/metrics/metrics_daemon.h @@ -231,7 +231,7 @@ class MetricsDaemon { void UnscheduleUseMonitor(); // Report daily use through UMA. - static void ReportDailyUse(void* handle, int count); + void ReportDailyUse(int use_seconds); // Sends a regular (exponential) histogram sample to Chrome for // transport to UMA. See MetricsLibrary::SendToUMA in diff --git a/metrics/metrics_daemon_test.cc b/metrics/metrics_daemon_test.cc index aea0f4bd6..e83ad4d75 100644 --- a/metrics/metrics_daemon_test.cc +++ b/metrics/metrics_daemon_test.cc @@ -230,14 +230,14 @@ TEST_F(MetricsDaemonTest, CheckSystemCrash) { TEST_F(MetricsDaemonTest, ReportDailyUse) { ExpectDailyUseTimeSample(/* sample */ 2); - MetricsDaemon::ReportDailyUse(&daemon_, /* count */ 90); + daemon_.ReportDailyUse(/* count */ 90); ExpectDailyUseTimeSample(/* sample */ 1); - MetricsDaemon::ReportDailyUse(&daemon_, /* count */ 89); + daemon_.ReportDailyUse(/* count */ 89); // There should be no metrics generated for the calls below. - MetricsDaemon::ReportDailyUse(&daemon_, /* count */ 0); - MetricsDaemon::ReportDailyUse(&daemon_, /* count */ -5); + daemon_.ReportDailyUse(/* count */ 0); + daemon_.ReportDailyUse(/* count */ -5); } TEST_F(MetricsDaemonTest, LookupPowerState) {