From 2d03783ccc88fef71268658d774318f8cca362e4 Mon Sep 17 00:00:00 2001 From: Bertrand SIMONNET Date: Wed, 16 Sep 2015 17:11:51 -0700 Subject: [PATCH] metricsd: Fix CumulativeUseTime metrics. This fixes three things: * name of the metrics: the metrics does not represent the daily use. * arithmetic error: we collect the use time in seconds so no need to divide by 1000 to get seconds. * the metrics should not be reset daily. This CL also renames the Send* helper methods to be more explicit about resetting the counters. This was also committed in Chrome OS at: https://chromium-review.googlesource.com/#/c/300059/. BUG:24131693 TEST: unit tests. Change-Id: I712baa1fd639b9b0df60906d94a0904d8c6760aa --- metricsd/metrics_daemon.cc | 35 +++++++++++++++++------------------ metricsd/metrics_daemon.h | 16 ++++++++++------ 2 files changed, 27 insertions(+), 24 deletions(-) diff --git a/metricsd/metrics_daemon.cc b/metricsd/metrics_daemon.cc index de7f2ea82..b0e4b2f6d 100644 --- a/metricsd/metrics_daemon.cc +++ b/metricsd/metrics_daemon.cc @@ -241,7 +241,7 @@ void MetricsDaemon::Init(bool testing, daily_active_use_.reset( new PersistentInteger("Platform.DailyUseTime")); version_cumulative_active_use_.reset( - new PersistentInteger("Platform.CumulativeDailyUseTime")); + new PersistentInteger("Platform.CumulativeUseTime")); version_cumulative_cpu_use_.reset( new PersistentInteger("Platform.CumulativeCpuTime")); @@ -444,7 +444,7 @@ void MetricsDaemon::ProcessUserCrash() { UpdateStats(TimeTicks::Now(), Time::Now()); // Reports the active use time since the last crash and resets it. - SendCrashIntervalSample(user_crash_interval_); + SendAndResetCrashIntervalSample(user_crash_interval_); any_crashes_daily_count_->Add(1); any_crashes_weekly_count_->Add(1); @@ -457,7 +457,7 @@ void MetricsDaemon::ProcessKernelCrash() { UpdateStats(TimeTicks::Now(), Time::Now()); // Reports the active use time since the last crash and resets it. - SendCrashIntervalSample(kernel_crash_interval_); + SendAndResetCrashIntervalSample(kernel_crash_interval_); any_crashes_daily_count_->Add(1); any_crashes_weekly_count_->Add(1); @@ -472,7 +472,7 @@ void MetricsDaemon::ProcessUncleanShutdown() { UpdateStats(TimeTicks::Now(), Time::Now()); // Reports the active use time since the last crash and resets it. - SendCrashIntervalSample(unclean_shutdown_interval_); + SendAndResetCrashIntervalSample(unclean_shutdown_interval_); unclean_shutdowns_daily_count_->Add(1); unclean_shutdowns_weekly_count_->Add(1); @@ -1033,7 +1033,7 @@ void MetricsDaemon::SendKernelCrashesCumulativeCountStats() { int64_t active_use_seconds = version_cumulative_active_use_->Get(); if (active_use_seconds > 0) { SendSample(version_cumulative_active_use_->Name(), - active_use_seconds / 1000, // stat is in seconds + active_use_seconds, 1, // device may be used very little... 8 * 1000 * 1000, // ... or a lot (about 90 days) 100); @@ -1046,7 +1046,7 @@ void MetricsDaemon::SendKernelCrashesCumulativeCountStats() { } } -void MetricsDaemon::SendDailyUseSample( +void MetricsDaemon::SendAndResetDailyUseSample( const scoped_ptr& use) { SendSample(use->Name(), use->GetAndClear(), @@ -1055,7 +1055,7 @@ void MetricsDaemon::SendDailyUseSample( 50); // number of buckets } -void MetricsDaemon::SendCrashIntervalSample( +void MetricsDaemon::SendAndResetCrashIntervalSample( const scoped_ptr& interval) { SendSample(interval->Name(), interval->GetAndClear(), @@ -1064,7 +1064,7 @@ void MetricsDaemon::SendCrashIntervalSample( 50); // number of buckets } -void MetricsDaemon::SendCrashFrequencySample( +void MetricsDaemon::SendAndResetCrashFrequencySample( const scoped_ptr& frequency) { SendSample(frequency->Name(), frequency->GetAndClear(), @@ -1097,21 +1097,20 @@ void MetricsDaemon::UpdateStats(TimeTicks now_ticks, if (daily_cycle_->Get() != day) { daily_cycle_->Set(day); - SendDailyUseSample(daily_active_use_); - SendDailyUseSample(version_cumulative_active_use_); - SendCrashFrequencySample(any_crashes_daily_count_); - SendCrashFrequencySample(user_crashes_daily_count_); - SendCrashFrequencySample(kernel_crashes_daily_count_); - SendCrashFrequencySample(unclean_shutdowns_daily_count_); + SendAndResetDailyUseSample(daily_active_use_); + SendAndResetCrashFrequencySample(any_crashes_daily_count_); + SendAndResetCrashFrequencySample(user_crashes_daily_count_); + SendAndResetCrashFrequencySample(kernel_crashes_daily_count_); + SendAndResetCrashFrequencySample(unclean_shutdowns_daily_count_); SendKernelCrashesCumulativeCountStats(); } if (weekly_cycle_->Get() != week) { weekly_cycle_->Set(week); - SendCrashFrequencySample(any_crashes_weekly_count_); - SendCrashFrequencySample(user_crashes_weekly_count_); - SendCrashFrequencySample(kernel_crashes_weekly_count_); - SendCrashFrequencySample(unclean_shutdowns_weekly_count_); + SendAndResetCrashFrequencySample(any_crashes_weekly_count_); + SendAndResetCrashFrequencySample(user_crashes_weekly_count_); + SendAndResetCrashFrequencySample(kernel_crashes_weekly_count_); + SendAndResetCrashFrequencySample(unclean_shutdowns_weekly_count_); } } diff --git a/metricsd/metrics_daemon.h b/metricsd/metrics_daemon.h index b363c5ea4..fbb871ec1 100644 --- a/metricsd/metrics_daemon.h +++ b/metricsd/metrics_daemon.h @@ -171,15 +171,19 @@ class MetricsDaemon : public chromeos::DBusDaemon { base::TimeDelta GetIncrementalCpuUse(); // Sends a sample representing the number of seconds of active use - // for a 24-hour period. - void SendDailyUseSample(const scoped_ptr& use); + // for a 24-hour period and reset |use|. + void SendAndResetDailyUseSample( + const scoped_ptr& use); // Sends a sample representing a time interval between two crashes of the - // same type. - void SendCrashIntervalSample(const scoped_ptr& interval); + // same type and reset |interval|. + void SendAndResetCrashIntervalSample( + const scoped_ptr& interval); - // Sends a sample representing a frequency of crashes of some type. - void SendCrashFrequencySample(const scoped_ptr& frequency); + // Sends a sample representing a frequency of crashes of some type and reset + // |frequency|. + void SendAndResetCrashFrequencySample( + const scoped_ptr& frequency); // Initializes vm and disk stats reporting. void StatsReporterInit();