blob: cf4d79df53994d7a3ae4704c287ec1d2292dda76 [file] [log] [blame]
Bertrand SIMONNET52e5b992015-08-10 15:18:00 -07001/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Darin Petkov65b01462010-04-14 13:32:20 -070016
Bertrand SIMONNET4b915ae2015-07-28 15:38:14 -070017#include "metrics_daemon.h"
Darin Petkov65b01462010-04-14 13:32:20 -070018
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080019#include <fcntl.h>
Luigi Semenzato4a6c9422014-06-30 18:12:28 -070020#include <inttypes.h>
Luigi Semenzato8accd332011-05-17 16:37:18 -070021#include <math.h>
Ken Mixter4c5daa42010-08-26 18:35:06 -070022#include <string.h>
Steve Funge86591e2014-12-01 13:38:21 -080023#include <sysexits.h>
Luigi Semenzato8accd332011-05-17 16:37:18 -070024#include <time.h>
Darin Petkov65b01462010-04-14 13:32:20 -070025
Bertrand SIMONNET4b915ae2015-07-28 15:38:14 -070026#include <base/bind.h>
Luigi Semenzato859b3f02014-02-05 15:33:19 -080027#include <base/files/file_path.h>
Ben Chan51bf92a2014-09-05 08:21:06 -070028#include <base/files/file_util.h>
Luigi Semenzato859b3f02014-02-05 15:33:19 -080029#include <base/hash.h>
Darin Petkov65b01462010-04-14 13:32:20 -070030#include <base/logging.h>
Ben Chan2e6543d2014-02-05 23:26:25 -080031#include <base/strings/string_number_conversions.h>
32#include <base/strings/string_split.h>
33#include <base/strings/string_util.h>
34#include <base/strings/stringprintf.h>
Bertrand SIMONNET26993622015-08-20 14:08:41 -070035#include <cutils/properties.h>
Steve Funge86591e2014-12-01 13:38:21 -080036#include <dbus/dbus.h>
37#include <dbus/message.h>
Bertrand SIMONNETbae5dcc2015-08-04 14:12:10 -070038
39#include "constants.h"
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -070040#include "uploader/upload_service.h"
Darin Petkov65b01462010-04-14 13:32:20 -070041
Ben Chan2e6543d2014-02-05 23:26:25 -080042using base::FilePath;
43using base::StringPrintf;
Darin Petkovf27f0362010-06-04 13:14:19 -070044using base::Time;
45using base::TimeDelta;
46using base::TimeTicks;
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080047using chromeos_metrics::PersistentInteger;
Luigi Semenzato8accd332011-05-17 16:37:18 -070048using std::map;
Darin Petkov38d5cb02010-06-24 12:10:26 -070049using std::string;
Luigi Semenzato8accd332011-05-17 16:37:18 -070050using std::vector;
51
Daniel Eratc83975a2014-04-04 08:53:44 -070052namespace {
Darin Petkovf27f0362010-06-04 13:14:19 -070053
Daniel Eratc83975a2014-04-04 08:53:44 -070054const char kCrashReporterInterface[] = "org.chromium.CrashReporter";
55const char kCrashReporterUserCrashSignal[] = "UserCrash";
Steve Funge86591e2014-12-01 13:38:21 -080056const char kCrashReporterMatchRule[] =
57 "type='signal',interface='%s',path='/',member='%s'";
Darin Petkov41e06232010-05-03 16:45:37 -070058
Daniel Eratc83975a2014-04-04 08:53:44 -070059const int kSecondsPerMinute = 60;
60const int kMinutesPerHour = 60;
61const int kHoursPerDay = 24;
62const int kMinutesPerDay = kHoursPerDay * kMinutesPerHour;
63const int kSecondsPerDay = kSecondsPerMinute * kMinutesPerDay;
64const int kDaysPerWeek = 7;
65const int kSecondsPerWeek = kSecondsPerDay * kDaysPerWeek;
Darin Petkov41e06232010-05-03 16:45:37 -070066
Daniel Eratc83975a2014-04-04 08:53:44 -070067// Interval between calls to UpdateStats().
Steve Funge86591e2014-12-01 13:38:21 -080068const uint32_t kUpdateStatsIntervalMs = 300000;
Darin Petkov65b01462010-04-14 13:32:20 -070069
Luigi Semenzatoc5a92342014-02-14 15:05:51 -080070const char kKernelCrashDetectedFile[] = "/var/run/kernel-crash-detected";
Daniel Eratc83975a2014-04-04 08:53:44 -070071const char kUncleanShutdownDetectedFile[] =
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -080072 "/var/run/unclean-shutdown-detected";
Ken Mixterccd84c02010-08-16 19:57:13 -070073
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080074// disk stats metrics
75
76// The {Read,Write}Sectors numbers are in sectors/second.
77// A sector is usually 512 bytes.
78
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -070079const char kMetricReadSectorsLongName[] = "Platform.ReadSectorsLong";
80const char kMetricWriteSectorsLongName[] = "Platform.WriteSectorsLong";
81const char kMetricReadSectorsShortName[] = "Platform.ReadSectorsShort";
82const char kMetricWriteSectorsShortName[] = "Platform.WriteSectorsShort";
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080083
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -070084const int kMetricStatsShortInterval = 1; // seconds
85const int kMetricStatsLongInterval = 30; // seconds
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080086
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -070087const int kMetricMeminfoInterval = 30; // seconds
Luigi Semenzato29c7ef92011-04-12 14:12:35 -070088
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -080089// Assume a max rate of 250Mb/s for reads (worse for writes) and 512 byte
90// sectors.
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -070091const int kMetricSectorsIOMax = 500000; // sectors/second
92const int kMetricSectorsBuckets = 50; // buckets
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070093// Page size is 4k, sector size is 0.5k. We're not interested in page fault
94// rates that the disk cannot sustain.
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -070095const int kMetricPageFaultsMax = kMetricSectorsIOMax / 8;
96const int kMetricPageFaultsBuckets = 50;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -070097
98// Major page faults, i.e. the ones that require data to be read from disk.
99
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700100const char kMetricPageFaultsLongName[] = "Platform.PageFaultsLong";
101const char kMetricPageFaultsShortName[] = "Platform.PageFaultsShort";
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800102
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700103// Swap in and Swap out
104
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700105const char kMetricSwapInLongName[] = "Platform.SwapInLong";
106const char kMetricSwapInShortName[] = "Platform.SwapInShort";
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700107
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700108const char kMetricSwapOutLongName[] = "Platform.SwapOutLong";
109const char kMetricSwapOutShortName[] = "Platform.SwapOutShort";
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700110
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700111const char kMetricsProcStatFileName[] = "/proc/stat";
112const char kVmStatFileName[] = "/proc/vmstat";
113const char kMeminfoFileName[] = "/proc/meminfo";
114const int kMetricsProcStatFirstLineItemsCount = 11;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700115
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700116// Thermal CPU throttling.
117
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700118const char kMetricScaledCpuFrequencyName[] =
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700119 "Platform.CpuFrequencyThermalScaling";
120
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700121} // namespace
122
Luigi Semenzato96360192014-06-04 10:53:35 -0700123// Zram sysfs entries.
124
125const char MetricsDaemon::kComprDataSizeName[] = "compr_data_size";
126const char MetricsDaemon::kOrigDataSizeName[] = "orig_data_size";
127const char MetricsDaemon::kZeroPagesName[] = "zero_pages";
128
Luigi Semenzato8accd332011-05-17 16:37:18 -0700129// Memory use stats collection intervals. We collect some memory use interval
130// at these intervals after boot, and we stop collecting after the last one,
131// with the assumption that in most cases the memory use won't change much
132// after that.
133static const int kMemuseIntervals[] = {
134 1 * kSecondsPerMinute, // 1 minute mark
135 4 * kSecondsPerMinute, // 5 minute mark
136 25 * kSecondsPerMinute, // 0.5 hour mark
137 120 * kSecondsPerMinute, // 2.5 hour mark
138 600 * kSecondsPerMinute, // 12.5 hour mark
139};
140
Darin Petkovf1e85e42010-06-10 15:59:53 -0700141MetricsDaemon::MetricsDaemon()
Steve Funge86591e2014-12-01 13:38:21 -0800142 : memuse_final_time_(0),
Luigi Semenzato8accd332011-05-17 16:37:18 -0700143 memuse_interval_index_(0),
144 read_sectors_(0),
145 write_sectors_(0),
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700146 vmstats_(),
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700147 stats_state_(kStatsShort),
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700148 stats_initial_time_(0),
149 ticks_per_second_(0),
150 latest_cpu_use_ticks_(0) {}
Darin Petkovf1e85e42010-06-10 15:59:53 -0700151
Ken Mixter4c5daa42010-08-26 18:35:06 -0700152MetricsDaemon::~MetricsDaemon() {
Ken Mixter4c5daa42010-08-26 18:35:06 -0700153}
154
Luigi Semenzato8accd332011-05-17 16:37:18 -0700155double MetricsDaemon::GetActiveTime() {
156 struct timespec ts;
157 int r = clock_gettime(CLOCK_MONOTONIC, &ts);
158 if (r < 0) {
159 PLOG(WARNING) << "clock_gettime(CLOCK_MONOTONIC) failed";
160 return 0;
161 } else {
Luigi Semenzato4a6c9422014-06-30 18:12:28 -0700162 return ts.tv_sec + static_cast<double>(ts.tv_nsec) / (1000 * 1000 * 1000);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700163 }
164}
165
Steve Funge86591e2014-12-01 13:38:21 -0800166int MetricsDaemon::Run() {
Ken Mixterccd84c02010-08-16 19:57:13 -0700167 if (CheckSystemCrash(kKernelCrashDetectedFile)) {
168 ProcessKernelCrash();
169 }
170
171 if (CheckSystemCrash(kUncleanShutdownDetectedFile)) {
172 ProcessUncleanShutdown();
173 }
174
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800175 // On OS version change, clear version stats (which are reported daily).
Ben Chanf05ab402014-08-07 00:54:59 -0700176 int32_t version = GetOsVersionHash();
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800177 if (version_cycle_->Get() != version) {
178 version_cycle_->Set(version);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800179 kernel_crashes_version_count_->Set(0);
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700180 version_cumulative_active_use_->Set(0);
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700181 version_cumulative_cpu_use_->Set(0);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800182 }
183
Steve Funge86591e2014-12-01 13:38:21 -0800184 return chromeos::DBusDaemon::Run();
Darin Petkov65b01462010-04-14 13:32:20 -0700185}
186
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700187void MetricsDaemon::RunUploaderTest() {
Bertrand SIMONNET12531862015-08-31 11:11:57 -0700188 upload_service_.reset(new UploadService(
189 new SystemProfileCache(true, base::FilePath(config_root_)),
190 metrics_lib_,
191 server_));
Bertrand SIMONNETcac74e12014-10-09 10:14:13 -0700192 upload_service_->Init(upload_interval_, metrics_file_);
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700193 upload_service_->UploadEvent();
194}
195
Ben Chanf05ab402014-08-07 00:54:59 -0700196uint32_t MetricsDaemon::GetOsVersionHash() {
197 static uint32_t cached_version_hash = 0;
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800198 static bool version_hash_is_cached = false;
199 if (version_hash_is_cached)
200 return cached_version_hash;
201 version_hash_is_cached = true;
Bertrand SIMONNET26993622015-08-20 14:08:41 -0700202
203 char version[PROPERTY_VALUE_MAX];
Bertrand SIMONNETbae5dcc2015-08-04 14:12:10 -0700204 // The version might not be set for development devices. In this case, use the
205 // zero version.
Bertrand SIMONNET26993622015-08-20 14:08:41 -0700206 property_get(metrics::kProductVersionProperty, version,
207 metrics::kDefaultVersion);
208
Bertrand SIMONNETbae5dcc2015-08-04 14:12:10 -0700209 cached_version_hash = base::Hash(version);
210 if (testing_) {
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800211 cached_version_hash = 42; // return any plausible value for the hash
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800212 }
213 return cached_version_hash;
214}
215
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700216void MetricsDaemon::Init(bool testing,
217 bool uploader_active,
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700218 bool dbus_enabled,
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700219 MetricsLibraryInterface* metrics_lib,
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700220 const string& scaling_max_freq_path,
Steve Fung67906c62014-10-06 15:15:30 -0700221 const string& cpuinfo_max_freq_path,
Bertrand SIMONNETcac74e12014-10-09 10:14:13 -0700222 const base::TimeDelta& upload_interval,
Steve Fung67906c62014-10-06 15:15:30 -0700223 const string& server,
Bertrand SIMONNET71a62ef2014-10-07 11:26:25 -0700224 const string& metrics_file,
225 const string& config_root) {
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700226 CHECK(metrics_lib);
Darin Petkov65b01462010-04-14 13:32:20 -0700227 testing_ = testing;
Steve Funge86591e2014-12-01 13:38:21 -0800228 uploader_active_ = uploader_active;
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700229 dbus_enabled_ = dbus_enabled;
Bertrand SIMONNET71a62ef2014-10-07 11:26:25 -0700230 config_root_ = config_root;
Darin Petkovfc91b422010-05-12 13:05:45 -0700231 metrics_lib_ = metrics_lib;
Darin Petkov38d5cb02010-06-24 12:10:26 -0700232
Bertrand SIMONNETcac74e12014-10-09 10:14:13 -0700233 upload_interval_ = upload_interval;
Steve Fung67906c62014-10-06 15:15:30 -0700234 server_ = server;
235 metrics_file_ = metrics_file;
236
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700237 // Get ticks per second (HZ) on this system.
238 // Sysconf cannot fail, so no sanity checks are needed.
239 ticks_per_second_ = sysconf(_SC_CLK_TCK);
240
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700241 daily_active_use_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700242 new PersistentInteger("Platform.DailyUseTime"));
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700243 version_cumulative_active_use_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700244 new PersistentInteger("Platform.CumulativeDailyUseTime"));
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700245 version_cumulative_cpu_use_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700246 new PersistentInteger("Platform.CumulativeCpuTime"));
Darin Petkov38d5cb02010-06-24 12:10:26 -0700247
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800248 kernel_crash_interval_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700249 new PersistentInteger("Platform.KernelCrashInterval"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800250 unclean_shutdown_interval_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700251 new PersistentInteger("Platform.UncleanShutdownInterval"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800252 user_crash_interval_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700253 new PersistentInteger("Platform.UserCrashInterval"));
Darin Petkov2ccef012010-05-05 16:06:37 -0700254
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800255 any_crashes_daily_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700256 new PersistentInteger("Platform.AnyCrashesDaily"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800257 any_crashes_weekly_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700258 new PersistentInteger("Platform.AnyCrashesWeekly"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800259 user_crashes_daily_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700260 new PersistentInteger("Platform.UserCrashesDaily"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800261 user_crashes_weekly_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700262 new PersistentInteger("Platform.UserCrashesWeekly"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800263 kernel_crashes_daily_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700264 new PersistentInteger("Platform.KernelCrashesDaily"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800265 kernel_crashes_weekly_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700266 new PersistentInteger("Platform.KernelCrashesWeekly"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800267 kernel_crashes_version_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700268 new PersistentInteger("Platform.KernelCrashesSinceUpdate"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800269 unclean_shutdowns_daily_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700270 new PersistentInteger("Platform.UncleanShutdownsDaily"));
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800271 unclean_shutdowns_weekly_count_.reset(
Luigi Semenzatodc865892015-07-09 08:28:08 -0700272 new PersistentInteger("Platform.UncleanShutdownsWeekly"));
Darin Petkov38d5cb02010-06-24 12:10:26 -0700273
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800274 daily_cycle_.reset(new PersistentInteger("daily.cycle"));
275 weekly_cycle_.reset(new PersistentInteger("weekly.cycle"));
276 version_cycle_.reset(new PersistentInteger("version.cycle"));
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800277
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700278 scaling_max_freq_path_ = scaling_max_freq_path;
279 cpuinfo_max_freq_path_ = cpuinfo_max_freq_path;
Steve Funge86591e2014-12-01 13:38:21 -0800280}
281
282int MetricsDaemon::OnInit() {
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700283 int return_code = dbus_enabled_ ? chromeos::DBusDaemon::OnInit() :
284 chromeos::Daemon::OnInit();
Steve Funge86591e2014-12-01 13:38:21 -0800285 if (return_code != EX_OK)
286 return return_code;
287
Steve Funge86591e2014-12-01 13:38:21 -0800288 if (testing_)
289 return EX_OK;
Darin Petkov65b01462010-04-14 13:32:20 -0700290
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700291 if (dbus_enabled_) {
292 bus_->AssertOnDBusThread();
293 CHECK(bus_->SetUpAsyncOperations());
Darin Petkov65b01462010-04-14 13:32:20 -0700294
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700295 if (bus_->is_connected()) {
296 const std::string match_rule =
297 base::StringPrintf(kCrashReporterMatchRule,
298 kCrashReporterInterface,
299 kCrashReporterUserCrashSignal);
Darin Petkov65b01462010-04-14 13:32:20 -0700300
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700301 bus_->AddFilterFunction(&MetricsDaemon::MessageFilter, this);
Darin Petkov65b01462010-04-14 13:32:20 -0700302
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700303 DBusError error;
304 dbus_error_init(&error);
305 bus_->AddMatch(match_rule, &error);
Darin Petkov65b01462010-04-14 13:32:20 -0700306
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700307 if (dbus_error_is_set(&error)) {
308 LOG(ERROR) << "Failed to add match rule \"" << match_rule << "\". Got "
309 << error.name << ": " << error.message;
310 return EX_SOFTWARE;
311 }
312 } else {
313 LOG(ERROR) << "DBus isn't connected.";
314 return EX_UNAVAILABLE;
Steve Funge86591e2014-12-01 13:38:21 -0800315 }
Darin Petkov703ec972010-04-27 11:02:18 -0700316 }
317
Steve Funge86591e2014-12-01 13:38:21 -0800318 if (uploader_active_) {
Bertrand SIMONNETbae5dcc2015-08-04 14:12:10 -0700319 upload_service_.reset(
320 new UploadService(new SystemProfileCache(), metrics_lib_, server_));
321 upload_service_->Init(upload_interval_, metrics_file_);
Bertrand SIMONNET46b49da2014-06-25 14:38:07 -0700322 }
Steve Funge86591e2014-12-01 13:38:21 -0800323
324 return EX_OK;
Darin Petkov65b01462010-04-14 13:32:20 -0700325}
326
Steve Funge86591e2014-12-01 13:38:21 -0800327void MetricsDaemon::OnShutdown(int* return_code) {
Bertrand SIMONNETfec4d2c2015-08-05 16:04:14 -0700328 if (!testing_ && dbus_enabled_ && bus_->is_connected()) {
Steve Funge86591e2014-12-01 13:38:21 -0800329 const std::string match_rule =
330 base::StringPrintf(kCrashReporterMatchRule,
331 kCrashReporterInterface,
332 kCrashReporterUserCrashSignal);
333
334 bus_->RemoveFilterFunction(&MetricsDaemon::MessageFilter, this);
335
336 DBusError error;
337 dbus_error_init(&error);
338 bus_->RemoveMatch(match_rule, &error);
339
340 if (dbus_error_is_set(&error)) {
341 LOG(ERROR) << "Failed to remove match rule \"" << match_rule << "\". Got "
342 << error.name << ": " << error.message;
343 }
344 }
345 chromeos::DBusDaemon::OnShutdown(return_code);
Darin Petkov65b01462010-04-14 13:32:20 -0700346}
347
Darin Petkov703ec972010-04-27 11:02:18 -0700348// static
349DBusHandlerResult MetricsDaemon::MessageFilter(DBusConnection* connection,
350 DBusMessage* message,
351 void* user_data) {
Darin Petkov703ec972010-04-27 11:02:18 -0700352 int message_type = dbus_message_get_type(message);
353 if (message_type != DBUS_MESSAGE_TYPE_SIGNAL) {
Darin Petkov41e06232010-05-03 16:45:37 -0700354 DLOG(WARNING) << "unexpected message type " << message_type;
Darin Petkov703ec972010-04-27 11:02:18 -0700355 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
356 }
357
358 // Signal messages always have interfaces.
Daniel Eratc83975a2014-04-04 08:53:44 -0700359 const std::string interface(dbus_message_get_interface(message));
360 const std::string member(dbus_message_get_member(message));
361 DLOG(INFO) << "Got " << interface << "." << member << " D-Bus signal";
Darin Petkov703ec972010-04-27 11:02:18 -0700362
363 MetricsDaemon* daemon = static_cast<MetricsDaemon*>(user_data);
364
365 DBusMessageIter iter;
366 dbus_message_iter_init(message, &iter);
Daniel Eratc83975a2014-04-04 08:53:44 -0700367 if (interface == kCrashReporterInterface) {
368 CHECK_EQ(member, kCrashReporterUserCrashSignal);
Darin Petkov1bb904e2010-06-16 15:58:06 -0700369 daemon->ProcessUserCrash();
Darin Petkov703ec972010-04-27 11:02:18 -0700370 } else {
Daniel Eratc83975a2014-04-04 08:53:44 -0700371 // Ignore messages from the bus itself.
Darin Petkov703ec972010-04-27 11:02:18 -0700372 return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
373 }
374
375 return DBUS_HANDLER_RESULT_HANDLED;
Darin Petkov65b01462010-04-14 13:32:20 -0700376}
377
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700378// One might argue that parts of this should go into
379// chromium/src/base/sys_info_chromeos.c instead, but put it here for now.
380
381TimeDelta MetricsDaemon::GetIncrementalCpuUse() {
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700382 FilePath proc_stat_path = FilePath(kMetricsProcStatFileName);
383 std::string proc_stat_string;
384 if (!base::ReadFileToString(proc_stat_path, &proc_stat_string)) {
385 LOG(WARNING) << "cannot open " << kMetricsProcStatFileName;
386 return TimeDelta();
387 }
388
389 std::vector<std::string> proc_stat_lines;
390 base::SplitString(proc_stat_string, '\n', &proc_stat_lines);
391 if (proc_stat_lines.empty()) {
392 LOG(WARNING) << "cannot parse " << kMetricsProcStatFileName
393 << ": " << proc_stat_string;
394 return TimeDelta();
395 }
396 std::vector<std::string> proc_stat_totals;
397 base::SplitStringAlongWhitespace(proc_stat_lines[0], &proc_stat_totals);
398
Ben Chanf05ab402014-08-07 00:54:59 -0700399 uint64_t user_ticks, user_nice_ticks, system_ticks;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700400 if (proc_stat_totals.size() != kMetricsProcStatFirstLineItemsCount ||
401 proc_stat_totals[0] != "cpu" ||
402 !base::StringToUint64(proc_stat_totals[1], &user_ticks) ||
403 !base::StringToUint64(proc_stat_totals[2], &user_nice_ticks) ||
404 !base::StringToUint64(proc_stat_totals[3], &system_ticks)) {
405 LOG(WARNING) << "cannot parse first line: " << proc_stat_lines[0];
406 return TimeDelta(base::TimeDelta::FromSeconds(0));
407 }
408
Ben Chanf05ab402014-08-07 00:54:59 -0700409 uint64_t total_cpu_use_ticks = user_ticks + user_nice_ticks + system_ticks;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700410
411 // Sanity check.
412 if (total_cpu_use_ticks < latest_cpu_use_ticks_) {
413 LOG(WARNING) << "CPU time decreasing from " << latest_cpu_use_ticks_
414 << " to " << total_cpu_use_ticks;
415 return TimeDelta();
416 }
417
Ben Chanf05ab402014-08-07 00:54:59 -0700418 uint64_t diff = total_cpu_use_ticks - latest_cpu_use_ticks_;
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700419 latest_cpu_use_ticks_ = total_cpu_use_ticks;
420 // Use microseconds to avoid significant truncations.
421 return base::TimeDelta::FromMicroseconds(
422 diff * 1000 * 1000 / ticks_per_second_);
423}
424
Darin Petkov1bb904e2010-06-16 15:58:06 -0700425void MetricsDaemon::ProcessUserCrash() {
Daniel Eratc83975a2014-04-04 08:53:44 -0700426 // Counts the active time up to now.
427 UpdateStats(TimeTicks::Now(), Time::Now());
Darin Petkov1bb904e2010-06-16 15:58:06 -0700428
429 // Reports the active use time since the last crash and resets it.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800430 SendCrashIntervalSample(user_crash_interval_);
Ken Mixterccd84c02010-08-16 19:57:13 -0700431
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800432 any_crashes_daily_count_->Add(1);
433 any_crashes_weekly_count_->Add(1);
434 user_crashes_daily_count_->Add(1);
435 user_crashes_weekly_count_->Add(1);
Darin Petkov1bb904e2010-06-16 15:58:06 -0700436}
437
Darin Petkov38d5cb02010-06-24 12:10:26 -0700438void MetricsDaemon::ProcessKernelCrash() {
Daniel Eratc83975a2014-04-04 08:53:44 -0700439 // Counts the active time up to now.
440 UpdateStats(TimeTicks::Now(), Time::Now());
Darin Petkov38d5cb02010-06-24 12:10:26 -0700441
442 // Reports the active use time since the last crash and resets it.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800443 SendCrashIntervalSample(kernel_crash_interval_);
Ken Mixterccd84c02010-08-16 19:57:13 -0700444
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800445 any_crashes_daily_count_->Add(1);
446 any_crashes_weekly_count_->Add(1);
447 kernel_crashes_daily_count_->Add(1);
448 kernel_crashes_weekly_count_->Add(1);
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800449
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800450 kernel_crashes_version_count_->Add(1);
Darin Petkov38d5cb02010-06-24 12:10:26 -0700451}
452
Ken Mixterccd84c02010-08-16 19:57:13 -0700453void MetricsDaemon::ProcessUncleanShutdown() {
Daniel Eratc83975a2014-04-04 08:53:44 -0700454 // Counts the active time up to now.
455 UpdateStats(TimeTicks::Now(), Time::Now());
Ken Mixterccd84c02010-08-16 19:57:13 -0700456
457 // Reports the active use time since the last crash and resets it.
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800458 SendCrashIntervalSample(unclean_shutdown_interval_);
Ken Mixterccd84c02010-08-16 19:57:13 -0700459
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800460 unclean_shutdowns_daily_count_->Add(1);
461 unclean_shutdowns_weekly_count_->Add(1);
462 any_crashes_daily_count_->Add(1);
463 any_crashes_weekly_count_->Add(1);
Ken Mixterccd84c02010-08-16 19:57:13 -0700464}
465
Luigi Semenzato8accd332011-05-17 16:37:18 -0700466bool MetricsDaemon::CheckSystemCrash(const string& crash_file) {
Darin Petkov38d5cb02010-06-24 12:10:26 -0700467 FilePath crash_detected(crash_file);
Ben Chan2e6543d2014-02-05 23:26:25 -0800468 if (!base::PathExists(crash_detected))
Ken Mixterccd84c02010-08-16 19:57:13 -0700469 return false;
Darin Petkov38d5cb02010-06-24 12:10:26 -0700470
471 // Deletes the crash-detected file so that the daemon doesn't report
472 // another kernel crash in case it's restarted.
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800473 base::DeleteFile(crash_detected, false); // not recursive
Ken Mixterccd84c02010-08-16 19:57:13 -0700474 return true;
Darin Petkov38d5cb02010-06-24 12:10:26 -0700475}
476
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700477void MetricsDaemon::StatsReporterInit() {
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800478 DiskStatsReadStats(&read_sectors_, &write_sectors_);
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700479 VmStatsReadStats(&vmstats_);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800480 // The first time around just run the long stat, so we don't delay boot.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700481 stats_state_ = kStatsLong;
482 stats_initial_time_ = GetActiveTime();
483 if (stats_initial_time_ < 0) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700484 LOG(WARNING) << "not collecting disk stats";
485 } else {
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700486 ScheduleStatsCallback(kMetricStatsLongInterval);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700487 }
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800488}
489
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700490void MetricsDaemon::ScheduleStatsCallback(int wait) {
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800491 if (testing_) {
492 return;
493 }
Steve Funge86591e2014-12-01 13:38:21 -0800494 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
495 base::Bind(&MetricsDaemon::StatsCallback, base::Unretained(this)),
496 base::TimeDelta::FromSeconds(wait));
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800497}
498
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700499bool MetricsDaemon::VmStatsParseStats(const char* stats,
500 struct VmstatRecord* record) {
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700501 CHECK(stats);
502 CHECK(record);
503 base::StringPairs pairs;
504 base::SplitStringIntoKeyValuePairs(stats, ' ', '\n', &pairs);
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700505
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700506 for (base::StringPairs::iterator it = pairs.begin(); it != pairs.end(); ++it) {
507 if (it->first == "pgmajfault" &&
508 !base::StringToUint64(it->second, &record->page_faults_)) {
509 return false;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700510 }
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700511 if (it->first == "pswpin" &&
512 !base::StringToUint64(it->second, &record->swap_in_)) {
513 return false;
514 }
515 if (it->first == "pswpout" &&
516 !base::StringToUint64(it->second, &record->swap_out_)) {
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700517 return false;
518 }
519 }
520 return true;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700521}
522
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700523bool MetricsDaemon::VmStatsReadStats(struct VmstatRecord* stats) {
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700524 CHECK(stats);
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700525 string value_string;
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700526 if (!base::ReadFileToString(base::FilePath(kVmStatFileName), &value_string)) {
527 LOG(WARNING) << "cannot read " << kVmStatFileName;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700528 return false;
529 }
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700530 return VmStatsParseStats(value_string.c_str(), stats);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800531}
532
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700533bool MetricsDaemon::ReadFreqToInt(const string& sysfs_file_name, int* value) {
Luigi Semenzatod92d18c2013-06-04 13:24:21 -0700534 const FilePath sysfs_path(sysfs_file_name);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700535 string value_string;
Ben Chan2e6543d2014-02-05 23:26:25 -0800536 if (!base::ReadFileToString(sysfs_path, &value_string)) {
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700537 LOG(WARNING) << "cannot read " << sysfs_path.value().c_str();
538 return false;
539 }
Ben Chan2e6543d2014-02-05 23:26:25 -0800540 if (!base::RemoveChars(value_string, "\n", &value_string)) {
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700541 LOG(WARNING) << "no newline in " << value_string;
542 // Continue even though the lack of newline is suspicious.
543 }
544 if (!base::StringToInt(value_string, value)) {
545 LOG(WARNING) << "cannot convert " << value_string << " to int";
546 return false;
547 }
548 return true;
549}
550
551void MetricsDaemon::SendCpuThrottleMetrics() {
552 // |max_freq| is 0 only the first time through.
553 static int max_freq = 0;
554 if (max_freq == -1)
555 // Give up, as sysfs did not report max_freq correctly.
556 return;
557 if (max_freq == 0 || testing_) {
558 // One-time initialization of max_freq. (Every time when testing.)
559 if (!ReadFreqToInt(cpuinfo_max_freq_path_, &max_freq)) {
560 max_freq = -1;
561 return;
562 }
563 if (max_freq == 0) {
564 LOG(WARNING) << "sysfs reports 0 max CPU frequency\n";
565 max_freq = -1;
566 return;
567 }
568 if (max_freq % 10000 == 1000) {
569 // Special case: system has turbo mode, and max non-turbo frequency is
570 // max_freq - 1000. This relies on "normal" (non-turbo) frequencies
571 // being multiples of (at least) 10 MHz. Although there is no guarantee
572 // of this, it seems a fairly reasonable assumption. Otherwise we should
573 // read scaling_available_frequencies, sort the frequencies, compare the
574 // two highest ones, and check if they differ by 1000 (kHz) (and that's a
575 // hack too, no telling when it will change).
576 max_freq -= 1000;
577 }
578 }
579 int scaled_freq = 0;
580 if (!ReadFreqToInt(scaling_max_freq_path_, &scaled_freq))
581 return;
582 // Frequencies are in kHz. If scaled_freq > max_freq, turbo is on, but
583 // scaled_freq is not the actual turbo frequency. We indicate this situation
584 // with a 101% value.
585 int percent = scaled_freq > max_freq ? 101 : scaled_freq / (max_freq / 100);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800586 SendLinearSample(kMetricScaledCpuFrequencyName, percent, 101, 102);
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700587}
588
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700589// Collects disk and vm stats alternating over a short and a long interval.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700590
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700591void MetricsDaemon::StatsCallback() {
Ben Chanf05ab402014-08-07 00:54:59 -0700592 uint64_t read_sectors_now, write_sectors_now;
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700593 struct VmstatRecord vmstats_now;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700594 double time_now = GetActiveTime();
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700595 double delta_time = time_now - stats_initial_time_;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700596 if (testing_) {
597 // Fake the time when testing.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700598 delta_time = stats_state_ == kStatsShort ?
599 kMetricStatsShortInterval : kMetricStatsLongInterval;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700600 }
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700601 bool diskstats_success = DiskStatsReadStats(&read_sectors_now,
602 &write_sectors_now);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700603 int delta_read = read_sectors_now - read_sectors_;
604 int delta_write = write_sectors_now - write_sectors_;
605 int read_sectors_per_second = delta_read / delta_time;
606 int write_sectors_per_second = delta_write / delta_time;
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700607 bool vmstats_success = VmStatsReadStats(&vmstats_now);
608 uint64_t delta_faults = vmstats_now.page_faults_ - vmstats_.page_faults_;
609 uint64_t delta_swap_in = vmstats_now.swap_in_ - vmstats_.swap_in_;
610 uint64_t delta_swap_out = vmstats_now.swap_out_ - vmstats_.swap_out_;
611 uint64_t page_faults_per_second = delta_faults / delta_time;
612 uint64_t swap_in_per_second = delta_swap_in / delta_time;
613 uint64_t swap_out_per_second = delta_swap_out / delta_time;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800614
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700615 switch (stats_state_) {
616 case kStatsShort:
617 if (diskstats_success) {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800618 SendSample(kMetricReadSectorsShortName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700619 read_sectors_per_second,
620 1,
621 kMetricSectorsIOMax,
622 kMetricSectorsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800623 SendSample(kMetricWriteSectorsShortName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700624 write_sectors_per_second,
625 1,
626 kMetricSectorsIOMax,
627 kMetricSectorsBuckets);
628 }
629 if (vmstats_success) {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800630 SendSample(kMetricPageFaultsShortName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700631 page_faults_per_second,
632 1,
633 kMetricPageFaultsMax,
634 kMetricPageFaultsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800635 SendSample(kMetricSwapInShortName,
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700636 swap_in_per_second,
637 1,
638 kMetricPageFaultsMax,
639 kMetricPageFaultsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800640 SendSample(kMetricSwapOutShortName,
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700641 swap_out_per_second,
642 1,
643 kMetricPageFaultsMax,
644 kMetricPageFaultsBuckets);
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700645 }
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800646 // Schedule long callback.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700647 stats_state_ = kStatsLong;
648 ScheduleStatsCallback(kMetricStatsLongInterval -
649 kMetricStatsShortInterval);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800650 break;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700651 case kStatsLong:
652 if (diskstats_success) {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800653 SendSample(kMetricReadSectorsLongName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700654 read_sectors_per_second,
655 1,
656 kMetricSectorsIOMax,
657 kMetricSectorsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800658 SendSample(kMetricWriteSectorsLongName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700659 write_sectors_per_second,
660 1,
661 kMetricSectorsIOMax,
662 kMetricSectorsBuckets);
663 // Reset sector counters.
664 read_sectors_ = read_sectors_now;
665 write_sectors_ = write_sectors_now;
666 }
667 if (vmstats_success) {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800668 SendSample(kMetricPageFaultsLongName,
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700669 page_faults_per_second,
670 1,
671 kMetricPageFaultsMax,
672 kMetricPageFaultsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800673 SendSample(kMetricSwapInLongName,
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700674 swap_in_per_second,
675 1,
676 kMetricPageFaultsMax,
677 kMetricPageFaultsBuckets);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800678 SendSample(kMetricSwapOutLongName,
Sonny Rao4b8aebb2013-07-31 23:18:31 -0700679 swap_out_per_second,
680 1,
681 kMetricPageFaultsMax,
682 kMetricPageFaultsBuckets);
683
684 vmstats_ = vmstats_now;
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700685 }
Luigi Semenzatofb3a8212013-05-07 16:55:00 -0700686 SendCpuThrottleMetrics();
Luigi Semenzato8accd332011-05-17 16:37:18 -0700687 // Set start time for new cycle.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700688 stats_initial_time_ = time_now;
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800689 // Schedule short callback.
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700690 stats_state_ = kStatsShort;
691 ScheduleStatsCallback(kMetricStatsShortInterval);
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800692 break;
693 default:
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700694 LOG(FATAL) << "Invalid stats state";
Luigi Semenzatoc88e42d2011-02-17 10:21:16 -0800695 }
696}
697
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700698void MetricsDaemon::ScheduleMeminfoCallback(int wait) {
699 if (testing_) {
700 return;
701 }
Steve Funge86591e2014-12-01 13:38:21 -0800702 base::TimeDelta waitDelta = base::TimeDelta::FromSeconds(wait);
703 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
704 base::Bind(&MetricsDaemon::MeminfoCallback, base::Unretained(this),
Steve Fung8ab89c52015-01-05 13:48:30 -0800705 waitDelta),
Steve Funge86591e2014-12-01 13:38:21 -0800706 waitDelta);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700707}
708
Steve Funge86591e2014-12-01 13:38:21 -0800709void MetricsDaemon::MeminfoCallback(base::TimeDelta wait) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700710 string meminfo_raw;
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700711 const FilePath meminfo_path(kMeminfoFileName);
Ben Chan2e6543d2014-02-05 23:26:25 -0800712 if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700713 LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
Steve Funge86591e2014-12-01 13:38:21 -0800714 return;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700715 }
Luigi Semenzato96360192014-06-04 10:53:35 -0700716 // Make both calls even if the first one fails.
717 bool success = ProcessMeminfo(meminfo_raw);
Steve Funge86591e2014-12-01 13:38:21 -0800718 bool reschedule =
719 ReportZram(base::FilePath(FILE_PATH_LITERAL("/sys/block/zram0"))) &&
Luigi Semenzato96360192014-06-04 10:53:35 -0700720 success;
Steve Funge86591e2014-12-01 13:38:21 -0800721 if (reschedule) {
722 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
723 base::Bind(&MetricsDaemon::MeminfoCallback, base::Unretained(this),
Steve Fung8ab89c52015-01-05 13:48:30 -0800724 wait),
Steve Funge86591e2014-12-01 13:38:21 -0800725 wait);
726 }
Luigi Semenzato96360192014-06-04 10:53:35 -0700727}
728
729// static
730bool MetricsDaemon::ReadFileToUint64(const base::FilePath& path,
Ben Chanf05ab402014-08-07 00:54:59 -0700731 uint64_t* value) {
Luigi Semenzato96360192014-06-04 10:53:35 -0700732 std::string content;
733 if (!base::ReadFileToString(path, &content)) {
734 PLOG(WARNING) << "cannot read " << path.MaybeAsASCII();
735 return false;
736 }
Luigi Semenzato4a6c9422014-06-30 18:12:28 -0700737 // Remove final newline.
738 base::TrimWhitespaceASCII(content, base::TRIM_TRAILING, &content);
Luigi Semenzato96360192014-06-04 10:53:35 -0700739 if (!base::StringToUint64(content, value)) {
740 LOG(WARNING) << "invalid integer: " << content;
741 return false;
742 }
743 return true;
744}
745
746bool MetricsDaemon::ReportZram(const base::FilePath& zram_dir) {
747 // Data sizes are in bytes. |zero_pages| is in number of pages.
Ben Chanf05ab402014-08-07 00:54:59 -0700748 uint64_t compr_data_size, orig_data_size, zero_pages;
Luigi Semenzato96360192014-06-04 10:53:35 -0700749 const size_t page_size = 4096;
750
751 if (!ReadFileToUint64(zram_dir.Append(kComprDataSizeName),
752 &compr_data_size) ||
753 !ReadFileToUint64(zram_dir.Append(kOrigDataSizeName), &orig_data_size) ||
754 !ReadFileToUint64(zram_dir.Append(kZeroPagesName), &zero_pages)) {
755 return false;
756 }
757
758 // |orig_data_size| does not include zero-filled pages.
759 orig_data_size += zero_pages * page_size;
760
761 const int compr_data_size_mb = compr_data_size >> 20;
762 const int savings_mb = (orig_data_size - compr_data_size) >> 20;
763 const int zero_ratio_percent = zero_pages * page_size * 100 / orig_data_size;
764
765 // Report compressed size in megabytes. 100 MB or less has little impact.
766 SendSample("Platform.ZramCompressedSize", compr_data_size_mb, 100, 4000, 50);
767 SendSample("Platform.ZramSavings", savings_mb, 100, 4000, 50);
768 // The compression ratio is multiplied by 100 for better resolution. The
769 // ratios of interest are between 1 and 6 (100% and 600% as reported). We
770 // don't want samples when very little memory is being compressed.
771 if (compr_data_size_mb >= 1) {
772 SendSample("Platform.ZramCompressionRatioPercent",
773 orig_data_size * 100 / compr_data_size, 100, 600, 50);
774 }
775 // The values of interest for zero_pages are between 1MB and 1GB. The units
776 // are number of pages.
777 SendSample("Platform.ZramZeroPages", zero_pages, 256, 256 * 1024, 50);
778 SendSample("Platform.ZramZeroRatioPercent", zero_ratio_percent, 1, 50, 50);
779
780 return true;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700781}
782
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700783bool MetricsDaemon::ProcessMeminfo(const string& meminfo_raw) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700784 static const MeminfoRecord fields_array[] = {
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700785 { "MemTotal", "MemTotal" }, // SPECIAL CASE: total system memory
786 { "MemFree", "MemFree" },
787 { "Buffers", "Buffers" },
788 { "Cached", "Cached" },
789 // { "SwapCached", "SwapCached" },
790 { "Active", "Active" },
791 { "Inactive", "Inactive" },
792 { "ActiveAnon", "Active(anon)" },
793 { "InactiveAnon", "Inactive(anon)" },
794 { "ActiveFile" , "Active(file)" },
795 { "InactiveFile", "Inactive(file)" },
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800796 { "Unevictable", "Unevictable", kMeminfoOp_HistLog },
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700797 // { "Mlocked", "Mlocked" },
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800798 { "SwapTotal", "SwapTotal", kMeminfoOp_SwapTotal },
799 { "SwapFree", "SwapFree", kMeminfoOp_SwapFree },
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700800 // { "Dirty", "Dirty" },
801 // { "Writeback", "Writeback" },
802 { "AnonPages", "AnonPages" },
803 { "Mapped", "Mapped" },
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800804 { "Shmem", "Shmem", kMeminfoOp_HistLog },
805 { "Slab", "Slab", kMeminfoOp_HistLog },
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700806 // { "SReclaimable", "SReclaimable" },
807 // { "SUnreclaim", "SUnreclaim" },
808 };
Luigi Semenzato8accd332011-05-17 16:37:18 -0700809 vector<MeminfoRecord> fields(fields_array,
810 fields_array + arraysize(fields_array));
811 if (!FillMeminfo(meminfo_raw, &fields)) {
812 return false;
813 }
814 int total_memory = fields[0].value;
815 if (total_memory == 0) {
816 // this "cannot happen"
817 LOG(WARNING) << "borked meminfo parser";
818 return false;
819 }
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800820 int swap_total = 0;
821 int swap_free = 0;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700822 // Send all fields retrieved, except total memory.
823 for (unsigned int i = 1; i < fields.size(); i++) {
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800824 string metrics_name = base::StringPrintf("Platform.Meminfo%s",
825 fields[i].name);
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800826 int percent;
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800827 switch (fields[i].op) {
828 case kMeminfoOp_HistPercent:
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800829 // report value as percent of total memory
830 percent = fields[i].value * 100 / total_memory;
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800831 SendLinearSample(metrics_name, percent, 100, 101);
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800832 break;
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800833 case kMeminfoOp_HistLog:
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800834 // report value in kbytes, log scale, 4Gb max
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800835 SendSample(metrics_name, fields[i].value, 1, 4 * 1000 * 1000, 100);
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800836 break;
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800837 case kMeminfoOp_SwapTotal:
838 swap_total = fields[i].value;
839 case kMeminfoOp_SwapFree:
840 swap_free = fields[i].value;
Luigi Semenzato3ccca062013-02-04 19:50:45 -0800841 break;
Luigi Semenzato8accd332011-05-17 16:37:18 -0700842 }
843 }
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800844 if (swap_total > 0) {
845 int swap_used = swap_total - swap_free;
846 int swap_used_percent = swap_used * 100 / swap_total;
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800847 SendSample("Platform.MeminfoSwapUsed", swap_used, 1, 8 * 1000 * 1000, 100);
848 SendLinearSample("Platform.MeminfoSwapUsedPercent", swap_used_percent,
Luigi Semenzato942cbab2013-02-12 13:17:07 -0800849 100, 101);
850 }
Luigi Semenzato8accd332011-05-17 16:37:18 -0700851 return true;
852}
853
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700854bool MetricsDaemon::FillMeminfo(const string& meminfo_raw,
855 vector<MeminfoRecord>* fields) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700856 vector<string> lines;
857 unsigned int nlines = Tokenize(meminfo_raw, "\n", &lines);
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700858
859 // Scan meminfo output and collect field values. Each field name has to
860 // match a meminfo entry (case insensitive) after removing non-alpha
861 // characters from the entry.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700862 unsigned int ifield = 0;
863 for (unsigned int iline = 0;
864 iline < nlines && ifield < fields->size();
865 iline++) {
866 vector<string> tokens;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700867 Tokenize(lines[iline], ": ", &tokens);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700868 if (strcmp((*fields)[ifield].match, tokens[0].c_str()) == 0) {
869 // Name matches. Parse value and save.
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700870 if (!base::StringToInt(tokens[1], &(*fields)[ifield].value)) {
871 LOG(WARNING) << "Cound not convert " << tokens[1] << " to int";
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700872 return false;
873 }
Luigi Semenzato8accd332011-05-17 16:37:18 -0700874 ifield++;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700875 }
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700876 }
Luigi Semenzato8accd332011-05-17 16:37:18 -0700877 if (ifield < fields->size()) {
878 // End of input reached while scanning.
879 LOG(WARNING) << "cannot find field " << (*fields)[ifield].match
880 << " and following";
881 return false;
882 }
883 return true;
884}
885
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800886void MetricsDaemon::ScheduleMemuseCallback(double interval) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700887 if (testing_) {
888 return;
889 }
Steve Funge86591e2014-12-01 13:38:21 -0800890 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
891 base::Bind(&MetricsDaemon::MemuseCallback, base::Unretained(this)),
892 base::TimeDelta::FromSeconds(interval));
Luigi Semenzato8accd332011-05-17 16:37:18 -0700893}
894
895void MetricsDaemon::MemuseCallback() {
896 // Since we only care about active time (i.e. uptime minus sleep time) but
897 // the callbacks are driven by real time (uptime), we check if we should
898 // reschedule this callback due to intervening sleep periods.
899 double now = GetActiveTime();
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800900 // Avoid intervals of less than one second.
901 double remaining_time = ceil(memuse_final_time_ - now);
902 if (remaining_time > 0) {
903 ScheduleMemuseCallback(remaining_time);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700904 } else {
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800905 // Report stats and advance the measurement interval unless there are
906 // errors or we've completed the last interval.
Luigi Semenzato8accd332011-05-17 16:37:18 -0700907 if (MemuseCallbackWork() &&
Luigi Semenzato0d9a9c92013-12-05 15:55:12 -0800908 memuse_interval_index_ < arraysize(kMemuseIntervals)) {
909 double interval = kMemuseIntervals[memuse_interval_index_++];
910 memuse_final_time_ = now + interval;
911 ScheduleMemuseCallback(interval);
Luigi Semenzato8accd332011-05-17 16:37:18 -0700912 }
913 }
914}
915
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700916bool MetricsDaemon::MemuseCallbackWork() {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700917 string meminfo_raw;
Bertrand SIMONNET675a10c2015-08-25 14:11:43 -0700918 const FilePath meminfo_path(kMeminfoFileName);
Ben Chan2e6543d2014-02-05 23:26:25 -0800919 if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700920 LOG(WARNING) << "cannot read " << meminfo_path.value().c_str();
921 return false;
922 }
923 return ProcessMemuse(meminfo_raw);
924}
925
Luigi Semenzato5bd764f2011-10-14 12:03:35 -0700926bool MetricsDaemon::ProcessMemuse(const string& meminfo_raw) {
Luigi Semenzato8accd332011-05-17 16:37:18 -0700927 static const MeminfoRecord fields_array[] = {
928 { "MemTotal", "MemTotal" }, // SPECIAL CASE: total system memory
929 { "ActiveAnon", "Active(anon)" },
930 { "InactiveAnon", "Inactive(anon)" },
931 };
932 vector<MeminfoRecord> fields(fields_array,
933 fields_array + arraysize(fields_array));
934 if (!FillMeminfo(meminfo_raw, &fields)) {
935 return false;
936 }
937 int total = fields[0].value;
938 int active_anon = fields[1].value;
939 int inactive_anon = fields[2].value;
940 if (total == 0) {
941 // this "cannot happen"
942 LOG(WARNING) << "borked meminfo parser";
943 return false;
944 }
Luigi Semenzato859b3f02014-02-05 15:33:19 -0800945 string metrics_name = base::StringPrintf("Platform.MemuseAnon%d",
946 memuse_interval_index_);
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800947 SendLinearSample(metrics_name, (active_anon + inactive_anon) * 100 / total,
Luigi Semenzato8accd332011-05-17 16:37:18 -0700948 100, 101);
949 return true;
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700950}
951
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800952void MetricsDaemon::SendSample(const string& name, int sample,
Darin Petkov11b8eb32010-05-18 11:00:59 -0700953 int min, int max, int nbuckets) {
Darin Petkovfc91b422010-05-12 13:05:45 -0700954 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets);
Darin Petkov65b01462010-04-14 13:32:20 -0700955}
Luigi Semenzato29c7ef92011-04-12 14:12:35 -0700956
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700957void MetricsDaemon::SendKernelCrashesCumulativeCountStats() {
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800958 // Report the number of crashes for this OS version, but don't clear the
959 // counter. It is cleared elsewhere on version change.
Ben Chanf05ab402014-08-07 00:54:59 -0700960 int64_t crashes_count = kernel_crashes_version_count_->Get();
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -0800961 SendSample(kernel_crashes_version_count_->Name(),
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700962 crashes_count,
963 1, // value of first bucket
964 500, // value of last bucket
965 100); // number of buckets
966
967
Ben Chanf05ab402014-08-07 00:54:59 -0700968 int64_t cpu_use_ms = version_cumulative_cpu_use_->Get();
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700969 SendSample(version_cumulative_cpu_use_->Name(),
970 cpu_use_ms / 1000, // stat is in seconds
971 1, // device may be used very little...
972 8 * 1000 * 1000, // ... or a lot (a little over 90 days)
973 100);
974
975 // On the first run after an autoupdate, cpu_use_ms and active_use_seconds
976 // can be zero. Avoid division by zero.
977 if (cpu_use_ms > 0) {
978 // Send the crash frequency since update in number of crashes per CPU year.
979 SendSample("Logging.KernelCrashesPerCpuYear",
980 crashes_count * kSecondsPerDay * 365 * 1000 / cpu_use_ms,
981 1,
982 1000 * 1000, // about one crash every 30s of CPU time
983 100);
984 }
985
Ben Chanf05ab402014-08-07 00:54:59 -0700986 int64_t active_use_seconds = version_cumulative_active_use_->Get();
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700987 if (active_use_seconds > 0) {
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -0700988 SendSample(version_cumulative_active_use_->Name(),
989 active_use_seconds / 1000, // stat is in seconds
990 1, // device may be used very little...
991 8 * 1000 * 1000, // ... or a lot (about 90 days)
992 100);
Luigi Semenzatoba0c65d2014-03-17 12:28:38 -0700993 // Same as above, but per year of active time.
994 SendSample("Logging.KernelCrashesPerActiveYear",
995 crashes_count * kSecondsPerDay * 365 / active_use_seconds,
996 1,
997 1000 * 1000, // about one crash every 30s of active time
998 100);
999 }
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -08001000}
1001
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001002void MetricsDaemon::SendDailyUseSample(
1003 const scoped_ptr<PersistentInteger>& use) {
1004 SendSample(use->Name(),
1005 use->GetAndClear(),
1006 1, // value of first bucket
1007 kSecondsPerDay, // value of last bucket
1008 50); // number of buckets
1009}
1010
Luigi Semenzato2fd51cc2014-02-26 11:53:16 -08001011void MetricsDaemon::SendCrashIntervalSample(
1012 const scoped_ptr<PersistentInteger>& interval) {
1013 SendSample(interval->Name(),
1014 interval->GetAndClear(),
1015 1, // value of first bucket
1016 4 * kSecondsPerWeek, // value of last bucket
1017 50); // number of buckets
1018}
1019
1020void MetricsDaemon::SendCrashFrequencySample(
1021 const scoped_ptr<PersistentInteger>& frequency) {
1022 SendSample(frequency->Name(),
1023 frequency->GetAndClear(),
1024 1, // value of first bucket
1025 100, // value of last bucket
1026 50); // number of buckets
1027}
1028
1029void MetricsDaemon::SendLinearSample(const string& name, int sample,
Luigi Semenzato29c7ef92011-04-12 14:12:35 -07001030 int max, int nbuckets) {
Luigi Semenzato29c7ef92011-04-12 14:12:35 -07001031 // TODO(semenzato): add a proper linear histogram to the Chrome external
1032 // metrics API.
1033 LOG_IF(FATAL, nbuckets != max + 1) << "unsupported histogram scale";
1034 metrics_lib_->SendEnumToUMA(name, sample, max);
1035}
Daniel Eratc83975a2014-04-04 08:53:44 -07001036
1037void MetricsDaemon::UpdateStats(TimeTicks now_ticks,
1038 Time now_wall_time) {
1039 const int elapsed_seconds = (now_ticks - last_update_stats_time_).InSeconds();
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001040 daily_active_use_->Add(elapsed_seconds);
1041 version_cumulative_active_use_->Add(elapsed_seconds);
Daniel Eratc83975a2014-04-04 08:53:44 -07001042 user_crash_interval_->Add(elapsed_seconds);
1043 kernel_crash_interval_->Add(elapsed_seconds);
1044 version_cumulative_cpu_use_->Add(GetIncrementalCpuUse().InMilliseconds());
1045 last_update_stats_time_ = now_ticks;
1046
1047 const TimeDelta since_epoch = now_wall_time - Time::UnixEpoch();
1048 const int day = since_epoch.InDays();
1049 const int week = day / 7;
1050
1051 if (daily_cycle_->Get() != day) {
1052 daily_cycle_->Set(day);
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001053 SendDailyUseSample(daily_active_use_);
1054 SendDailyUseSample(version_cumulative_active_use_);
Daniel Eratc83975a2014-04-04 08:53:44 -07001055 SendCrashFrequencySample(any_crashes_daily_count_);
1056 SendCrashFrequencySample(user_crashes_daily_count_);
1057 SendCrashFrequencySample(kernel_crashes_daily_count_);
1058 SendCrashFrequencySample(unclean_shutdowns_daily_count_);
Luigi Semenzatoe5883fa2014-04-18 17:00:35 -07001059 SendKernelCrashesCumulativeCountStats();
Daniel Eratc83975a2014-04-04 08:53:44 -07001060 }
1061
1062 if (weekly_cycle_->Get() != week) {
1063 weekly_cycle_->Set(week);
1064 SendCrashFrequencySample(any_crashes_weekly_count_);
1065 SendCrashFrequencySample(user_crashes_weekly_count_);
1066 SendCrashFrequencySample(kernel_crashes_weekly_count_);
1067 SendCrashFrequencySample(unclean_shutdowns_weekly_count_);
1068 }
1069}
1070
Steve Funge86591e2014-12-01 13:38:21 -08001071void MetricsDaemon::HandleUpdateStatsTimeout() {
1072 UpdateStats(TimeTicks::Now(), Time::Now());
1073 base::MessageLoop::current()->PostDelayedTask(FROM_HERE,
1074 base::Bind(&MetricsDaemon::HandleUpdateStatsTimeout,
1075 base::Unretained(this)),
1076 base::TimeDelta::FromMilliseconds(kUpdateStatsIntervalMs));
Daniel Eratc83975a2014-04-04 08:53:44 -07001077}