Darin Petkov | 8032dd0 | 2011-05-09 16:33:19 -0700 | [diff] [blame] | 1 | // Copyright (c) 2011 The Chromium OS Authors. All rights reserved. |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "metrics_daemon.h" |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 6 | |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 7 | #include <fcntl.h> |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 8 | #include <math.h> |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 9 | #include <string.h> |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 10 | #include <time.h> |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 11 | |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 12 | #include <base/at_exit.h> |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 13 | #include <base/file_util.h> |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 14 | #include <base/files/file_path.h> |
| 15 | #include <base/hash.h> |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 16 | #include <base/logging.h> |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 17 | #include <base/strings/string_number_conversions.h> |
| 18 | #include <base/strings/string_split.h> |
| 19 | #include <base/strings/string_util.h> |
| 20 | #include <base/strings/stringprintf.h> |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 21 | #include <base/sys_info.h> |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 22 | #include <chromeos/dbus/service_constants.h> |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 23 | #include <dbus/dbus-glib-lowlevel.h> |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 24 | |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 25 | #include "counter.h" |
| 26 | |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 27 | using base::FilePath; |
| 28 | using base::StringPrintf; |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 29 | using base::Time; |
| 30 | using base::TimeDelta; |
| 31 | using base::TimeTicks; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 32 | using std::map; |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 33 | using std::string; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 34 | using std::vector; |
| 35 | |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 36 | |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 37 | #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error") |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 38 | |
| 39 | static const char kCrashReporterInterface[] = "org.chromium.CrashReporter"; |
| 40 | static const char kCrashReporterUserCrashSignal[] = "UserCrash"; |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 41 | |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 42 | static const int kSecondsPerMinute = 60; |
| 43 | static const int kMinutesPerHour = 60; |
| 44 | static const int kHoursPerDay = 24; |
| 45 | static const int kMinutesPerDay = kHoursPerDay * kMinutesPerHour; |
Darin Petkov | 1bb904e | 2010-06-16 15:58:06 -0700 | [diff] [blame] | 46 | static const int kSecondsPerDay = kSecondsPerMinute * kMinutesPerDay; |
| 47 | static const int kDaysPerWeek = 7; |
| 48 | static const int kSecondsPerWeek = kSecondsPerDay * kDaysPerWeek; |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 49 | |
| 50 | // The daily use monitor is scheduled to a 1-minute interval after |
| 51 | // initial user activity and then it's exponentially backed off to |
| 52 | // 10-minute intervals. Although not required, the back off is |
| 53 | // implemented because the histogram buckets are spaced exponentially |
| 54 | // anyway and to avoid too frequent metrics daemon process wake-ups |
| 55 | // and file I/O. |
| 56 | static const int kUseMonitorIntervalInit = 1 * kSecondsPerMinute; |
| 57 | static const int kUseMonitorIntervalMax = 10 * kSecondsPerMinute; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 58 | |
Luigi Semenzato | c5a9234 | 2014-02-14 15:05:51 -0800 | [diff] [blame] | 59 | const char kKernelCrashDetectedFile[] = "/var/run/kernel-crash-detected"; |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 60 | static const char kUncleanShutdownDetectedFile[] = |
Luigi Semenzato | c5a9234 | 2014-02-14 15:05:51 -0800 | [diff] [blame] | 61 | "/var/run/unclean-shutdown-detected"; |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 62 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 63 | // static metrics parameters |
Darin Petkov | 2ccef01 | 2010-05-05 16:06:37 -0700 | [diff] [blame] | 64 | const char MetricsDaemon::kMetricDailyUseTimeName[] = |
| 65 | "Logging.DailyUseTime"; |
| 66 | const int MetricsDaemon::kMetricDailyUseTimeMin = 1; |
| 67 | const int MetricsDaemon::kMetricDailyUseTimeMax = kMinutesPerDay; |
| 68 | const int MetricsDaemon::kMetricDailyUseTimeBuckets = 50; |
| 69 | |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 70 | // crash interval metrics |
| 71 | const char MetricsDaemon::kMetricKernelCrashIntervalName[] = |
| 72 | "Logging.KernelCrashInterval"; |
| 73 | const char MetricsDaemon::kMetricUncleanShutdownIntervalName[] = |
| 74 | "Logging.UncleanShutdownInterval"; |
Darin Petkov | 1bb904e | 2010-06-16 15:58:06 -0700 | [diff] [blame] | 75 | const char MetricsDaemon::kMetricUserCrashIntervalName[] = |
| 76 | "Logging.UserCrashInterval"; |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 77 | |
| 78 | const int MetricsDaemon::kMetricCrashIntervalMin = 1; |
| 79 | const int MetricsDaemon::kMetricCrashIntervalMax = |
| 80 | 4 * kSecondsPerWeek; |
| 81 | const int MetricsDaemon::kMetricCrashIntervalBuckets = 50; |
| 82 | |
| 83 | // crash frequency metrics |
| 84 | const char MetricsDaemon::kMetricAnyCrashesDailyName[] = |
| 85 | "Logging.AnyCrashesDaily"; |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 86 | const char MetricsDaemon::kMetricAnyCrashesWeeklyName[] = |
| 87 | "Logging.AnyCrashesWeekly"; |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 88 | const char MetricsDaemon::kMetricKernelCrashesDailyName[] = |
| 89 | "Logging.KernelCrashesDaily"; |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 90 | const char MetricsDaemon::kMetricKernelCrashesWeeklyName[] = |
| 91 | "Logging.KernelCrashesWeekly"; |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 92 | const char MetricsDaemon::kMetricKernelCrashesVersionName[] = |
| 93 | "Logging.KernelCrashesSinceUpdate"; |
| 94 | const int MetricsDaemon::kMetricCumulativeCrashCountMin = 1; |
| 95 | const int MetricsDaemon::kMetricCumulativeCrashCountMax = 500; |
| 96 | const int MetricsDaemon::kMetricCumulativeCrashCountBuckets = 100; |
| 97 | |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 98 | const char MetricsDaemon::kMetricUncleanShutdownsDailyName[] = |
| 99 | "Logging.UncleanShutdownsDaily"; |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 100 | const char MetricsDaemon::kMetricUncleanShutdownsWeeklyName[] = |
| 101 | "Logging.UncleanShutdownsWeekly"; |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 102 | const char MetricsDaemon::kMetricUserCrashesDailyName[] = |
| 103 | "Logging.UserCrashesDaily"; |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 104 | const char MetricsDaemon::kMetricUserCrashesWeeklyName[] = |
| 105 | "Logging.UserCrashesWeekly"; |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 106 | const int MetricsDaemon::kMetricCrashFrequencyMin = 1; |
| 107 | const int MetricsDaemon::kMetricCrashFrequencyMax = 100; |
| 108 | const int MetricsDaemon::kMetricCrashFrequencyBuckets = 50; |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 109 | |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 110 | // disk stats metrics |
| 111 | |
| 112 | // The {Read,Write}Sectors numbers are in sectors/second. |
| 113 | // A sector is usually 512 bytes. |
| 114 | |
| 115 | const char MetricsDaemon::kMetricReadSectorsLongName[] = |
| 116 | "Platform.ReadSectorsLong"; |
| 117 | const char MetricsDaemon::kMetricWriteSectorsLongName[] = |
| 118 | "Platform.WriteSectorsLong"; |
| 119 | const char MetricsDaemon::kMetricReadSectorsShortName[] = |
| 120 | "Platform.ReadSectorsShort"; |
| 121 | const char MetricsDaemon::kMetricWriteSectorsShortName[] = |
| 122 | "Platform.WriteSectorsShort"; |
| 123 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 124 | const int MetricsDaemon::kMetricStatsShortInterval = 1; // seconds |
| 125 | const int MetricsDaemon::kMetricStatsLongInterval = 30; // seconds |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 126 | |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 127 | const int MetricsDaemon::kMetricMeminfoInterval = 30; // seconds |
| 128 | |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 129 | // Assume a max rate of 250Mb/s for reads (worse for writes) and 512 byte |
| 130 | // sectors. |
| 131 | const int MetricsDaemon::kMetricSectorsIOMax = 500000; // sectors/second |
| 132 | const int MetricsDaemon::kMetricSectorsBuckets = 50; // buckets |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 133 | // Page size is 4k, sector size is 0.5k. We're not interested in page fault |
| 134 | // rates that the disk cannot sustain. |
| 135 | const int MetricsDaemon::kMetricPageFaultsMax = kMetricSectorsIOMax / 8; |
| 136 | const int MetricsDaemon::kMetricPageFaultsBuckets = 50; |
| 137 | |
| 138 | // Major page faults, i.e. the ones that require data to be read from disk. |
| 139 | |
| 140 | const char MetricsDaemon::kMetricPageFaultsLongName[] = |
| 141 | "Platform.PageFaultsLong"; |
| 142 | const char MetricsDaemon::kMetricPageFaultsShortName[] = |
| 143 | "Platform.PageFaultsShort"; |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 144 | |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 145 | // Swap in and Swap out |
| 146 | |
| 147 | const char MetricsDaemon::kMetricSwapInLongName[] = |
| 148 | "Platform.SwapInLong"; |
| 149 | const char MetricsDaemon::kMetricSwapInShortName[] = |
| 150 | "Platform.SwapInShort"; |
| 151 | |
| 152 | const char MetricsDaemon::kMetricSwapOutLongName[] = |
| 153 | "Platform.SwapOutLong"; |
| 154 | const char MetricsDaemon::kMetricSwapOutShortName[] = |
| 155 | "Platform.SwapOutShort"; |
| 156 | |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 157 | // Thermal CPU throttling. |
| 158 | |
| 159 | const char MetricsDaemon::kMetricScaledCpuFrequencyName[] = |
| 160 | "Platform.CpuFrequencyThermalScaling"; |
| 161 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 162 | // persistent metrics path |
| 163 | const char MetricsDaemon::kMetricsPath[] = "/var/log/metrics"; |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 164 | |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 165 | // file containing OS version string |
| 166 | const char MetricsDaemon::kLsbReleasePath[] = "/etc/lsb-release"; |
| 167 | |
| 168 | |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 169 | // static |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 170 | const char* MetricsDaemon::kPowerStates_[] = { |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 171 | #define STATE(name, capname) #name, |
| 172 | #include "power_states.h" |
| 173 | }; |
| 174 | |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 175 | // static |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 176 | const char* MetricsDaemon::kSessionStates_[] = { |
| 177 | #define STATE(name, capname) #name, |
| 178 | #include "session_states.h" |
| 179 | }; |
| 180 | |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 181 | // Memory use stats collection intervals. We collect some memory use interval |
| 182 | // at these intervals after boot, and we stop collecting after the last one, |
| 183 | // with the assumption that in most cases the memory use won't change much |
| 184 | // after that. |
| 185 | static const int kMemuseIntervals[] = { |
| 186 | 1 * kSecondsPerMinute, // 1 minute mark |
| 187 | 4 * kSecondsPerMinute, // 5 minute mark |
| 188 | 25 * kSecondsPerMinute, // 0.5 hour mark |
| 189 | 120 * kSecondsPerMinute, // 2.5 hour mark |
| 190 | 600 * kSecondsPerMinute, // 12.5 hour mark |
| 191 | }; |
| 192 | |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 193 | MetricsDaemon::MetricsDaemon() |
Sam Leffler | 239b826 | 2010-08-30 08:56:58 -0700 | [diff] [blame] | 194 | : power_state_(kUnknownPowerState), |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 195 | session_state_(kUnknownSessionState), |
| 196 | user_active_(false), |
| 197 | usemon_interval_(0), |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 198 | usemon_source_(NULL), |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 199 | memuse_final_time_(0), |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 200 | memuse_interval_index_(0), |
| 201 | read_sectors_(0), |
| 202 | write_sectors_(0), |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 203 | vmstats_(), |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 204 | stats_state_(kStatsShort), |
| 205 | stats_initial_time_(0) {} |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 206 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 207 | MetricsDaemon::~MetricsDaemon() { |
| 208 | DeleteFrequencyCounters(); |
| 209 | } |
| 210 | |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 211 | double MetricsDaemon::GetActiveTime() { |
| 212 | struct timespec ts; |
| 213 | int r = clock_gettime(CLOCK_MONOTONIC, &ts); |
| 214 | if (r < 0) { |
| 215 | PLOG(WARNING) << "clock_gettime(CLOCK_MONOTONIC) failed"; |
| 216 | return 0; |
| 217 | } else { |
| 218 | return ts.tv_sec + ((double) ts.tv_nsec) / (1000 * 1000 * 1000); |
| 219 | } |
| 220 | } |
| 221 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 222 | void MetricsDaemon::DeleteFrequencyCounters() { |
| 223 | for (FrequencyCounters::iterator i = frequency_counters_.begin(); |
| 224 | i != frequency_counters_.end(); ++i) { |
| 225 | delete i->second; |
| 226 | i->second = NULL; |
| 227 | } |
| 228 | } |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 229 | |
Darin Petkov | 2ccef01 | 2010-05-05 16:06:37 -0700 | [diff] [blame] | 230 | void MetricsDaemon::Run(bool run_as_daemon) { |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 231 | base::AtExitManager at_exit_manager; |
| 232 | |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 233 | if (run_as_daemon && daemon(0, 0) != 0) |
| 234 | return; |
| 235 | |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 236 | if (CheckSystemCrash(kKernelCrashDetectedFile)) { |
| 237 | ProcessKernelCrash(); |
| 238 | } |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 239 | kernel_crash_version_counter_->FlushOnChange(GetOsVersionHash()); |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 240 | |
| 241 | if (CheckSystemCrash(kUncleanShutdownDetectedFile)) { |
| 242 | ProcessUncleanShutdown(); |
| 243 | } |
| 244 | |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 245 | Loop(); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 248 | FilePath MetricsDaemon::GetHistogramPath(const char* histogram_name) { |
| 249 | return FilePath(kMetricsPath).Append(histogram_name); |
| 250 | } |
| 251 | |
| 252 | void MetricsDaemon::ConfigureCrashIntervalReporter( |
| 253 | const char* histogram_name, |
| 254 | scoped_ptr<chromeos_metrics::TaggedCounterReporter>* reporter) { |
| 255 | reporter->reset(new chromeos_metrics::TaggedCounterReporter()); |
| 256 | FilePath file_path = GetHistogramPath(histogram_name); |
| 257 | (*reporter)->Init(file_path.value().c_str(), |
| 258 | histogram_name, |
| 259 | kMetricCrashIntervalMin, |
| 260 | kMetricCrashIntervalMax, |
| 261 | kMetricCrashIntervalBuckets); |
| 262 | } |
| 263 | |
| 264 | void MetricsDaemon::ConfigureCrashFrequencyReporter( |
| 265 | const char* histogram_name) { |
| 266 | scoped_ptr<chromeos_metrics::TaggedCounterReporter> reporter( |
| 267 | new chromeos_metrics::TaggedCounterReporter()); |
| 268 | FilePath file_path = GetHistogramPath(histogram_name); |
| 269 | reporter->Init(file_path.value().c_str(), |
| 270 | histogram_name, |
| 271 | kMetricCrashFrequencyMin, |
| 272 | kMetricCrashFrequencyMax, |
| 273 | kMetricCrashFrequencyBuckets); |
| 274 | scoped_ptr<chromeos_metrics::FrequencyCounter> new_counter( |
| 275 | new chromeos_metrics::FrequencyCounter()); |
| 276 | time_t cycle_duration = strstr(histogram_name, "Weekly") != NULL ? |
| 277 | chromeos_metrics::kSecondsPerWeek : |
| 278 | chromeos_metrics::kSecondsPerDay; |
| 279 | new_counter->Init( |
| 280 | static_cast<chromeos_metrics::TaggedCounterInterface*>( |
| 281 | reporter.release()), |
| 282 | cycle_duration); |
| 283 | frequency_counters_[histogram_name] = new_counter.release(); |
| 284 | } |
| 285 | |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 286 | void MetricsDaemon::ConfigureCrashVersionReporter( |
| 287 | const char* histogram_name) { |
| 288 | scoped_ptr<chromeos_metrics::TaggedCounterReporter> reporter( |
| 289 | new chromeos_metrics::TaggedCounterReporter()); |
| 290 | FilePath file_path = GetHistogramPath(histogram_name); |
| 291 | reporter->Init(file_path.value().c_str(), |
| 292 | histogram_name, |
| 293 | kMetricCumulativeCrashCountMin, |
| 294 | kMetricCumulativeCrashCountMax, |
| 295 | kMetricCumulativeCrashCountBuckets); |
| 296 | scoped_ptr<chromeos_metrics::VersionCounter> new_counter( |
| 297 | new chromeos_metrics::VersionCounter()); |
| 298 | new_counter->Init( |
| 299 | static_cast<chromeos_metrics::TaggedCounterInterface*>( |
| 300 | reporter.release()), |
| 301 | chromeos_metrics::kSecondsPerDay); |
| 302 | kernel_crash_version_counter_ = new_counter.release(); |
| 303 | } |
| 304 | |
| 305 | uint32 MetricsDaemon::GetOsVersionHash() { |
| 306 | static uint32 cached_version_hash = 0; |
| 307 | static bool version_hash_is_cached = false; |
| 308 | if (version_hash_is_cached) |
| 309 | return cached_version_hash; |
| 310 | version_hash_is_cached = true; |
| 311 | std::string version; |
| 312 | if (base::SysInfo::GetLsbReleaseValue("CHROMEOS_RELEASE_VERSION", &version)) { |
| 313 | cached_version_hash = base::Hash(version); |
| 314 | } else if (testing_) { |
| 315 | cached_version_hash = 42; // return any plausible value for the hash |
| 316 | } else { |
| 317 | LOG(FATAL) << "could not find CHROMEOS_RELEASE_VERSION"; |
| 318 | } |
| 319 | return cached_version_hash; |
| 320 | } |
| 321 | |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 322 | void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib, |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 323 | const string& diskstats_path, |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 324 | const string& vmstats_path, |
| 325 | const string& scaling_max_freq_path, |
| 326 | const string& cpuinfo_max_freq_path |
| 327 | ) { |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 328 | testing_ = testing; |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 329 | DCHECK(metrics_lib != NULL); |
| 330 | metrics_lib_ = metrics_lib; |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 331 | chromeos_metrics::TaggedCounterReporter:: |
| 332 | SetMetricsLibraryInterface(metrics_lib); |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 333 | |
| 334 | static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage"; |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 335 | daily_use_.reset(new chromeos_metrics::TaggedCounter()); |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 336 | daily_use_->Init(kDailyUseRecordFile, &ReportDailyUse, this); |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 337 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 338 | ConfigureCrashIntervalReporter(kMetricKernelCrashIntervalName, |
| 339 | &kernel_crash_interval_); |
| 340 | ConfigureCrashIntervalReporter(kMetricUncleanShutdownIntervalName, |
| 341 | &unclean_shutdown_interval_); |
| 342 | ConfigureCrashIntervalReporter(kMetricUserCrashIntervalName, |
| 343 | &user_crash_interval_); |
Darin Petkov | 2ccef01 | 2010-05-05 16:06:37 -0700 | [diff] [blame] | 344 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 345 | DeleteFrequencyCounters(); |
| 346 | ConfigureCrashFrequencyReporter(kMetricAnyCrashesDailyName); |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 347 | ConfigureCrashFrequencyReporter(kMetricAnyCrashesWeeklyName); |
| 348 | ConfigureCrashFrequencyReporter(kMetricKernelCrashesDailyName); |
| 349 | ConfigureCrashFrequencyReporter(kMetricKernelCrashesWeeklyName); |
| 350 | ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsDailyName); |
| 351 | ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsWeeklyName); |
| 352 | ConfigureCrashFrequencyReporter(kMetricUserCrashesDailyName); |
| 353 | ConfigureCrashFrequencyReporter(kMetricUserCrashesWeeklyName); |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 354 | |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 355 | ConfigureCrashVersionReporter(kMetricKernelCrashesVersionName); |
| 356 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 357 | diskstats_path_ = diskstats_path; |
| 358 | vmstats_path_ = vmstats_path; |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 359 | scaling_max_freq_path_ = scaling_max_freq_path; |
| 360 | cpuinfo_max_freq_path_ = cpuinfo_max_freq_path; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 361 | StatsReporterInit(); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 362 | |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 363 | // Start collecting meminfo stats. |
| 364 | ScheduleMeminfoCallback(kMetricMeminfoInterval); |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 365 | memuse_final_time_ = GetActiveTime() + kMemuseIntervals[0]; |
| 366 | ScheduleMemuseCallback(kMemuseIntervals[0]); |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 367 | |
Darin Petkov | 2ccef01 | 2010-05-05 16:06:37 -0700 | [diff] [blame] | 368 | // Don't setup D-Bus and GLib in test mode. |
| 369 | if (testing) |
| 370 | return; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 371 | |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 372 | g_type_init(); |
Ben Chan | 6f59842 | 2013-06-22 06:29:36 -0700 | [diff] [blame] | 373 | dbus_threads_init_default(); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 374 | |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 375 | DBusError error; |
| 376 | dbus_error_init(&error); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 377 | |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 378 | DBusConnection* connection = dbus_bus_get(DBUS_BUS_SYSTEM, &error); |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 379 | LOG_IF(FATAL, dbus_error_is_set(&error)) << |
| 380 | "No D-Bus connection: " << SAFE_MESSAGE(error); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 381 | |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 382 | dbus_connection_setup_with_g_main(connection, NULL); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 383 | |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 384 | vector<string> matches; |
| 385 | matches.push_back( |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 386 | base::StringPrintf("type='signal',interface='%s',path='/',member='%s'", |
| 387 | kCrashReporterInterface, |
| 388 | kCrashReporterUserCrashSignal)); |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 389 | matches.push_back( |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 390 | base::StringPrintf("type='signal',interface='%s',path='%s',member='%s'", |
| 391 | power_manager::kPowerManagerInterface, |
| 392 | power_manager::kPowerManagerServicePath, |
| 393 | power_manager::kPowerStateChangedSignal)); |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 394 | matches.push_back( |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 395 | base::StringPrintf("type='signal',sender='%s',interface='%s',path='%s'", |
| 396 | login_manager::kSessionManagerServiceName, |
| 397 | login_manager::kSessionManagerInterface, |
| 398 | login_manager::kSessionManagerServicePath)); |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 399 | |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 400 | // Registers D-Bus matches for the signals we would like to catch. |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 401 | for (vector<string>::const_iterator it = matches.begin(); |
| 402 | it != matches.end(); ++it) { |
| 403 | const char* match = it->c_str(); |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 404 | DLOG(INFO) << "adding dbus match: " << match; |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 405 | dbus_bus_add_match(connection, match, &error); |
| 406 | LOG_IF(FATAL, dbus_error_is_set(&error)) << |
| 407 | "unable to add a match: " << SAFE_MESSAGE(error); |
| 408 | } |
| 409 | |
| 410 | // Adds the D-Bus filter routine to be called back whenever one of |
| 411 | // the registered D-Bus matches is successful. The daemon is not |
| 412 | // activated for D-Bus messages that don't match. |
| 413 | CHECK(dbus_connection_add_filter(connection, MessageFilter, this, NULL)); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 414 | } |
| 415 | |
| 416 | void MetricsDaemon::Loop() { |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 417 | GMainLoop* loop = g_main_loop_new(NULL, false); |
| 418 | g_main_loop_run(loop); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 421 | // static |
| 422 | DBusHandlerResult MetricsDaemon::MessageFilter(DBusConnection* connection, |
| 423 | DBusMessage* message, |
| 424 | void* user_data) { |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 425 | Time now = Time::Now(); |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 426 | DLOG(INFO) << "message intercepted @ " << now.ToInternalValue(); |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 427 | |
| 428 | int message_type = dbus_message_get_type(message); |
| 429 | if (message_type != DBUS_MESSAGE_TYPE_SIGNAL) { |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 430 | DLOG(WARNING) << "unexpected message type " << message_type; |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 431 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 432 | } |
| 433 | |
| 434 | // Signal messages always have interfaces. |
| 435 | const char* interface = dbus_message_get_interface(message); |
| 436 | CHECK(interface != NULL); |
| 437 | |
| 438 | MetricsDaemon* daemon = static_cast<MetricsDaemon*>(user_data); |
| 439 | |
| 440 | DBusMessageIter iter; |
| 441 | dbus_message_iter_init(message, &iter); |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 442 | if (strcmp(interface, kCrashReporterInterface) == 0) { |
Darin Petkov | 1bb904e | 2010-06-16 15:58:06 -0700 | [diff] [blame] | 443 | CHECK(strcmp(dbus_message_get_member(message), |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 444 | kCrashReporterUserCrashSignal) == 0); |
Darin Petkov | 1bb904e | 2010-06-16 15:58:06 -0700 | [diff] [blame] | 445 | daemon->ProcessUserCrash(); |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 446 | } else if (strcmp(interface, power_manager::kPowerManagerInterface) == 0) { |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 447 | CHECK(strcmp(dbus_message_get_member(message), |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 448 | power_manager::kPowerStateChangedSignal) == 0); |
David James | 3b3add5 | 2010-06-04 15:01:19 -0700 | [diff] [blame] | 449 | char* state_name; |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 450 | dbus_message_iter_get_basic(&iter, &state_name); |
Darin Petkov | 40f2573 | 2013-04-29 15:07:31 +0200 | [diff] [blame] | 451 | daemon->PowerStateChanged(state_name, now); |
| 452 | } else if (strcmp(interface, login_manager::kSessionManagerInterface) == 0) { |
| 453 | const char* member = dbus_message_get_member(message); |
| 454 | if (strcmp(member, login_manager::kScreenIsLockedSignal) == 0) { |
| 455 | daemon->SetUserActiveState(false, now); |
| 456 | } else if (strcmp(member, login_manager::kScreenIsUnlockedSignal) == 0) { |
| 457 | daemon->SetUserActiveState(true, now); |
| 458 | } else if (strcmp(member, login_manager::kSessionStateChangedSignal) == 0) { |
| 459 | char* state_name; |
| 460 | dbus_message_iter_get_basic(&iter, &state_name); |
| 461 | daemon->SessionStateChanged(state_name, now); |
| 462 | } |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 463 | } else { |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 464 | DLOG(WARNING) << "unexpected interface: " << interface; |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 465 | return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; |
| 466 | } |
| 467 | |
| 468 | return DBUS_HANDLER_RESULT_HANDLED; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 471 | void MetricsDaemon::PowerStateChanged(const char* state_name, Time now) { |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 472 | DLOG(INFO) << "power state: " << state_name; |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 473 | power_state_ = LookupPowerState(state_name); |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 474 | |
| 475 | if (power_state_ != kPowerStateOn) |
| 476 | SetUserActiveState(false, now); |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 477 | } |
| 478 | |
| 479 | MetricsDaemon::PowerState |
| 480 | MetricsDaemon::LookupPowerState(const char* state_name) { |
| 481 | for (int i = 0; i < kNumberPowerStates; i++) { |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 482 | if (strcmp(state_name, kPowerStates_[i]) == 0) { |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 483 | return static_cast<PowerState>(i); |
| 484 | } |
| 485 | } |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 486 | DLOG(WARNING) << "unknown power state: " << state_name; |
Darin Petkov | 703ec97 | 2010-04-27 11:02:18 -0700 | [diff] [blame] | 487 | return kUnknownPowerState; |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 490 | void MetricsDaemon::SessionStateChanged(const char* state_name, Time now) { |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 491 | DLOG(INFO) << "user session state: " << state_name; |
| 492 | session_state_ = LookupSessionState(state_name); |
| 493 | SetUserActiveState(session_state_ == kSessionStateStarted, now); |
| 494 | } |
| 495 | |
| 496 | MetricsDaemon::SessionState |
| 497 | MetricsDaemon::LookupSessionState(const char* state_name) { |
| 498 | for (int i = 0; i < kNumberSessionStates; i++) { |
| 499 | if (strcmp(state_name, kSessionStates_[i]) == 0) { |
| 500 | return static_cast<SessionState>(i); |
| 501 | } |
| 502 | } |
| 503 | DLOG(WARNING) << "unknown user session state: " << state_name; |
| 504 | return kUnknownSessionState; |
| 505 | } |
| 506 | |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 507 | void MetricsDaemon::SetUserActiveState(bool active, Time now) { |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 508 | DLOG(INFO) << "user: " << (active ? "active" : "inactive"); |
| 509 | |
| 510 | // Calculates the seconds of active use since the last update and |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 511 | // the day since Epoch, and logs the usage data. Guards against the |
| 512 | // time jumping back and forth due to the user changing it by |
| 513 | // discarding the new use time. |
| 514 | int seconds = 0; |
| 515 | if (user_active_ && now > user_active_last_) { |
| 516 | TimeDelta since_active = now - user_active_last_; |
| 517 | if (since_active < TimeDelta::FromSeconds( |
| 518 | kUseMonitorIntervalMax + kSecondsPerMinute)) { |
| 519 | seconds = static_cast<int>(since_active.InSeconds()); |
| 520 | } |
| 521 | } |
| 522 | TimeDelta since_epoch = now - Time(); |
| 523 | int day = since_epoch.InDays(); |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 524 | daily_use_->Update(day, seconds, 0); |
| 525 | user_crash_interval_->Update(0, seconds, 0); |
| 526 | kernel_crash_interval_->Update(0, seconds, 0); |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 527 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 528 | // Flush finished cycles of all frequency counters. |
| 529 | for (FrequencyCounters::iterator i = frequency_counters_.begin(); |
| 530 | i != frequency_counters_.end(); ++i) { |
| 531 | i->second->FlushFinishedCycles(); |
| 532 | } |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 533 | // Report count if we're on a new cycle. FlushOnChange can also reset the |
| 534 | // counter, but not when called from here, because any version change has |
| 535 | // already been processed during initialization. |
| 536 | kernel_crash_version_counter_->FlushOnChange(GetOsVersionHash()); |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 537 | |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 538 | // Schedules a use monitor on inactive->active transitions and |
| 539 | // unschedules it on active->inactive transitions. |
| 540 | if (!user_active_ && active) |
| 541 | ScheduleUseMonitor(kUseMonitorIntervalInit, /* backoff */ false); |
| 542 | else if (user_active_ && !active) |
| 543 | UnscheduleUseMonitor(); |
| 544 | |
| 545 | // Remembers the current active state and the time of the last |
| 546 | // activity update. |
| 547 | user_active_ = active; |
| 548 | user_active_last_ = now; |
| 549 | } |
| 550 | |
Darin Petkov | 1bb904e | 2010-06-16 15:58:06 -0700 | [diff] [blame] | 551 | void MetricsDaemon::ProcessUserCrash() { |
| 552 | // Counts the active use time up to now. |
| 553 | SetUserActiveState(user_active_, Time::Now()); |
| 554 | |
| 555 | // Reports the active use time since the last crash and resets it. |
| 556 | user_crash_interval_->Flush(); |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 557 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 558 | frequency_counters_[kMetricUserCrashesDailyName]->Update(1); |
| 559 | frequency_counters_[kMetricUserCrashesWeeklyName]->Update(1); |
| 560 | frequency_counters_[kMetricAnyCrashesDailyName]->Update(1); |
| 561 | frequency_counters_[kMetricAnyCrashesWeeklyName]->Update(1); |
Darin Petkov | 1bb904e | 2010-06-16 15:58:06 -0700 | [diff] [blame] | 562 | } |
| 563 | |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 564 | void MetricsDaemon::ProcessKernelCrash() { |
| 565 | // Counts the active use time up to now. |
| 566 | SetUserActiveState(user_active_, Time::Now()); |
| 567 | |
| 568 | // Reports the active use time since the last crash and resets it. |
| 569 | kernel_crash_interval_->Flush(); |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 570 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 571 | frequency_counters_[kMetricKernelCrashesDailyName]->Update(1); |
| 572 | frequency_counters_[kMetricKernelCrashesWeeklyName]->Update(1); |
| 573 | frequency_counters_[kMetricAnyCrashesDailyName]->Update(1); |
| 574 | frequency_counters_[kMetricAnyCrashesWeeklyName]->Update(1); |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 575 | |
| 576 | kernel_crash_version_counter_->Update(1, GetOsVersionHash()); |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 579 | void MetricsDaemon::ProcessUncleanShutdown() { |
| 580 | // Counts the active use time up to now. |
| 581 | SetUserActiveState(user_active_, Time::Now()); |
| 582 | |
| 583 | // Reports the active use time since the last crash and resets it. |
| 584 | unclean_shutdown_interval_->Flush(); |
| 585 | |
Ken Mixter | 4c5daa4 | 2010-08-26 18:35:06 -0700 | [diff] [blame] | 586 | frequency_counters_[kMetricUncleanShutdownsDailyName]->Update(1); |
| 587 | frequency_counters_[kMetricUncleanShutdownsWeeklyName]->Update(1); |
| 588 | frequency_counters_[kMetricAnyCrashesDailyName]->Update(1); |
| 589 | frequency_counters_[kMetricAnyCrashesWeeklyName]->Update(1); |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 590 | } |
| 591 | |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 592 | bool MetricsDaemon::CheckSystemCrash(const string& crash_file) { |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 593 | FilePath crash_detected(crash_file); |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 594 | if (!base::PathExists(crash_detected)) |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 595 | return false; |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 596 | |
| 597 | // Deletes the crash-detected file so that the daemon doesn't report |
| 598 | // another kernel crash in case it's restarted. |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 599 | base::DeleteFile(crash_detected, false); // not recursive |
Ken Mixter | ccd84c0 | 2010-08-16 19:57:13 -0700 | [diff] [blame] | 600 | return true; |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 601 | } |
| 602 | |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 603 | // static |
| 604 | gboolean MetricsDaemon::UseMonitorStatic(gpointer data) { |
| 605 | return static_cast<MetricsDaemon*>(data)->UseMonitor() ? TRUE : FALSE; |
| 606 | } |
| 607 | |
| 608 | bool MetricsDaemon::UseMonitor() { |
Darin Petkov | f27f036 | 2010-06-04 13:14:19 -0700 | [diff] [blame] | 609 | SetUserActiveState(user_active_, Time::Now()); |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 610 | |
| 611 | // If a new monitor source/instance is scheduled, returns false to |
| 612 | // tell GLib to destroy this monitor source/instance. Returns true |
| 613 | // otherwise to keep calling back this monitor. |
| 614 | return !ScheduleUseMonitor(usemon_interval_ * 2, /* backoff */ true); |
| 615 | } |
| 616 | |
| 617 | bool MetricsDaemon::ScheduleUseMonitor(int interval, bool backoff) |
| 618 | { |
Darin Petkov | 2ccef01 | 2010-05-05 16:06:37 -0700 | [diff] [blame] | 619 | if (testing_) |
| 620 | return false; |
| 621 | |
Darin Petkov | 41e0623 | 2010-05-03 16:45:37 -0700 | [diff] [blame] | 622 | // Caps the interval -- the bigger the interval, the more active use |
| 623 | // time will be potentially dropped on system shutdown. |
| 624 | if (interval > kUseMonitorIntervalMax) |
| 625 | interval = kUseMonitorIntervalMax; |
| 626 | |
| 627 | if (backoff) { |
| 628 | // Back-off mode is used by the use monitor to reschedule itself |
| 629 | // with exponential back-off in time. This mode doesn't create a |
| 630 | // new timeout source if the new interval is the same as the old |
| 631 | // one. Also, if a new timeout source is created, the old one is |
| 632 | // not destroyed explicitly here -- it will be destroyed by GLib |
| 633 | // when the monitor returns FALSE (see UseMonitor and |
| 634 | // UseMonitorStatic). |
| 635 | if (interval == usemon_interval_) |
| 636 | return false; |
| 637 | } else { |
| 638 | UnscheduleUseMonitor(); |
| 639 | } |
| 640 | |
| 641 | // Schedules a new use monitor for |interval| seconds from now. |
| 642 | DLOG(INFO) << "scheduling use monitor in " << interval << " seconds"; |
| 643 | usemon_source_ = g_timeout_source_new_seconds(interval); |
| 644 | g_source_set_callback(usemon_source_, UseMonitorStatic, this, |
| 645 | NULL); // No destroy notification. |
| 646 | g_source_attach(usemon_source_, |
| 647 | NULL); // Default context. |
| 648 | usemon_interval_ = interval; |
| 649 | return true; |
| 650 | } |
| 651 | |
| 652 | void MetricsDaemon::UnscheduleUseMonitor() { |
| 653 | // If there's a use monitor scheduled already, destroys it. |
| 654 | if (usemon_source_ == NULL) |
| 655 | return; |
| 656 | |
| 657 | DLOG(INFO) << "destroying use monitor"; |
| 658 | g_source_destroy(usemon_source_); |
| 659 | usemon_source_ = NULL; |
| 660 | usemon_interval_ = 0; |
| 661 | } |
| 662 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 663 | void MetricsDaemon::StatsReporterInit() { |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 664 | DiskStatsReadStats(&read_sectors_, &write_sectors_); |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 665 | VmStatsReadStats(&vmstats_); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 666 | // The first time around just run the long stat, so we don't delay boot. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 667 | stats_state_ = kStatsLong; |
| 668 | stats_initial_time_ = GetActiveTime(); |
| 669 | if (stats_initial_time_ < 0) { |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 670 | LOG(WARNING) << "not collecting disk stats"; |
| 671 | } else { |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 672 | ScheduleStatsCallback(kMetricStatsLongInterval); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 673 | } |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 674 | } |
| 675 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 676 | void MetricsDaemon::ScheduleStatsCallback(int wait) { |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 677 | if (testing_) { |
| 678 | return; |
| 679 | } |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 680 | g_timeout_add_seconds(wait, StatsCallbackStatic, this); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 681 | } |
| 682 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 683 | bool MetricsDaemon::DiskStatsReadStats(long int* read_sectors, |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 684 | long int* write_sectors) { |
| 685 | int nchars; |
| 686 | int nitems; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 687 | bool success = false; |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 688 | char line[200]; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 689 | if (diskstats_path_.empty()) { |
| 690 | return false; |
| 691 | } |
Luigi Semenzato | 0f132bb | 2011-02-28 11:17:43 -0800 | [diff] [blame] | 692 | int file = HANDLE_EINTR(open(diskstats_path_.c_str(), O_RDONLY)); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 693 | if (file < 0) { |
| 694 | PLOG(WARNING) << "cannot open " << diskstats_path_; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 695 | return false; |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 696 | } |
| 697 | nchars = HANDLE_EINTR(read(file, line, sizeof(line))); |
| 698 | if (nchars < 0) { |
| 699 | PLOG(WARNING) << "cannot read from " << diskstats_path_; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 700 | return false; |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 701 | } else { |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 702 | LOG_IF(WARNING, nchars == sizeof(line)) |
| 703 | << "line too long in " << diskstats_path_; |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 704 | line[nchars] = '\0'; |
| 705 | nitems = sscanf(line, "%*d %*d %ld %*d %*d %*d %ld", |
| 706 | read_sectors, write_sectors); |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 707 | if (nitems == 2) { |
| 708 | success = true; |
| 709 | } else { |
| 710 | LOG(WARNING) << "found " << nitems << " items in " |
| 711 | << diskstats_path_ << ", expected 2"; |
| 712 | } |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 713 | } |
| 714 | HANDLE_EINTR(close(file)); |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 715 | return success; |
| 716 | } |
| 717 | |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 718 | bool MetricsDaemon::VmStatsParseStats(const char* stats, |
| 719 | struct VmstatRecord* record) { |
| 720 | // a mapping of string name to field in VmstatRecord and whether we found it |
| 721 | struct mapping { |
| 722 | const string name; |
| 723 | uint64_t* value_p; |
| 724 | bool found; |
| 725 | } map[] = |
| 726 | { { .name = "pgmajfault", |
| 727 | .value_p = &record->page_faults_, |
| 728 | .found = false }, |
| 729 | { .name = "pswpin", |
| 730 | .value_p = &record->swap_in_, |
| 731 | .found = false }, |
| 732 | { .name = "pswpout", |
| 733 | .value_p = &record->swap_out_, |
| 734 | .found = false }, }; |
| 735 | |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 736 | // Each line in the file has the form |
| 737 | // <ID> <VALUE> |
| 738 | // for instance: |
| 739 | // nr_free_pages 213427 |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 740 | vector<string> lines; |
| 741 | Tokenize(stats, "\n", &lines); |
| 742 | for (vector<string>::iterator it = lines.begin(); |
| 743 | it != lines.end(); ++it) { |
| 744 | vector<string> tokens; |
| 745 | base::SplitString(*it, ' ', &tokens); |
| 746 | if (tokens.size() == 2) { |
| 747 | for (unsigned int i = 0; i < sizeof(map)/sizeof(struct mapping); i++) { |
| 748 | if (!tokens[0].compare(map[i].name)) { |
| 749 | if (!base::StringToUint64(tokens[1], map[i].value_p)) |
| 750 | return false; |
| 751 | map[i].found = true; |
| 752 | } |
| 753 | } |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 754 | } else { |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 755 | LOG(WARNING) << "unexpected vmstat format"; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 756 | } |
| 757 | } |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 758 | // make sure we got all the stats |
| 759 | for (unsigned i = 0; i < sizeof(map)/sizeof(struct mapping); i++) { |
| 760 | if (map[i].found == false) { |
| 761 | LOG(WARNING) << "vmstat missing " << map[i].name; |
| 762 | return false; |
| 763 | } |
| 764 | } |
| 765 | return true; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 766 | } |
| 767 | |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 768 | bool MetricsDaemon::VmStatsReadStats(struct VmstatRecord* stats) { |
| 769 | string value_string; |
| 770 | FilePath* path = new FilePath(vmstats_path_); |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 771 | if (!base::ReadFileToString(*path, &value_string)) { |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 772 | delete path; |
| 773 | LOG(WARNING) << "cannot read " << vmstats_path_; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 774 | return false; |
| 775 | } |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 776 | delete path; |
| 777 | return VmStatsParseStats(value_string.c_str(), stats); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 778 | } |
| 779 | |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 780 | bool MetricsDaemon::ReadFreqToInt(const string& sysfs_file_name, int* value) { |
Luigi Semenzato | d92d18c | 2013-06-04 13:24:21 -0700 | [diff] [blame] | 781 | const FilePath sysfs_path(sysfs_file_name); |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 782 | string value_string; |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 783 | if (!base::ReadFileToString(sysfs_path, &value_string)) { |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 784 | LOG(WARNING) << "cannot read " << sysfs_path.value().c_str(); |
| 785 | return false; |
| 786 | } |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 787 | if (!base::RemoveChars(value_string, "\n", &value_string)) { |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 788 | LOG(WARNING) << "no newline in " << value_string; |
| 789 | // Continue even though the lack of newline is suspicious. |
| 790 | } |
| 791 | if (!base::StringToInt(value_string, value)) { |
| 792 | LOG(WARNING) << "cannot convert " << value_string << " to int"; |
| 793 | return false; |
| 794 | } |
| 795 | return true; |
| 796 | } |
| 797 | |
| 798 | void MetricsDaemon::SendCpuThrottleMetrics() { |
| 799 | // |max_freq| is 0 only the first time through. |
| 800 | static int max_freq = 0; |
| 801 | if (max_freq == -1) |
| 802 | // Give up, as sysfs did not report max_freq correctly. |
| 803 | return; |
| 804 | if (max_freq == 0 || testing_) { |
| 805 | // One-time initialization of max_freq. (Every time when testing.) |
| 806 | if (!ReadFreqToInt(cpuinfo_max_freq_path_, &max_freq)) { |
| 807 | max_freq = -1; |
| 808 | return; |
| 809 | } |
| 810 | if (max_freq == 0) { |
| 811 | LOG(WARNING) << "sysfs reports 0 max CPU frequency\n"; |
| 812 | max_freq = -1; |
| 813 | return; |
| 814 | } |
| 815 | if (max_freq % 10000 == 1000) { |
| 816 | // Special case: system has turbo mode, and max non-turbo frequency is |
| 817 | // max_freq - 1000. This relies on "normal" (non-turbo) frequencies |
| 818 | // being multiples of (at least) 10 MHz. Although there is no guarantee |
| 819 | // of this, it seems a fairly reasonable assumption. Otherwise we should |
| 820 | // read scaling_available_frequencies, sort the frequencies, compare the |
| 821 | // two highest ones, and check if they differ by 1000 (kHz) (and that's a |
| 822 | // hack too, no telling when it will change). |
| 823 | max_freq -= 1000; |
| 824 | } |
| 825 | } |
| 826 | int scaled_freq = 0; |
| 827 | if (!ReadFreqToInt(scaling_max_freq_path_, &scaled_freq)) |
| 828 | return; |
| 829 | // Frequencies are in kHz. If scaled_freq > max_freq, turbo is on, but |
| 830 | // scaled_freq is not the actual turbo frequency. We indicate this situation |
| 831 | // with a 101% value. |
| 832 | int percent = scaled_freq > max_freq ? 101 : scaled_freq / (max_freq / 100); |
| 833 | SendLinearMetric(kMetricScaledCpuFrequencyName, percent, 101, 102); |
| 834 | } |
| 835 | |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 836 | // static |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 837 | gboolean MetricsDaemon::StatsCallbackStatic(void* handle) { |
| 838 | (static_cast<MetricsDaemon*>(handle))->StatsCallback(); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 839 | return false; // one-time callback |
| 840 | } |
| 841 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 842 | // Collects disk and vm stats alternating over a short and a long interval. |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 843 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 844 | void MetricsDaemon::StatsCallback() { |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 845 | long int read_sectors_now, write_sectors_now; |
| 846 | struct VmstatRecord vmstats_now; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 847 | double time_now = GetActiveTime(); |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 848 | double delta_time = time_now - stats_initial_time_; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 849 | if (testing_) { |
| 850 | // Fake the time when testing. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 851 | delta_time = stats_state_ == kStatsShort ? |
| 852 | kMetricStatsShortInterval : kMetricStatsLongInterval; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 853 | } |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 854 | bool diskstats_success = DiskStatsReadStats(&read_sectors_now, |
| 855 | &write_sectors_now); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 856 | int delta_read = read_sectors_now - read_sectors_; |
| 857 | int delta_write = write_sectors_now - write_sectors_; |
| 858 | int read_sectors_per_second = delta_read / delta_time; |
| 859 | int write_sectors_per_second = delta_write / delta_time; |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 860 | bool vmstats_success = VmStatsReadStats(&vmstats_now); |
| 861 | uint64_t delta_faults = vmstats_now.page_faults_ - vmstats_.page_faults_; |
| 862 | uint64_t delta_swap_in = vmstats_now.swap_in_ - vmstats_.swap_in_; |
| 863 | uint64_t delta_swap_out = vmstats_now.swap_out_ - vmstats_.swap_out_; |
| 864 | uint64_t page_faults_per_second = delta_faults / delta_time; |
| 865 | uint64_t swap_in_per_second = delta_swap_in / delta_time; |
| 866 | uint64_t swap_out_per_second = delta_swap_out / delta_time; |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 867 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 868 | switch (stats_state_) { |
| 869 | case kStatsShort: |
| 870 | if (diskstats_success) { |
| 871 | SendMetric(kMetricReadSectorsShortName, |
| 872 | read_sectors_per_second, |
| 873 | 1, |
| 874 | kMetricSectorsIOMax, |
| 875 | kMetricSectorsBuckets); |
| 876 | SendMetric(kMetricWriteSectorsShortName, |
| 877 | write_sectors_per_second, |
| 878 | 1, |
| 879 | kMetricSectorsIOMax, |
| 880 | kMetricSectorsBuckets); |
| 881 | } |
| 882 | if (vmstats_success) { |
| 883 | SendMetric(kMetricPageFaultsShortName, |
| 884 | page_faults_per_second, |
| 885 | 1, |
| 886 | kMetricPageFaultsMax, |
| 887 | kMetricPageFaultsBuckets); |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 888 | SendMetric(kMetricSwapInShortName, |
| 889 | swap_in_per_second, |
| 890 | 1, |
| 891 | kMetricPageFaultsMax, |
| 892 | kMetricPageFaultsBuckets); |
| 893 | SendMetric(kMetricSwapOutShortName, |
| 894 | swap_out_per_second, |
| 895 | 1, |
| 896 | kMetricPageFaultsMax, |
| 897 | kMetricPageFaultsBuckets); |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 898 | } |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 899 | // Schedule long callback. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 900 | stats_state_ = kStatsLong; |
| 901 | ScheduleStatsCallback(kMetricStatsLongInterval - |
| 902 | kMetricStatsShortInterval); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 903 | break; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 904 | case kStatsLong: |
| 905 | if (diskstats_success) { |
| 906 | SendMetric(kMetricReadSectorsLongName, |
| 907 | read_sectors_per_second, |
| 908 | 1, |
| 909 | kMetricSectorsIOMax, |
| 910 | kMetricSectorsBuckets); |
| 911 | SendMetric(kMetricWriteSectorsLongName, |
| 912 | write_sectors_per_second, |
| 913 | 1, |
| 914 | kMetricSectorsIOMax, |
| 915 | kMetricSectorsBuckets); |
| 916 | // Reset sector counters. |
| 917 | read_sectors_ = read_sectors_now; |
| 918 | write_sectors_ = write_sectors_now; |
| 919 | } |
| 920 | if (vmstats_success) { |
| 921 | SendMetric(kMetricPageFaultsLongName, |
| 922 | page_faults_per_second, |
| 923 | 1, |
| 924 | kMetricPageFaultsMax, |
| 925 | kMetricPageFaultsBuckets); |
Sonny Rao | 4b8aebb | 2013-07-31 23:18:31 -0700 | [diff] [blame] | 926 | SendMetric(kMetricSwapInLongName, |
| 927 | swap_in_per_second, |
| 928 | 1, |
| 929 | kMetricPageFaultsMax, |
| 930 | kMetricPageFaultsBuckets); |
| 931 | SendMetric(kMetricSwapOutLongName, |
| 932 | swap_out_per_second, |
| 933 | 1, |
| 934 | kMetricPageFaultsMax, |
| 935 | kMetricPageFaultsBuckets); |
| 936 | |
| 937 | vmstats_ = vmstats_now; |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 938 | } |
Luigi Semenzato | fb3a821 | 2013-05-07 16:55:00 -0700 | [diff] [blame] | 939 | SendCpuThrottleMetrics(); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 940 | // Set start time for new cycle. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 941 | stats_initial_time_ = time_now; |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 942 | // Schedule short callback. |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 943 | stats_state_ = kStatsShort; |
| 944 | ScheduleStatsCallback(kMetricStatsShortInterval); |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 945 | break; |
| 946 | default: |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 947 | LOG(FATAL) << "Invalid stats state"; |
Luigi Semenzato | c88e42d | 2011-02-17 10:21:16 -0800 | [diff] [blame] | 948 | } |
| 949 | } |
| 950 | |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 951 | void MetricsDaemon::ScheduleMeminfoCallback(int wait) { |
| 952 | if (testing_) { |
| 953 | return; |
| 954 | } |
| 955 | g_timeout_add_seconds(wait, MeminfoCallbackStatic, this); |
| 956 | } |
| 957 | |
| 958 | // static |
| 959 | gboolean MetricsDaemon::MeminfoCallbackStatic(void* handle) { |
| 960 | return (static_cast<MetricsDaemon*>(handle))->MeminfoCallback(); |
| 961 | } |
| 962 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 963 | bool MetricsDaemon::MeminfoCallback() { |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 964 | string meminfo_raw; |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 965 | const FilePath meminfo_path("/proc/meminfo"); |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 966 | if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) { |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 967 | LOG(WARNING) << "cannot read " << meminfo_path.value().c_str(); |
| 968 | return false; |
| 969 | } |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 970 | return ProcessMeminfo(meminfo_raw); |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 971 | } |
| 972 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 973 | bool MetricsDaemon::ProcessMeminfo(const string& meminfo_raw) { |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 974 | static const MeminfoRecord fields_array[] = { |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 975 | { "MemTotal", "MemTotal" }, // SPECIAL CASE: total system memory |
| 976 | { "MemFree", "MemFree" }, |
| 977 | { "Buffers", "Buffers" }, |
| 978 | { "Cached", "Cached" }, |
| 979 | // { "SwapCached", "SwapCached" }, |
| 980 | { "Active", "Active" }, |
| 981 | { "Inactive", "Inactive" }, |
| 982 | { "ActiveAnon", "Active(anon)" }, |
| 983 | { "InactiveAnon", "Inactive(anon)" }, |
| 984 | { "ActiveFile" , "Active(file)" }, |
| 985 | { "InactiveFile", "Inactive(file)" }, |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 986 | { "Unevictable", "Unevictable", kMeminfoOp_HistLog }, |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 987 | // { "Mlocked", "Mlocked" }, |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 988 | { "SwapTotal", "SwapTotal", kMeminfoOp_SwapTotal }, |
| 989 | { "SwapFree", "SwapFree", kMeminfoOp_SwapFree }, |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 990 | // { "Dirty", "Dirty" }, |
| 991 | // { "Writeback", "Writeback" }, |
| 992 | { "AnonPages", "AnonPages" }, |
| 993 | { "Mapped", "Mapped" }, |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 994 | { "Shmem", "Shmem", kMeminfoOp_HistLog }, |
| 995 | { "Slab", "Slab", kMeminfoOp_HistLog }, |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 996 | // { "SReclaimable", "SReclaimable" }, |
| 997 | // { "SUnreclaim", "SUnreclaim" }, |
| 998 | }; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 999 | vector<MeminfoRecord> fields(fields_array, |
| 1000 | fields_array + arraysize(fields_array)); |
| 1001 | if (!FillMeminfo(meminfo_raw, &fields)) { |
| 1002 | return false; |
| 1003 | } |
| 1004 | int total_memory = fields[0].value; |
| 1005 | if (total_memory == 0) { |
| 1006 | // this "cannot happen" |
| 1007 | LOG(WARNING) << "borked meminfo parser"; |
| 1008 | return false; |
| 1009 | } |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 1010 | int swap_total = 0; |
| 1011 | int swap_free = 0; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1012 | // Send all fields retrieved, except total memory. |
| 1013 | for (unsigned int i = 1; i < fields.size(); i++) { |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 1014 | string metrics_name = base::StringPrintf("Platform.Meminfo%s", |
| 1015 | fields[i].name); |
Luigi Semenzato | 3ccca06 | 2013-02-04 19:50:45 -0800 | [diff] [blame] | 1016 | int percent; |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 1017 | switch (fields[i].op) { |
| 1018 | case kMeminfoOp_HistPercent: |
Luigi Semenzato | 3ccca06 | 2013-02-04 19:50:45 -0800 | [diff] [blame] | 1019 | // report value as percent of total memory |
| 1020 | percent = fields[i].value * 100 / total_memory; |
| 1021 | SendLinearMetric(metrics_name, percent, 100, 101); |
| 1022 | break; |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 1023 | case kMeminfoOp_HistLog: |
Luigi Semenzato | 3ccca06 | 2013-02-04 19:50:45 -0800 | [diff] [blame] | 1024 | // report value in kbytes, log scale, 4Gb max |
| 1025 | SendMetric(metrics_name, fields[i].value, 1, 4 * 1000 * 1000, 100); |
| 1026 | break; |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 1027 | case kMeminfoOp_SwapTotal: |
| 1028 | swap_total = fields[i].value; |
| 1029 | case kMeminfoOp_SwapFree: |
| 1030 | swap_free = fields[i].value; |
Luigi Semenzato | 3ccca06 | 2013-02-04 19:50:45 -0800 | [diff] [blame] | 1031 | break; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1032 | } |
| 1033 | } |
Luigi Semenzato | 942cbab | 2013-02-12 13:17:07 -0800 | [diff] [blame] | 1034 | if (swap_total > 0) { |
| 1035 | int swap_used = swap_total - swap_free; |
| 1036 | int swap_used_percent = swap_used * 100 / swap_total; |
| 1037 | SendMetric("Platform.MeminfoSwapUsed", swap_used, 1, 8 * 1000 * 1000, 100); |
| 1038 | SendLinearMetric("Platform.MeminfoSwapUsedPercent", swap_used_percent, |
| 1039 | 100, 101); |
| 1040 | } |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1041 | return true; |
| 1042 | } |
| 1043 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 1044 | bool MetricsDaemon::FillMeminfo(const string& meminfo_raw, |
| 1045 | vector<MeminfoRecord>* fields) { |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1046 | vector<string> lines; |
| 1047 | unsigned int nlines = Tokenize(meminfo_raw, "\n", &lines); |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 1048 | |
| 1049 | // Scan meminfo output and collect field values. Each field name has to |
| 1050 | // match a meminfo entry (case insensitive) after removing non-alpha |
| 1051 | // characters from the entry. |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1052 | unsigned int ifield = 0; |
| 1053 | for (unsigned int iline = 0; |
| 1054 | iline < nlines && ifield < fields->size(); |
| 1055 | iline++) { |
| 1056 | vector<string> tokens; |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 1057 | Tokenize(lines[iline], ": ", &tokens); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1058 | if (strcmp((*fields)[ifield].match, tokens[0].c_str()) == 0) { |
| 1059 | // Name matches. Parse value and save. |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 1060 | char* rest; |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1061 | (*fields)[ifield].value = |
| 1062 | static_cast<int>(strtol(tokens[1].c_str(), &rest, 10)); |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 1063 | if (*rest != '\0') { |
| 1064 | LOG(WARNING) << "missing meminfo value"; |
| 1065 | return false; |
| 1066 | } |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1067 | ifield++; |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 1068 | } |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 1069 | } |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1070 | if (ifield < fields->size()) { |
| 1071 | // End of input reached while scanning. |
| 1072 | LOG(WARNING) << "cannot find field " << (*fields)[ifield].match |
| 1073 | << " and following"; |
| 1074 | return false; |
| 1075 | } |
| 1076 | return true; |
| 1077 | } |
| 1078 | |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 1079 | void MetricsDaemon::ScheduleMemuseCallback(double interval) { |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1080 | if (testing_) { |
| 1081 | return; |
| 1082 | } |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 1083 | g_timeout_add_seconds(interval, MemuseCallbackStatic, this); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1084 | } |
| 1085 | |
| 1086 | // static |
| 1087 | gboolean MetricsDaemon::MemuseCallbackStatic(void* handle) { |
| 1088 | MetricsDaemon* daemon = static_cast<MetricsDaemon*>(handle); |
| 1089 | daemon->MemuseCallback(); |
| 1090 | return false; |
| 1091 | } |
| 1092 | |
| 1093 | void MetricsDaemon::MemuseCallback() { |
| 1094 | // Since we only care about active time (i.e. uptime minus sleep time) but |
| 1095 | // the callbacks are driven by real time (uptime), we check if we should |
| 1096 | // reschedule this callback due to intervening sleep periods. |
| 1097 | double now = GetActiveTime(); |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 1098 | // Avoid intervals of less than one second. |
| 1099 | double remaining_time = ceil(memuse_final_time_ - now); |
| 1100 | if (remaining_time > 0) { |
| 1101 | ScheduleMemuseCallback(remaining_time); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1102 | } else { |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 1103 | // Report stats and advance the measurement interval unless there are |
| 1104 | // errors or we've completed the last interval. |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1105 | if (MemuseCallbackWork() && |
Luigi Semenzato | 0d9a9c9 | 2013-12-05 15:55:12 -0800 | [diff] [blame] | 1106 | memuse_interval_index_ < arraysize(kMemuseIntervals)) { |
| 1107 | double interval = kMemuseIntervals[memuse_interval_index_++]; |
| 1108 | memuse_final_time_ = now + interval; |
| 1109 | ScheduleMemuseCallback(interval); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1110 | } |
| 1111 | } |
| 1112 | } |
| 1113 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 1114 | bool MetricsDaemon::MemuseCallbackWork() { |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1115 | string meminfo_raw; |
| 1116 | const FilePath meminfo_path("/proc/meminfo"); |
Ben Chan | 2e6543d | 2014-02-05 23:26:25 -0800 | [diff] [blame] | 1117 | if (!base::ReadFileToString(meminfo_path, &meminfo_raw)) { |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1118 | LOG(WARNING) << "cannot read " << meminfo_path.value().c_str(); |
| 1119 | return false; |
| 1120 | } |
| 1121 | return ProcessMemuse(meminfo_raw); |
| 1122 | } |
| 1123 | |
Luigi Semenzato | 5bd764f | 2011-10-14 12:03:35 -0700 | [diff] [blame] | 1124 | bool MetricsDaemon::ProcessMemuse(const string& meminfo_raw) { |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1125 | static const MeminfoRecord fields_array[] = { |
| 1126 | { "MemTotal", "MemTotal" }, // SPECIAL CASE: total system memory |
| 1127 | { "ActiveAnon", "Active(anon)" }, |
| 1128 | { "InactiveAnon", "Inactive(anon)" }, |
| 1129 | }; |
| 1130 | vector<MeminfoRecord> fields(fields_array, |
| 1131 | fields_array + arraysize(fields_array)); |
| 1132 | if (!FillMeminfo(meminfo_raw, &fields)) { |
| 1133 | return false; |
| 1134 | } |
| 1135 | int total = fields[0].value; |
| 1136 | int active_anon = fields[1].value; |
| 1137 | int inactive_anon = fields[2].value; |
| 1138 | if (total == 0) { |
| 1139 | // this "cannot happen" |
| 1140 | LOG(WARNING) << "borked meminfo parser"; |
| 1141 | return false; |
| 1142 | } |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 1143 | string metrics_name = base::StringPrintf("Platform.MemuseAnon%d", |
| 1144 | memuse_interval_index_); |
Luigi Semenzato | 8accd33 | 2011-05-17 16:37:18 -0700 | [diff] [blame] | 1145 | SendLinearMetric(metrics_name, (active_anon + inactive_anon) * 100 / total, |
| 1146 | 100, 101); |
| 1147 | return true; |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 1150 | // static |
Luigi Semenzato | 859b3f0 | 2014-02-05 15:33:19 -0800 | [diff] [blame] | 1151 | void MetricsDaemon::ReportDailyUse(void* handle, int count) { |
Darin Petkov | 1bb904e | 2010-06-16 15:58:06 -0700 | [diff] [blame] | 1152 | if (count <= 0) |
| 1153 | return; |
| 1154 | |
Darin Petkov | f1e85e4 | 2010-06-10 15:59:53 -0700 | [diff] [blame] | 1155 | MetricsDaemon* daemon = static_cast<MetricsDaemon*>(handle); |
| 1156 | int minutes = (count + kSecondsPerMinute / 2) / kSecondsPerMinute; |
| 1157 | daemon->SendMetric(kMetricDailyUseTimeName, minutes, |
| 1158 | kMetricDailyUseTimeMin, |
| 1159 | kMetricDailyUseTimeMax, |
| 1160 | kMetricDailyUseTimeBuckets); |
| 1161 | } |
| 1162 | |
Darin Petkov | 38d5cb0 | 2010-06-24 12:10:26 -0700 | [diff] [blame] | 1163 | void MetricsDaemon::SendMetric(const string& name, int sample, |
Darin Petkov | 11b8eb3 | 2010-05-18 11:00:59 -0700 | [diff] [blame] | 1164 | int min, int max, int nbuckets) { |
Darin Petkov | fc91b42 | 2010-05-12 13:05:45 -0700 | [diff] [blame] | 1165 | DLOG(INFO) << "received metric: " << name << " " << sample << " " |
| 1166 | << min << " " << max << " " << nbuckets; |
| 1167 | metrics_lib_->SendToUMA(name, sample, min, max, nbuckets); |
Darin Petkov | 65b0146 | 2010-04-14 13:32:20 -0700 | [diff] [blame] | 1168 | } |
Luigi Semenzato | 29c7ef9 | 2011-04-12 14:12:35 -0700 | [diff] [blame] | 1169 | |
| 1170 | void MetricsDaemon::SendLinearMetric(const string& name, int sample, |
| 1171 | int max, int nbuckets) { |
| 1172 | DLOG(INFO) << "received linear metric: " << name << " " << sample << " " |
| 1173 | << max << " " << nbuckets; |
| 1174 | // TODO(semenzato): add a proper linear histogram to the Chrome external |
| 1175 | // metrics API. |
| 1176 | LOG_IF(FATAL, nbuckets != max + 1) << "unsupported histogram scale"; |
| 1177 | metrics_lib_->SendEnumToUMA(name, sample, max); |
| 1178 | } |