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
diff --git a/metricsd/metrics_daemon.cc b/metricsd/metrics_daemon.cc
index de7f2ea..b0e4b2f 100644
--- a/metricsd/metrics_daemon.cc
+++ b/metricsd/metrics_daemon.cc
@@ -241,7 +241,7 @@
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 @@
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 @@
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 @@
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 @@
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::SendDailyUseSample(
+void MetricsDaemon::SendAndResetDailyUseSample(
const scoped_ptr<PersistentInteger>& use) {
SendSample(use->Name(),
use->GetAndClear(),
@@ -1055,7 +1055,7 @@
50); // number of buckets
}
-void MetricsDaemon::SendCrashIntervalSample(
+void MetricsDaemon::SendAndResetCrashIntervalSample(
const scoped_ptr<PersistentInteger>& interval) {
SendSample(interval->Name(),
interval->GetAndClear(),
@@ -1064,7 +1064,7 @@
50); // number of buckets
}
-void MetricsDaemon::SendCrashFrequencySample(
+void MetricsDaemon::SendAndResetCrashFrequencySample(
const scoped_ptr<PersistentInteger>& frequency) {
SendSample(frequency->Name(),
frequency->GetAndClear(),
@@ -1097,21 +1097,20 @@
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 b363c5e..fbb871e 100644
--- a/metricsd/metrics_daemon.h
+++ b/metricsd/metrics_daemon.h
@@ -171,15 +171,19 @@
base::TimeDelta GetIncrementalCpuUse();
// Sends a sample representing the number of seconds of active use
- // for a 24-hour period.
- void SendDailyUseSample(const scoped_ptr<PersistentInteger>& use);
+ // for a 24-hour period and reset |use|.
+ void SendAndResetDailyUseSample(
+ const scoped_ptr<PersistentInteger>& use);
// Sends a sample representing a time interval between two crashes of the
- // same type.
- void SendCrashIntervalSample(const scoped_ptr<PersistentInteger>& interval);
+ // same type and reset |interval|.
+ void SendAndResetCrashIntervalSample(
+ const scoped_ptr<PersistentInteger>& interval);
- // Sends a sample representing a frequency of crashes of some type.
- void SendCrashFrequencySample(const scoped_ptr<PersistentInteger>& frequency);
+ // Sends a sample representing a frequency of crashes of some type and reset
+ // |frequency|.
+ void SendAndResetCrashFrequencySample(
+ const scoped_ptr<PersistentInteger>& frequency);
// Initializes vm and disk stats reporting.
void StatsReporterInit();