blob: f9061d563b59a1bf00ea12c9a0db5c59b45d2c5b [file] [log] [blame]
Darin Petkov8032dd02011-05-09 16:33:19 -07001// Copyright (c) 2011 The Chromium OS Authors. All rights reserved.
Darin Petkov65b01462010-04-14 13:32:20 -07002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Bertrand SIMONNET4b915ae2015-07-28 15:38:14 -07005#include "metrics_daemon.h"
Darin Petkov65b01462010-04-14 13:32:20 -07006
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -08007#include <fcntl.h>
Luigi Semenzato4a6c9422014-06-30 18:12:28 -07008#include <inttypes.h>
Luigi Semenzato8accd332011-05-17 16:37:18 -07009#include <math.h>
Ken Mixter4c5daa42010-08-26 18:35:06 -070010#include <string.h>
Steve Funge86591e2014-12-01 13:38:21 -080011#include <sysexits.h>
Luigi Semenzato8accd332011-05-17 16:37:18 -070012#include <time.h>
Darin Petkov65b01462010-04-14 13:32:20 -070013
Bertrand SIMONNET4b915ae2015-07-28 15:38:14 -070014#include <base/bind.h>
Luigi Semenzato859b3f02014-02-05 15:33:19 -080015#include <base/files/file_path.h>
Ben Chan51bf92a2014-09-05 08:21:06 -070016#include <base/files/file_util.h>
Luigi Semenzato859b3f02014-02-05 15:33:19 -080017#include <base/hash.h>
Darin Petkov65b01462010-04-14 13:32:20 -070018#include <base/logging.h>
Ben Chan2e6543d2014-02-05 23:26:25 -080019#include <base/strings/string_number_conversions.h>
20#include <base/strings/string_split.h>
21#include <base/strings/string_util.h>
22#include <base/strings/stringprintf.h>
Luigi Semenzato859b3f02014-02-05 15:33:19 -080023#include <base/sys_info.h>
Steve Funge86591e2014-12-01 13:38:21 -080024#include <dbus/dbus.h>
25#include <dbus/message.h>
Bertrand SIMONNETbae5dcc2015-08-04 14:12:10 -070026
27#include "constants.h"
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -070028#include "uploader/upload_service.h"
Darin Petkov65b01462010-04-14 13:32:20 -070029
Ben Chan2e6543d2014-02-05 23:26:25 -080030using base::FilePath;
31using base::StringPrintf;
Darin Petkovf27f0362010-06-04 13:14:19 -070032using base::Time;
33using base::TimeDelta;
34using base::TimeTicks;
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080035using chromeos_metrics::PersistentInteger;
Luigi Semenzato8accd332011-05-17 16:37:18 -070036using std::map;
Darin Petkov38d5cb02010-06-24 12:10:26 -070037using std::string;
Luigi Semenzato8accd332011-05-17 16:37:18 -070038using std::vector;
39
Daniel Eratc83975a2014-04-04 08:53:44 -070040namespace {
Darin Petkovf27f0362010-06-04 13:14:19 -070041
Darin Petkov703ec972010-04-27 11:02:18 -070042#define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error")
Darin Petkov40f25732013-04-29 15:07:31 +020043
Daniel Eratc83975a2014-04-04 08:53:44 -070044const char kCrashReporterInterface[] = "org.chromium.CrashReporter";
45const char kCrashReporterUserCrashSignal[] = "UserCrash";
Steve Funge86591e2014-12-01 13:38:21 -080046const char kCrashReporterMatchRule[] =
47 "type='signal',interface='%s',path='/',member='%s'";
Darin Petkov41e06232010-05-03 16:45:37 -070048
Daniel Eratc83975a2014-04-04 08:53:44 -070049const int kSecondsPerMinute = 60;
50const int kMinutesPerHour = 60;
51const int kHoursPerDay = 24;
52const int kMinutesPerDay = kHoursPerDay * kMinutesPerHour;
53const int kSecondsPerDay = kSecondsPerMinute * kMinutesPerDay;
54const int kDaysPerWeek = 7;
55const int kSecondsPerWeek = kSecondsPerDay * kDaysPerWeek;
Darin Petkov41e06232010-05-03 16:45:37 -070056
Daniel Eratc83975a2014-04-04 08:53:44 -070057// Interval between calls to UpdateStats().
Steve Funge86591e2014-12-01 13:38:21 -080058const uint32_t kUpdateStatsIntervalMs = 300000;
Darin Petkov65b01462010-04-14 13:32:20 -070059
Luigi Semenzatoc5a92342014-02-14 15:05:51 -080060const char kKernelCrashDetectedFile[] = "/var/run/kernel-crash-detected";
Daniel Eratc83975a2014-04-04 08:53:44 -070061const char kUncleanShutdownDetectedFile[] =
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080062 "/var/run/unclean-shutdown-detected";
Ken Mixterccd84c02010-08-16 19:57:13 -070063
Daniel Eratc83975a2014-04-04 08:53:44 -070064} // namespace
65
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080066// disk stats metrics
67
68// The {Read,Write}Sectors numbers are in sectors/second.
69// A sector is usually 512 bytes.
70
71const char MetricsDaemon::kMetricReadSectorsLongName[] =
72 "Platform.ReadSectorsLong";
73const char MetricsDaemon::kMetricWriteSectorsLongName[] =
74 "Platform.WriteSectorsLong";
75const char MetricsDaemon::kMetricReadSectorsShortName[] =
76 "Platform.ReadSectorsShort";
77const char MetricsDaemon::kMetricWriteSectorsShortName[] =
78 "Platform.WriteSectorsShort";
79
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070080const int MetricsDaemon::kMetricStatsShortInterval = 1; // seconds
81const int MetricsDaemon::kMetricStatsLongInterval = 30; // seconds
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080082
Luigi Semenzato29c7ef92011-04-12 14:12:35 -070083const int MetricsDaemon::kMetricMeminfoInterval = 30; // seconds
84
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080085// Assume a max rate of 250Mb/s for reads (worse for writes) and 512 byte
86// sectors.
87const int MetricsDaemon::kMetricSectorsIOMax = 500000; // sectors/second
88const int MetricsDaemon::kMetricSectorsBuckets = 50; // buckets
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070089// Page size is 4k, sector size is 0.5k. We're not interested in page fault
90// rates that the disk cannot sustain.
91const int MetricsDaemon::kMetricPageFaultsMax = kMetricSectorsIOMax / 8;
92const int MetricsDaemon::kMetricPageFaultsBuckets = 50;
93
94// Major page faults, i.e. the ones that require data to be read from disk.
95
96const char MetricsDaemon::kMetricPageFaultsLongName[] =
97 "Platform.PageFaultsLong";
98const char MetricsDaemon::kMetricPageFaultsShortName[] =
99 "Platform.PageFaultsShort";
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800100
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700101// Swap in and Swap out
102
103const char MetricsDaemon::kMetricSwapInLongName[] =
104 "Platform.SwapInLong";
105const char MetricsDaemon::kMetricSwapInShortName[] =
106 "Platform.SwapInShort";
107
108const char MetricsDaemon::kMetricSwapOutLongName[] =
109 "Platform.SwapOutLong";
110const char MetricsDaemon::kMetricSwapOutShortName[] =
111 "Platform.SwapOutShort";
112
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700113const char MetricsDaemon::kMetricsProcStatFileName[] = "/proc/stat";
114const int MetricsDaemon::kMetricsProcStatFirstLineItemsCount = 11;
115
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700116// Thermal CPU throttling.
117
118const char MetricsDaemon::kMetricScaledCpuFrequencyName[] =
119 "Platform.CpuFrequencyThermalScaling";
120
Luigi Semenzato96360192014-06-04 10:53:35 -0700121// Zram sysfs entries.
122
123const char MetricsDaemon::kComprDataSizeName[] = "compr_data_size";
124const char MetricsDaemon::kOrigDataSizeName[] = "orig_data_size";
125const char MetricsDaemon::kZeroPagesName[] = "zero_pages";
126
Luigi Semenzato8accd332011-05-17 16:37:18 -0700127// Memory use stats collection intervals. We collect some memory use interval
128// at these intervals after boot, and we stop collecting after the last one,
129// with the assumption that in most cases the memory use won't change much
130// after that.
131static const int kMemuseIntervals[] = {
132 1 * kSecondsPerMinute, // 1 minute mark
133 4 * kSecondsPerMinute, // 5 minute mark
134 25 * kSecondsPerMinute, // 0.5 hour mark
135 120 * kSecondsPerMinute, // 2.5 hour mark
136 600 * kSecondsPerMinute, // 12.5 hour mark
137};
138
Darin Petkovf1e85e42010-06-10 15:59:53 -0700139MetricsDaemon::MetricsDaemon()
Steve Funge86591e2014-12-01 13:38:21 -0800140 : memuse_final_time_(0),
Luigi Semenzato8accd332011-05-17 16:37:18 -0700141 memuse_interval_index_(0),
142 read_sectors_(0),
143 write_sectors_(0),
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700144 vmstats_(),
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700145 stats_state_(kStatsShort),
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700146 stats_initial_time_(0),
147 ticks_per_second_(0),
148 latest_cpu_use_ticks_(0) {}
Darin Petkovf1e85e42010-06-10 15:59:53 -0700149
Ken Mixter4c5daa42010-08-26 18:35:06 -0700150MetricsDaemon::~MetricsDaemon() {
Ken Mixter4c5daa42010-08-26 18:35:06 -0700151}
152
Luigi Semenzato8accd332011-05-17 16:37:18 -0700153double MetricsDaemon::GetActiveTime() {
154 struct timespec ts;
155 int r = clock_gettime(CLOCK_MONOTONIC, &ts);
156 if (r < 0) {
157 PLOG(WARNING) << "clock_gettime(CLOCK_MONOTONIC) failed";
158 return 0;
159 } else {
Luigi Semenzato4a6c9422014-06-30 18:12:28 -0700160 return ts.tv_sec + static_cast<double>(ts.tv_nsec) / (1000 * 1000 * 1000);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700161 }
162}
163
Steve Funge86591e2014-12-01 13:38:21 -0800164int MetricsDaemon::Run() {
Ken Mixterccd84c02010-08-16 19:57:13 -0700165 if (CheckSystemCrash(kKernelCrashDetectedFile)) {
166 ProcessKernelCrash();
167 }
168
169 if (CheckSystemCrash(kUncleanShutdownDetectedFile)) {
170 ProcessUncleanShutdown();
171 }
172
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800173 // On OS version change, clear version stats (which are reported daily).
Ben Chanf05ab402014-08-07 00:54:59 -0700174 int32_t version = GetOsVersionHash();
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800175 if (version_cycle_->Get() != version) {
176 version_cycle_->Set(version);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800177 kernel_crashes_version_count_->Set(0);
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700178 version_cumulative_active_use_->Set(0);
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700179 version_cumulative_cpu_use_->Set(0);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800180 }
181
Steve Funge86591e2014-12-01 13:38:21 -0800182 return chromeos::DBusDaemon::Run();
Darin Petkov65b01462010-04-14 13:32:20 -0700183}
184
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700185void MetricsDaemon::RunUploaderTest() {
Bertrand SIMONNET71a62ef2014-10-07 11:26:25 -0700186 upload_service_.reset(new UploadService(new SystemProfileCache(true,
187 config_root_),
Bertrand SIMONNETe4fa61e2015-02-18 09:38:55 -0800188 metrics_lib_,
Bertrand SIMONNET71a62ef2014-10-07 11:26:25 -0700189 server_));
Bertrand SIMONNETcac74e12014-10-09 10:14:13 -0700190 upload_service_->Init(upload_interval_, metrics_file_);
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700191 upload_service_->UploadEvent();
192}
193
Ben Chanf05ab402014-08-07 00:54:59 -0700194uint32_t MetricsDaemon::GetOsVersionHash() {
195 static uint32_t cached_version_hash = 0;
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800196 static bool version_hash_is_cached = false;
197 if (version_hash_is_cached)
198 return cached_version_hash;
199 version_hash_is_cached = true;
Bertrand SIMONNETbae5dcc2015-08-04 14:12:10 -0700200 std::string version = metrics::kDefaultVersion;
201 // The version might not be set for development devices. In this case, use the
202 // zero version.
203 base::SysInfo::GetLsbReleaseValue("BRILLO_VERSION", &version);
204 cached_version_hash = base::Hash(version);
205 if (testing_) {
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800206 cached_version_hash = 42; // return any plausible value for the hash
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800207 }
208 return cached_version_hash;
209}
210
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700211void MetricsDaemon::Init(bool testing,
212 bool uploader_active,
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700213 bool dbus_enabled,
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700214 MetricsLibraryInterface* metrics_lib,
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700215 const string& vmstats_path,
216 const string& scaling_max_freq_path,
Steve Fung67906c62014-10-06 15:15:30 -0700217 const string& cpuinfo_max_freq_path,
Bertrand SIMONNETcac74e12014-10-09 10:14:13 -0700218 const base::TimeDelta& upload_interval,
Steve Fung67906c62014-10-06 15:15:30 -0700219 const string& server,
Bertrand SIMONNET71a62ef2014-10-07 11:26:25 -0700220 const string& metrics_file,
221 const string& config_root) {
Darin Petkov65b01462010-04-14 13:32:20 -0700222 testing_ = testing;
Steve Funge86591e2014-12-01 13:38:21 -0800223 uploader_active_ = uploader_active;
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700224 dbus_enabled_ = dbus_enabled;
Bertrand SIMONNET71a62ef2014-10-07 11:26:25 -0700225 config_root_ = config_root;
Alex Vakulenko14595032014-08-28 14:59:56 -0700226 DCHECK(metrics_lib != nullptr);
Darin Petkovfc91b422010-05-12 13:05:45 -0700227 metrics_lib_ = metrics_lib;
Darin Petkov38d5cb02010-06-24 12:10:26 -0700228
Bertrand SIMONNETcac74e12014-10-09 10:14:13 -0700229 upload_interval_ = upload_interval;
Steve Fung67906c62014-10-06 15:15:30 -0700230 server_ = server;
231 metrics_file_ = metrics_file;
232
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700233 // Get ticks per second (HZ) on this system.
234 // Sysconf cannot fail, so no sanity checks are needed.
235 ticks_per_second_ = sysconf(_SC_CLK_TCK);
236
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700237 daily_active_use_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700238 new PersistentInteger("Platform.DailyUseTime"));
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700239 version_cumulative_active_use_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700240 new PersistentInteger("Platform.CumulativeDailyUseTime"));
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700241 version_cumulative_cpu_use_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700242 new PersistentInteger("Platform.CumulativeCpuTime"));
Darin Petkov38d5cb02010-06-24 12:10:26 -0700243
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800244 kernel_crash_interval_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700245 new PersistentInteger("Platform.KernelCrashInterval"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800246 unclean_shutdown_interval_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700247 new PersistentInteger("Platform.UncleanShutdownInterval"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800248 user_crash_interval_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700249 new PersistentInteger("Platform.UserCrashInterval"));
Darin Petkov2ccef012010-05-05 16:06:37 -0700250
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800251 any_crashes_daily_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700252 new PersistentInteger("Platform.AnyCrashesDaily"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800253 any_crashes_weekly_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700254 new PersistentInteger("Platform.AnyCrashesWeekly"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800255 user_crashes_daily_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700256 new PersistentInteger("Platform.UserCrashesDaily"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800257 user_crashes_weekly_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700258 new PersistentInteger("Platform.UserCrashesWeekly"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800259 kernel_crashes_daily_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700260 new PersistentInteger("Platform.KernelCrashesDaily"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800261 kernel_crashes_weekly_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700262 new PersistentInteger("Platform.KernelCrashesWeekly"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800263 kernel_crashes_version_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700264 new PersistentInteger("Platform.KernelCrashesSinceUpdate"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800265 unclean_shutdowns_daily_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700266 new PersistentInteger("Platform.UncleanShutdownsDaily"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800267 unclean_shutdowns_weekly_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700268 new PersistentInteger("Platform.UncleanShutdownsWeekly"));
Darin Petkov38d5cb02010-06-24 12:10:26 -0700269
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800270 daily_cycle_.reset(new PersistentInteger("daily.cycle"));
271 weekly_cycle_.reset(new PersistentInteger("weekly.cycle"));
272 version_cycle_.reset(new PersistentInteger("version.cycle"));
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800273
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700274 vmstats_path_ = vmstats_path;
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700275 scaling_max_freq_path_ = scaling_max_freq_path;
276 cpuinfo_max_freq_path_ = cpuinfo_max_freq_path;
Steve Funge86591e2014-12-01 13:38:21 -0800277}
278
279int MetricsDaemon::OnInit() {
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700280 int return_code = dbus_enabled_ ? chromeos::DBusDaemon::OnInit() :
281 chromeos::Daemon::OnInit();
Steve Funge86591e2014-12-01 13:38:21 -0800282 if (return_code != EX_OK)
283 return return_code;
284
Steve Funge86591e2014-12-01 13:38:21 -0800285 if (testing_)
286 return EX_OK;
Darin Petkov65b01462010-04-14 13:32:20 -0700287
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700288 if (dbus_enabled_) {
289 bus_->AssertOnDBusThread();
290 CHECK(bus_->SetUpAsyncOperations());
Darin Petkov65b01462010-04-14 13:32:20 -0700291
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700292 if (bus_->is_connected()) {
293 const std::string match_rule =
294 base::StringPrintf(kCrashReporterMatchRule,
295 kCrashReporterInterface,
296 kCrashReporterUserCrashSignal);
Darin Petkov65b01462010-04-14 13:32:20 -0700297
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700298 bus_->AddFilterFunction(&MetricsDaemon::MessageFilter, this);
Darin Petkov65b01462010-04-14 13:32:20 -0700299
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700300 DBusError error;
301 dbus_error_init(&error);
302 bus_->AddMatch(match_rule, &error);
Darin Petkov65b01462010-04-14 13:32:20 -0700303
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700304 if (dbus_error_is_set(&error)) {
305 LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got "
306 << error.name << ": " << error.message;
307 return EX_SOFTWARE;
308 }
309 } else {
310 LOG(ERROR) << "DBus isn't connected.";
311 return EX_UNAVAILABLE;
Steve Funge86591e2014-12-01 13:38:21 -0800312 }
Darin Petkov703ec972010-04-27 11:02:18 -0700313 }
314
Steve Funge86591e2014-12-01 13:38:21 -0800315 if (uploader_active_) {
Bertrand SIMONNETbae5dcc2015-08-04 14:12:10 -0700316 upload_service_.reset(
317 new UploadService(new SystemProfileCache(), metrics_lib_, server_));
318 upload_service_->Init(upload_interval_, metrics_file_);
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700319 }
Steve Funge86591e2014-12-01 13:38:21 -0800320
321 return EX_OK;
Darin Petkov65b01462010-04-14 13:32:20 -0700322}
323
Steve Funge86591e2014-12-01 13:38:21 -0800324void MetricsDaemon::OnShutdown(int* return_code) {
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700325 if (!testing_ && dbus_enabled_ && bus_->is_connected()) {
Steve Funge86591e2014-12-01 13:38:21 -0800326 const std::string match_rule =
327 base::StringPrintf(kCrashReporterMatchRule,
328 kCrashReporterInterface,
329 kCrashReporterUserCrashSignal);
330
331 bus_->RemoveFilterFunction(&MetricsDaemon::MessageFilter, this);
332
333 DBusError error;
334 dbus_error_init(&error);
335 bus_->RemoveMatch(match_rule, &error);
336
337 if (dbus_error_is_set(&error)) {
338 LOG(ERROR) << "Failed to remove match rule \"" << match_rule << "\". Got "
339 << error.name << ": " << error.message;
340 }
341 }
342 chromeos::DBusDaemon::OnShutdown(return_code);
Darin Petkov65b01462010-04-14 13:32:20 -0700343}
344
Darin Petkov703ec972010-04-27 11:02:18 -0700345// static
346DBusHandlerResult MetricsDaemon::MessageFilter(DBusConnection* connection,
347 DBusMessage* message,
348 void* user_data) {
Darin Petkov703ec972010-04-27 11:02:18 -0700349 int message_type = dbus_message_get_type(message);
350 if (message_type != DBUS_MESSAGE_TYPE_SIGNAL) {
Darin Petkov41e06232010-05-03 16:45:37 -0700351 DLOG(WARNING) << "unexpected message type " << message_type;
Darin Petkov703ec972010-04-27 11:02:18 -0700352 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
353 }
354
355 // Signal messages always have interfaces.
Daniel Eratc83975a2014-04-04 08:53:44 -0700356 const std::string interface(dbus_message_get_interface(message));
357 const std::string member(dbus_message_get_member(message));
358 DLOG(INFO) << "Got " << interface << "." << member << " D-Bus signal";
Darin Petkov703ec972010-04-27 11:02:18 -0700359
360 MetricsDaemon* daemon = static_cast<MetricsDaemon*>(user_data);
361
362 DBusMessageIter iter;
363 dbus_message_iter_init(message, &iter);
Daniel Eratc83975a2014-04-04 08:53:44 -0700364 if (interface == kCrashReporterInterface) {
365 CHECK_EQ(member, kCrashReporterUserCrashSignal);
Darin Petkov1bb904e2010-06-16 15:58:06 -0700366 daemon->ProcessUserCrash();
Darin Petkov703ec972010-04-27 11:02:18 -0700367 } else {
Daniel Eratc83975a2014-04-04 08:53:44 -0700368 // Ignore messages from the bus itself.
Darin Petkov703ec972010-04-27 11:02:18 -0700369 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
370 }
371
372 return DBUS_HANDLER_RESULT_HANDLED;
Darin Petkov65b01462010-04-14 13:32:20 -0700373}
374
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700375// One might argue that parts of this should go into
376// chromium/src/base/sys_info_chromeos.c instead, but put it here for now.
377
378TimeDelta MetricsDaemon::GetIncrementalCpuUse() {
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700379 FilePath proc_stat_path = FilePath(kMetricsProcStatFileName);
380 std::string proc_stat_string;
381 if (!base::ReadFileToString(proc_stat_path, &proc_stat_string)) {
382 LOG(WARNING) << "cannot open " << kMetricsProcStatFileName;
383 return TimeDelta();
384 }
385
386 std::vector<std::string> proc_stat_lines;
387 base::SplitString(proc_stat_string, '\n', &proc_stat_lines);
388 if (proc_stat_lines.empty()) {
389 LOG(WARNING) << "cannot parse " << kMetricsProcStatFileName
390 << ": " << proc_stat_string;
391 return TimeDelta();
392 }
393 std::vector<std::string> proc_stat_totals;
394 base::SplitStringAlongWhitespace(proc_stat_lines[0], &proc_stat_totals);
395
Ben Chanf05ab402014-08-07 00:54:59 -0700396 uint64_t user_ticks, user_nice_ticks, system_ticks;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700397 if (proc_stat_totals.size() != kMetricsProcStatFirstLineItemsCount ||
398 proc_stat_totals[0] != "cpu" ||
399 !base::StringToUint64(proc_stat_totals[1], &user_ticks) ||
400 !base::StringToUint64(proc_stat_totals[2], &user_nice_ticks) ||
401 !base::StringToUint64(proc_stat_totals[3], &system_ticks)) {
402 LOG(WARNING) << "cannot parse first line: " << proc_stat_lines[0];
403 return TimeDelta(base::TimeDelta::FromSeconds(0));
404 }
405
Ben Chanf05ab402014-08-07 00:54:59 -0700406 uint64_t total_cpu_use_ticks = user_ticks + user_nice_ticks + system_ticks;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700407
408 // Sanity check.
409 if (total_cpu_use_ticks < latest_cpu_use_ticks_) {
410 LOG(WARNING) << "CPU time decreasing from " << latest_cpu_use_ticks_
411 << " to " << total_cpu_use_ticks;
412 return TimeDelta();
413 }
414
Ben Chanf05ab402014-08-07 00:54:59 -0700415 uint64_t diff = total_cpu_use_ticks - latest_cpu_use_ticks_;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700416 latest_cpu_use_ticks_ = total_cpu_use_ticks;
417 // Use microseconds to avoid significant truncations.
418 return base::TimeDelta::FromMicroseconds(
419 diff * 1000 * 1000 / ticks_per_second_);
420}
421
Darin Petkov1bb904e2010-06-16 15:58:06 -0700422void MetricsDaemon::ProcessUserCrash() {
Daniel Eratc83975a2014-04-04 08:53:44 -0700423 // Counts the active time up to now.
424 UpdateStats(TimeTicks::Now(), Time::Now());
Darin Petkov1bb904e2010-06-16 15:58:06 -0700425
426 // Reports the active use time since the last crash and resets it.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800427 SendCrashIntervalSample(user_crash_interval_);
Ken Mixterccd84c02010-08-16 19:57:13 -0700428
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800429 any_crashes_daily_count_->Add(1);
430 any_crashes_weekly_count_->Add(1);
431 user_crashes_daily_count_->Add(1);
432 user_crashes_weekly_count_->Add(1);
Darin Petkov1bb904e2010-06-16 15:58:06 -0700433}
434
Darin Petkov38d5cb02010-06-24 12:10:26 -0700435void MetricsDaemon::ProcessKernelCrash() {
Daniel Eratc83975a2014-04-04 08:53:44 -0700436 // Counts the active time up to now.
437 UpdateStats(TimeTicks::Now(), Time::Now());
Darin Petkov38d5cb02010-06-24 12:10:26 -0700438
439 // Reports the active use time since the last crash and resets it.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800440 SendCrashIntervalSample(kernel_crash_interval_);
Ken Mixterccd84c02010-08-16 19:57:13 -0700441
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800442 any_crashes_daily_count_->Add(1);
443 any_crashes_weekly_count_->Add(1);
444 kernel_crashes_daily_count_->Add(1);
445 kernel_crashes_weekly_count_->Add(1);
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800446
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800447 kernel_crashes_version_count_->Add(1);
Darin Petkov38d5cb02010-06-24 12:10:26 -0700448}
449
Ken Mixterccd84c02010-08-16 19:57:13 -0700450void MetricsDaemon::ProcessUncleanShutdown() {
Daniel Eratc83975a2014-04-04 08:53:44 -0700451 // Counts the active time up to now.
452 UpdateStats(TimeTicks::Now(), Time::Now());
Ken Mixterccd84c02010-08-16 19:57:13 -0700453
454 // Reports the active use time since the last crash and resets it.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800455 SendCrashIntervalSample(unclean_shutdown_interval_);
Ken Mixterccd84c02010-08-16 19:57:13 -0700456
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800457 unclean_shutdowns_daily_count_->Add(1);
458 unclean_shutdowns_weekly_count_->Add(1);
459 any_crashes_daily_count_->Add(1);
460 any_crashes_weekly_count_->Add(1);
Ken Mixterccd84c02010-08-16 19:57:13 -0700461}
462
Luigi Semenzato8accd332011-05-17 16:37:18 -0700463bool MetricsDaemon::CheckSystemCrash(const string& crash_file) {
Darin Petkov38d5cb02010-06-24 12:10:26 -0700464 FilePath crash_detected(crash_file);
Ben Chan2e6543d2014-02-05 23:26:25 -0800465 if (!base::PathExists(crash_detected))
Ken Mixterccd84c02010-08-16 19:57:13 -0700466 return false;
Darin Petkov38d5cb02010-06-24 12:10:26 -0700467
468 // Deletes the crash-detected file so that the daemon doesn't report
469 // another kernel crash in case it's restarted.
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800470 base::DeleteFile(crash_detected, false); // not recursive
Ken Mixterccd84c02010-08-16 19:57:13 -0700471 return true;
Darin Petkov38d5cb02010-06-24 12:10:26 -0700472}
473
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700474void MetricsDaemon::StatsReporterInit() {
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800475 DiskStatsReadStats(&read_sectors_, &write_sectors_);
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700476 VmStatsReadStats(&vmstats_);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800477 // The first time around just run the long stat, so we don't delay boot.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700478 stats_state_ = kStatsLong;
479 stats_initial_time_ = GetActiveTime();
480 if (stats_initial_time_ < 0) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700481 LOG(WARNING) << "not collecting disk stats";
482 } else {
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700483 ScheduleStatsCallback(kMetricStatsLongInterval);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700484 }
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800485}
486
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700487void MetricsDaemon::ScheduleStatsCallback(int wait) {
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800488 if (testing_) {
489 return;
490 }
Steve Funge86591e2014-12-01 13:38:21 -0800491 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
492 base::Bind(&MetricsDaemon::StatsCallback, base::Unretained(this)),
493 base::TimeDelta::FromSeconds(wait));
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800494}
495
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700496bool MetricsDaemon::VmStatsParseStats(const char* stats,
497 struct VmstatRecord* record) {
498 // a mapping of string name to field in VmstatRecord and whether we found it
499 struct mapping {
500 const string name;
501 uint64_t* value_p;
502 bool found;
503 } map[] =
504 { { .name = "pgmajfault",
505 .value_p = &record->page_faults_,
506 .found = false },
507 { .name = "pswpin",
508 .value_p = &record->swap_in_,
509 .found = false },
510 { .name = "pswpout",
511 .value_p = &record->swap_out_,
512 .found = false }, };
513
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700514 // Each line in the file has the form
515 // <ID> <VALUE>
516 // for instance:
517 // nr_free_pages 213427
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700518 vector<string> lines;
519 Tokenize(stats, "\n", &lines);
520 for (vector<string>::iterator it = lines.begin();
521 it != lines.end(); ++it) {
522 vector<string> tokens;
523 base::SplitString(*it, ' ', &tokens);
524 if (tokens.size() == 2) {
525 for (unsigned int i = 0; i < sizeof(map)/sizeof(struct mapping); i++) {
526 if (!tokens[0].compare(map[i].name)) {
527 if (!base::StringToUint64(tokens[1], map[i].value_p))
528 return false;
529 map[i].found = true;
530 }
531 }
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700532 } else {
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700533 LOG(WARNING) << "unexpected vmstat format";
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700534 }
535 }
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700536 // make sure we got all the stats
537 for (unsigned i = 0; i < sizeof(map)/sizeof(struct mapping); i++) {
538 if (map[i].found == false) {
539 LOG(WARNING) << "vmstat missing " << map[i].name;
540 return false;
541 }
542 }
543 return true;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700544}
545
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700546bool MetricsDaemon::VmStatsReadStats(struct VmstatRecord* stats) {
547 string value_string;
548 FilePath* path = new FilePath(vmstats_path_);
Ben Chan2e6543d2014-02-05 23:26:25 -0800549 if (!base::ReadFileToString(*path, &value_string)) {
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700550 delete path;
551 LOG(WARNING) << "cannot read " << vmstats_path_;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700552 return false;
553 }
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700554 delete path;
555 return VmStatsParseStats(value_string.c_str(), stats);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800556}
557
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700558bool MetricsDaemon::ReadFreqToInt(const string& sysfs_file_name, int* value) {
Luigi Semenzatod92d18c2013-06-04 13:24:21 -0700559 const FilePath sysfs_path(sysfs_file_name);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700560 string value_string;
Ben Chan2e6543d2014-02-05 23:26:25 -0800561 if (!base::ReadFileToString(sysfs_path, &value_string)) {
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700562 LOG(WARNING) << "cannot read " << sysfs_path.value().c_str();
563 return false;
564 }
Ben Chan2e6543d2014-02-05 23:26:25 -0800565 if (!base::RemoveChars(value_string, "\n", &value_string)) {
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700566 LOG(WARNING) << "no newline in " << value_string;
567 // Continue even though the lack of newline is suspicious.
568 }
569 if (!base::StringToInt(value_string, value)) {
570 LOG(WARNING) << "cannot convert " << value_string << " to int";
571 return false;
572 }
573 return true;
574}
575
576void MetricsDaemon::SendCpuThrottleMetrics() {
577 // |max_freq| is 0 only the first time through.
578 static int max_freq = 0;
579 if (max_freq == -1)
580 // Give up, as sysfs did not report max_freq correctly.
581 return;
582 if (max_freq == 0 || testing_) {
583 // One-time initialization of max_freq. (Every time when testing.)
584 if (!ReadFreqToInt(cpuinfo_max_freq_path_, &max_freq)) {
585 max_freq = -1;
586 return;
587 }
588 if (max_freq == 0) {
589 LOG(WARNING) << "sysfs reports 0 max CPU frequency\n";
590 max_freq = -1;
591 return;
592 }
593 if (max_freq % 10000 == 1000) {
594 // Special case: system has turbo mode, and max non-turbo frequency is
595 // max_freq - 1000. This relies on "normal" (non-turbo) frequencies
596 // being multiples of (at least) 10 MHz. Although there is no guarantee
597 // of this, it seems a fairly reasonable assumption. Otherwise we should
598 // read scaling_available_frequencies, sort the frequencies, compare the
599 // two highest ones, and check if they differ by 1000 (kHz) (and that's a
600 // hack too, no telling when it will change).
601 max_freq -= 1000;
602 }
603 }
604 int scaled_freq = 0;
605 if (!ReadFreqToInt(scaling_max_freq_path_, &scaled_freq))
606 return;
607 // Frequencies are in kHz. If scaled_freq > max_freq, turbo is on, but
608 // scaled_freq is not the actual turbo frequency. We indicate this situation
609 // with a 101% value.
610 int percent = scaled_freq > max_freq ? 101 : scaled_freq / (max_freq / 100);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800611 SendLinearSample(kMetricScaledCpuFrequencyName, percent, 101, 102);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700612}
613
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700614// Collects disk and vm stats alternating over a short and a long interval.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700615
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700616void MetricsDaemon::StatsCallback() {
Ben Chanf05ab402014-08-07 00:54:59 -0700617 uint64_t read_sectors_now, write_sectors_now;
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700618 struct VmstatRecord vmstats_now;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700619 double time_now = GetActiveTime();
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700620 double delta_time = time_now - stats_initial_time_;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700621 if (testing_) {
622 // Fake the time when testing.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700623 delta_time = stats_state_ == kStatsShort ?
624 kMetricStatsShortInterval : kMetricStatsLongInterval;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700625 }
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700626 bool diskstats_success = DiskStatsReadStats(&read_sectors_now,
627 &write_sectors_now);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700628 int delta_read = read_sectors_now - read_sectors_;
629 int delta_write = write_sectors_now - write_sectors_;
630 int read_sectors_per_second = delta_read / delta_time;
631 int write_sectors_per_second = delta_write / delta_time;
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700632 bool vmstats_success = VmStatsReadStats(&vmstats_now);
633 uint64_t delta_faults = vmstats_now.page_faults_ - vmstats_.page_faults_;
634 uint64_t delta_swap_in = vmstats_now.swap_in_ - vmstats_.swap_in_;
635 uint64_t delta_swap_out = vmstats_now.swap_out_ - vmstats_.swap_out_;
636 uint64_t page_faults_per_second = delta_faults / delta_time;
637 uint64_t swap_in_per_second = delta_swap_in / delta_time;
638 uint64_t swap_out_per_second = delta_swap_out / delta_time;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800639
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700640 switch (stats_state_) {
641 case kStatsShort:
642 if (diskstats_success) {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800643 SendSample(kMetricReadSectorsShortName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700644 read_sectors_per_second,
645 1,
646 kMetricSectorsIOMax,
647 kMetricSectorsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800648 SendSample(kMetricWriteSectorsShortName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700649 write_sectors_per_second,
650 1,
651 kMetricSectorsIOMax,
652 kMetricSectorsBuckets);
653 }
654 if (vmstats_success) {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800655 SendSample(kMetricPageFaultsShortName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700656 page_faults_per_second,
657 1,
658 kMetricPageFaultsMax,
659 kMetricPageFaultsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800660 SendSample(kMetricSwapInShortName,
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700661 swap_in_per_second,
662 1,
663 kMetricPageFaultsMax,
664 kMetricPageFaultsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800665 SendSample(kMetricSwapOutShortName,
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700666 swap_out_per_second,
667 1,
668 kMetricPageFaultsMax,
669 kMetricPageFaultsBuckets);
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700670 }
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800671 // Schedule long callback.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700672 stats_state_ = kStatsLong;
673 ScheduleStatsCallback(kMetricStatsLongInterval -
674 kMetricStatsShortInterval);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800675 break;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700676 case kStatsLong:
677 if (diskstats_success) {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800678 SendSample(kMetricReadSectorsLongName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700679 read_sectors_per_second,
680 1,
681 kMetricSectorsIOMax,
682 kMetricSectorsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800683 SendSample(kMetricWriteSectorsLongName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700684 write_sectors_per_second,
685 1,
686 kMetricSectorsIOMax,
687 kMetricSectorsBuckets);
688 // Reset sector counters.
689 read_sectors_ = read_sectors_now;
690 write_sectors_ = write_sectors_now;
691 }
692 if (vmstats_success) {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800693 SendSample(kMetricPageFaultsLongName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700694 page_faults_per_second,
695 1,
696 kMetricPageFaultsMax,
697 kMetricPageFaultsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800698 SendSample(kMetricSwapInLongName,
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700699 swap_in_per_second,
700 1,
701 kMetricPageFaultsMax,
702 kMetricPageFaultsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800703 SendSample(kMetricSwapOutLongName,
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700704 swap_out_per_second,
705 1,
706 kMetricPageFaultsMax,
707 kMetricPageFaultsBuckets);
708
709 vmstats_ = vmstats_now;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700710 }
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700711 SendCpuThrottleMetrics();
Luigi Semenzato8accd332011-05-17 16:37:18 -0700712 // Set start time for new cycle.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700713 stats_initial_time_ = time_now;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800714 // Schedule short callback.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700715 stats_state_ = kStatsShort;
716 ScheduleStatsCallback(kMetricStatsShortInterval);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800717 break;
718 default:
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700719 LOG(FATAL) << "Invalid stats state";
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800720 }
721}
722
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700723void MetricsDaemon::ScheduleMeminfoCallback(int wait) {
724 if (testing_) {
725 return;
726 }
Steve Funge86591e2014-12-01 13:38:21 -0800727 base::TimeDelta waitDelta = base::TimeDelta::FromSeconds(wait);
728 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
729 base::Bind(&MetricsDaemon::MeminfoCallback, base::Unretained(this),
Steve Fung8ab89c52015-01-05 13:48:30 -0800730 waitDelta),
Steve Funge86591e2014-12-01 13:38:21 -0800731 waitDelta);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700732}
733
Steve Funge86591e2014-12-01 13:38:21 -0800734void MetricsDaemon::MeminfoCallback(base::TimeDelta wait) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700735 string meminfo_raw;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700736 const FilePath meminfo_path("/proc/meminfo");
Ben Chan2e6543d2014-02-05 23:26:25 -0800737 if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700738 LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
Steve Funge86591e2014-12-01 13:38:21 -0800739 return;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700740 }
Luigi Semenzato96360192014-06-04 10:53:35 -0700741 // Make both calls even if the first one fails.
742 bool success = ProcessMeminfo(meminfo_raw);
Steve Funge86591e2014-12-01 13:38:21 -0800743 bool reschedule =
744 ReportZram(base::FilePath(FILE_PATH_LITERAL("/sys/block/zram0"))) &&
Luigi Semenzato96360192014-06-04 10:53:35 -0700745 success;
Steve Funge86591e2014-12-01 13:38:21 -0800746 if (reschedule) {
747 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
748 base::Bind(&MetricsDaemon::MeminfoCallback, base::Unretained(this),
Steve Fung8ab89c52015-01-05 13:48:30 -0800749 wait),
Steve Funge86591e2014-12-01 13:38:21 -0800750 wait);
751 }
Luigi Semenzato96360192014-06-04 10:53:35 -0700752}
753
754// static
755bool MetricsDaemon::ReadFileToUint64(const base::FilePath& path,
Ben Chanf05ab402014-08-07 00:54:59 -0700756 uint64_t* value) {
Luigi Semenzato96360192014-06-04 10:53:35 -0700757 std::string content;
758 if (!base::ReadFileToString(path, &content)) {
759 PLOG(WARNING) << "cannot read " << path.MaybeAsASCII();
760 return false;
761 }
Luigi Semenzato4a6c9422014-06-30 18:12:28 -0700762 // Remove final newline.
763 base::TrimWhitespaceASCII(content, base::TRIM_TRAILING, &content);
Luigi Semenzato96360192014-06-04 10:53:35 -0700764 if (!base::StringToUint64(content, value)) {
765 LOG(WARNING) << "invalid integer: " << content;
766 return false;
767 }
768 return true;
769}
770
771bool MetricsDaemon::ReportZram(const base::FilePath& zram_dir) {
772 // Data sizes are in bytes. |zero_pages| is in number of pages.
Ben Chanf05ab402014-08-07 00:54:59 -0700773 uint64_t compr_data_size, orig_data_size, zero_pages;
Luigi Semenzato96360192014-06-04 10:53:35 -0700774 const size_t page_size = 4096;
775
776 if (!ReadFileToUint64(zram_dir.Append(kComprDataSizeName),
777 &compr_data_size) ||
778 !ReadFileToUint64(zram_dir.Append(kOrigDataSizeName), &orig_data_size) ||
779 !ReadFileToUint64(zram_dir.Append(kZeroPagesName), &zero_pages)) {
780 return false;
781 }
782
783 // |orig_data_size| does not include zero-filled pages.
784 orig_data_size += zero_pages * page_size;
785
786 const int compr_data_size_mb = compr_data_size >> 20;
787 const int savings_mb = (orig_data_size - compr_data_size) >> 20;
788 const int zero_ratio_percent = zero_pages * page_size * 100 / orig_data_size;
789
790 // Report compressed size in megabytes. 100 MB or less has little impact.
791 SendSample("Platform.ZramCompressedSize", compr_data_size_mb, 100, 4000, 50);
792 SendSample("Platform.ZramSavings", savings_mb, 100, 4000, 50);
793 // The compression ratio is multiplied by 100 for better resolution. The
794 // ratios of interest are between 1 and 6 (100% and 600% as reported). We
795 // don't want samples when very little memory is being compressed.
796 if (compr_data_size_mb >= 1) {
797 SendSample("Platform.ZramCompressionRatioPercent",
798 orig_data_size * 100 / compr_data_size, 100, 600, 50);
799 }
800 // The values of interest for zero_pages are between 1MB and 1GB. The units
801 // are number of pages.
802 SendSample("Platform.ZramZeroPages", zero_pages, 256, 256 * 1024, 50);
803 SendSample("Platform.ZramZeroRatioPercent", zero_ratio_percent, 1, 50, 50);
804
805 return true;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700806}
807
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700808bool MetricsDaemon::ProcessMeminfo(const string& meminfo_raw) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700809 static const MeminfoRecord fields_array[] = {
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700810 { "MemTotal", "MemTotal" }, // SPECIAL CASE: total system memory
811 { "MemFree", "MemFree" },
812 { "Buffers", "Buffers" },
813 { "Cached", "Cached" },
814 // { "SwapCached", "SwapCached" },
815 { "Active", "Active" },
816 { "Inactive", "Inactive" },
817 { "ActiveAnon", "Active(anon)" },
818 { "InactiveAnon", "Inactive(anon)" },
819 { "ActiveFile" , "Active(file)" },
820 { "InactiveFile", "Inactive(file)" },
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800821 { "Unevictable", "Unevictable", kMeminfoOp_HistLog },
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700822 // { "Mlocked", "Mlocked" },
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800823 { "SwapTotal", "SwapTotal", kMeminfoOp_SwapTotal },
824 { "SwapFree", "SwapFree", kMeminfoOp_SwapFree },
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700825 // { "Dirty", "Dirty" },
826 // { "Writeback", "Writeback" },
827 { "AnonPages", "AnonPages" },
828 { "Mapped", "Mapped" },
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800829 { "Shmem", "Shmem", kMeminfoOp_HistLog },
830 { "Slab", "Slab", kMeminfoOp_HistLog },
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700831 // { "SReclaimable", "SReclaimable" },
832 // { "SUnreclaim", "SUnreclaim" },
833 };
Luigi Semenzato8accd332011-05-17 16:37:18 -0700834 vector<MeminfoRecord> fields(fields_array,
835 fields_array + arraysize(fields_array));
836 if (!FillMeminfo(meminfo_raw, &fields)) {
837 return false;
838 }
839 int total_memory = fields[0].value;
840 if (total_memory == 0) {
841 // this "cannot happen"
842 LOG(WARNING) << "borked meminfo parser";
843 return false;
844 }
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800845 int swap_total = 0;
846 int swap_free = 0;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700847 // Send all fields retrieved, except total memory.
848 for (unsigned int i = 1; i < fields.size(); i++) {
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800849 string metrics_name = base::StringPrintf("Platform.Meminfo%s",
850 fields[i].name);
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800851 int percent;
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800852 switch (fields[i].op) {
853 case kMeminfoOp_HistPercent:
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800854 // report value as percent of total memory
855 percent = fields[i].value * 100 / total_memory;
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800856 SendLinearSample(metrics_name, percent, 100, 101);
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800857 break;
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800858 case kMeminfoOp_HistLog:
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800859 // report value in kbytes, log scale, 4Gb max
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800860 SendSample(metrics_name, fields[i].value, 1, 4 * 1000 * 1000, 100);
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800861 break;
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800862 case kMeminfoOp_SwapTotal:
863 swap_total = fields[i].value;
864 case kMeminfoOp_SwapFree:
865 swap_free = fields[i].value;
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800866 break;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700867 }
868 }
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800869 if (swap_total > 0) {
870 int swap_used = swap_total - swap_free;
871 int swap_used_percent = swap_used * 100 / swap_total;
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800872 SendSample("Platform.MeminfoSwapUsed", swap_used, 1, 8 * 1000 * 1000, 100);
873 SendLinearSample("Platform.MeminfoSwapUsedPercent", swap_used_percent,
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800874 100, 101);
875 }
Luigi Semenzato8accd332011-05-17 16:37:18 -0700876 return true;
877}
878
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700879bool MetricsDaemon::FillMeminfo(const string& meminfo_raw,
880 vector<MeminfoRecord>* fields) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700881 vector<string> lines;
882 unsigned int nlines = Tokenize(meminfo_raw, "\n", &lines);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700883
884 // Scan meminfo output and collect field values. Each field name has to
885 // match a meminfo entry (case insensitive) after removing non-alpha
886 // characters from the entry.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700887 unsigned int ifield = 0;
888 for (unsigned int iline = 0;
889 iline < nlines && ifield < fields->size();
890 iline++) {
891 vector<string> tokens;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700892 Tokenize(lines[iline], ": ", &tokens);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700893 if (strcmp((*fields)[ifield].match, tokens[0].c_str()) == 0) {
894 // Name matches. Parse value and save.
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700895 char* rest;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700896 (*fields)[ifield].value =
897 static_cast<int>(strtol(tokens[1].c_str(), &rest, 10));
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700898 if (*rest != '\0') {
899 LOG(WARNING) << "missing meminfo value";
900 return false;
901 }
Luigi Semenzato8accd332011-05-17 16:37:18 -0700902 ifield++;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700903 }
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700904 }
Luigi Semenzato8accd332011-05-17 16:37:18 -0700905 if (ifield < fields->size()) {
906 // End of input reached while scanning.
907 LOG(WARNING) << "cannot find field " << (*fields)[ifield].match
908 << " and following";
909 return false;
910 }
911 return true;
912}
913
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800914void MetricsDaemon::ScheduleMemuseCallback(double interval) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700915 if (testing_) {
916 return;
917 }
Steve Funge86591e2014-12-01 13:38:21 -0800918 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
919 base::Bind(&MetricsDaemon::MemuseCallback, base::Unretained(this)),
920 base::TimeDelta::FromSeconds(interval));
Luigi Semenzato8accd332011-05-17 16:37:18 -0700921}
922
923void MetricsDaemon::MemuseCallback() {
924 // Since we only care about active time (i.e. uptime minus sleep time) but
925 // the callbacks are driven by real time (uptime), we check if we should
926 // reschedule this callback due to intervening sleep periods.
927 double now = GetActiveTime();
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800928 // Avoid intervals of less than one second.
929 double remaining_time = ceil(memuse_final_time_ - now);
930 if (remaining_time > 0) {
931 ScheduleMemuseCallback(remaining_time);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700932 } else {
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800933 // Report stats and advance the measurement interval unless there are
934 // errors or we've completed the last interval.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700935 if (MemuseCallbackWork() &&
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800936 memuse_interval_index_ < arraysize(kMemuseIntervals)) {
937 double interval = kMemuseIntervals[memuse_interval_index_++];
938 memuse_final_time_ = now + interval;
939 ScheduleMemuseCallback(interval);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700940 }
941 }
942}
943
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700944bool MetricsDaemon::MemuseCallbackWork() {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700945 string meminfo_raw;
946 const FilePath meminfo_path("/proc/meminfo");
Ben Chan2e6543d2014-02-05 23:26:25 -0800947 if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700948 LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
949 return false;
950 }
951 return ProcessMemuse(meminfo_raw);
952}
953
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700954bool MetricsDaemon::ProcessMemuse(const string& meminfo_raw) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700955 static const MeminfoRecord fields_array[] = {
956 { "MemTotal", "MemTotal" }, // SPECIAL CASE: total system memory
957 { "ActiveAnon", "Active(anon)" },
958 { "InactiveAnon", "Inactive(anon)" },
959 };
960 vector<MeminfoRecord> fields(fields_array,
961 fields_array + arraysize(fields_array));
962 if (!FillMeminfo(meminfo_raw, &fields)) {
963 return false;
964 }
965 int total = fields[0].value;
966 int active_anon = fields[1].value;
967 int inactive_anon = fields[2].value;
968 if (total == 0) {
969 // this "cannot happen"
970 LOG(WARNING) << "borked meminfo parser";
971 return false;
972 }
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800973 string metrics_name = base::StringPrintf("Platform.MemuseAnon%d",
974 memuse_interval_index_);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800975 SendLinearSample(metrics_name, (active_anon + inactive_anon) * 100 / total,
Luigi Semenzato8accd332011-05-17 16:37:18 -0700976 100, 101);
977 return true;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700978}
979
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800980void MetricsDaemon::SendSample(const string& name, int sample,
Darin Petkov11b8eb32010-05-18 11:00:59 -0700981 int min, int max, int nbuckets) {
Darin Petkovfc91b422010-05-12 13:05:45 -0700982 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets);
Darin Petkov65b01462010-04-14 13:32:20 -0700983}
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700984
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700985void MetricsDaemon::SendKernelCrashesCumulativeCountStats() {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800986 // Report the number of crashes for this OS version, but don't clear the
987 // counter. It is cleared elsewhere on version change.
Ben Chanf05ab402014-08-07 00:54:59 -0700988 int64_t crashes_count = kernel_crashes_version_count_->Get();
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800989 SendSample(kernel_crashes_version_count_->Name(),
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700990 crashes_count,
991 1, // value of first bucket
992 500, // value of last bucket
993 100); // number of buckets
994
995
Ben Chanf05ab402014-08-07 00:54:59 -0700996 int64_t cpu_use_ms = version_cumulative_cpu_use_->Get();
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700997 SendSample(version_cumulative_cpu_use_->Name(),
998 cpu_use_ms / 1000, // stat is in seconds
999 1, // device may be used very little...
1000 8 * 1000 * 1000, // ... or a lot (a little over 90 days)
1001 100);
1002
1003 // On the first run after an autoupdate, cpu_use_ms and active_use_seconds
1004 // can be zero. Avoid division by zero.
1005 if (cpu_use_ms > 0) {
1006 // Send the crash frequency since update in number of crashes per CPU year.
1007 SendSample("Logging.KernelCrashesPerCpuYear",
1008 crashes_count * kSecondsPerDay * 365 * 1000 / cpu_use_ms,
1009 1,
1010 1000 * 1000, // about one crash every 30s of CPU time
1011 100);
1012 }
1013
Ben Chanf05ab402014-08-07 00:54:59 -07001014 int64_t active_use_seconds = version_cumulative_active_use_->Get();
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -07001015 if (active_use_seconds > 0) {
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001016 SendSample(version_cumulative_active_use_->Name(),
1017 active_use_seconds / 1000, // stat is in seconds
1018 1, // device may be used very little...
1019 8 * 1000 * 1000, // ... or a lot (about 90 days)
1020 100);
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -07001021 // Same as above, but per year of active time.
1022 SendSample("Logging.KernelCrashesPerActiveYear",
1023 crashes_count * kSecondsPerDay * 365 / active_use_seconds,
1024 1,
1025 1000 * 1000, // about one crash every 30s of active time
1026 100);
1027 }
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -08001028}
1029
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001030void MetricsDaemon::SendDailyUseSample(
1031 const scoped_ptr<PersistentInteger>& use) {
1032 SendSample(use->Name(),
1033 use->GetAndClear(),
1034 1, // value of first bucket
1035 kSecondsPerDay, // value of last bucket
1036 50); // number of buckets
1037}
1038
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -08001039void MetricsDaemon::SendCrashIntervalSample(
1040 const scoped_ptr<PersistentInteger>& interval) {
1041 SendSample(interval->Name(),
1042 interval->GetAndClear(),
1043 1, // value of first bucket
1044 4 * kSecondsPerWeek, // value of last bucket
1045 50); // number of buckets
1046}
1047
1048void MetricsDaemon::SendCrashFrequencySample(
1049 const scoped_ptr<PersistentInteger>& frequency) {
1050 SendSample(frequency->Name(),
1051 frequency->GetAndClear(),
1052 1, // value of first bucket
1053 100, // value of last bucket
1054 50); // number of buckets
1055}
1056
1057void MetricsDaemon::SendLinearSample(const string& name, int sample,
Luigi Semenzato29c7ef92011-04-12 14:12:35 -07001058 int max, int nbuckets) {
Luigi Semenzato29c7ef92011-04-12 14:12:35 -07001059 // TODO(semenzato): add a proper linear histogram to the Chrome external
1060 // metrics API.
1061 LOG_IF(FATAL, nbuckets != max + 1) << "unsupported histogram scale";
1062 metrics_lib_->SendEnumToUMA(name, sample, max);
1063}
Daniel Eratc83975a2014-04-04 08:53:44 -07001064
1065void MetricsDaemon::UpdateStats(TimeTicks now_ticks,
1066 Time now_wall_time) {
1067 const int elapsed_seconds = (now_ticks - last_update_stats_time_).InSeconds();
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001068 daily_active_use_->Add(elapsed_seconds);
1069 version_cumulative_active_use_->Add(elapsed_seconds);
Daniel Eratc83975a2014-04-04 08:53:44 -07001070 user_crash_interval_->Add(elapsed_seconds);
1071 kernel_crash_interval_->Add(elapsed_seconds);
1072 version_cumulative_cpu_use_->Add(GetIncrementalCpuUse().InMilliseconds());
1073 last_update_stats_time_ = now_ticks;
1074
1075 const TimeDelta since_epoch = now_wall_time - Time::UnixEpoch();
1076 const int day = since_epoch.InDays();
1077 const int week = day / 7;
1078
1079 if (daily_cycle_->Get() != day) {
1080 daily_cycle_->Set(day);
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001081 SendDailyUseSample(daily_active_use_);
1082 SendDailyUseSample(version_cumulative_active_use_);
Daniel Eratc83975a2014-04-04 08:53:44 -07001083 SendCrashFrequencySample(any_crashes_daily_count_);
1084 SendCrashFrequencySample(user_crashes_daily_count_);
1085 SendCrashFrequencySample(kernel_crashes_daily_count_);
1086 SendCrashFrequencySample(unclean_shutdowns_daily_count_);
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001087 SendKernelCrashesCumulativeCountStats();
Daniel Eratc83975a2014-04-04 08:53:44 -07001088 }
1089
1090 if (weekly_cycle_->Get() != week) {
1091 weekly_cycle_->Set(week);
1092 SendCrashFrequencySample(any_crashes_weekly_count_);
1093 SendCrashFrequencySample(user_crashes_weekly_count_);
1094 SendCrashFrequencySample(kernel_crashes_weekly_count_);
1095 SendCrashFrequencySample(unclean_shutdowns_weekly_count_);
1096 }
1097}
1098
Steve Funge86591e2014-12-01 13:38:21 -08001099void MetricsDaemon::HandleUpdateStatsTimeout() {
1100 UpdateStats(TimeTicks::Now(), Time::Now());
1101 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
1102 base::Bind(&MetricsDaemon::HandleUpdateStatsTimeout,
1103 base::Unretained(this)),
1104 base::TimeDelta::FromMilliseconds(kUpdateStatsIntervalMs));
Daniel Eratc83975a2014-04-04 08:53:44 -07001105}