Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "metrics_daemon.h" | 5 #include "metrics_daemon.h" |
| 6 | 6 |
| 7 #include <fcntl.h> | 7 #include <fcntl.h> |
| 8 #include <string.h> | 8 #include <string.h> |
| 9 | 9 |
| 10 #include <base/file_util.h> | 10 #include <base/file_util.h> |
| (...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 140 #define STATE(name, capname) #name, | 140 #define STATE(name, capname) #name, |
| 141 #include "session_states.h" | 141 #include "session_states.h" |
| 142 }; | 142 }; |
| 143 | 143 |
| 144 MetricsDaemon::MetricsDaemon() | 144 MetricsDaemon::MetricsDaemon() |
| 145 : power_state_(kUnknownPowerState), | 145 : power_state_(kUnknownPowerState), |
| 146 session_state_(kUnknownSessionState), | 146 session_state_(kUnknownSessionState), |
| 147 user_active_(false), | 147 user_active_(false), |
| 148 usemon_interval_(0), | 148 usemon_interval_(0), |
| 149 usemon_source_(NULL), | 149 usemon_source_(NULL), |
| 150 diskstats_path_(NULL) {} | 150 diskstats_path_() {} |
|
petkov
2011/02/26 00:26:46
just remove this one -- implicit construction is O
| |
| 151 | 151 |
| 152 MetricsDaemon::~MetricsDaemon() { | 152 MetricsDaemon::~MetricsDaemon() { |
| 153 DeleteFrequencyCounters(); | 153 DeleteFrequencyCounters(); |
| 154 } | 154 } |
| 155 | 155 |
| 156 void MetricsDaemon::DeleteFrequencyCounters() { | 156 void MetricsDaemon::DeleteFrequencyCounters() { |
| 157 for (FrequencyCounters::iterator i = frequency_counters_.begin(); | 157 for (FrequencyCounters::iterator i = frequency_counters_.begin(); |
| 158 i != frequency_counters_.end(); ++i) { | 158 i != frequency_counters_.end(); ++i) { |
| 159 delete i->second; | 159 delete i->second; |
| 160 i->second = NULL; | 160 i->second = NULL; |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 208 chromeos_metrics::kSecondsPerWeek : | 208 chromeos_metrics::kSecondsPerWeek : |
| 209 chromeos_metrics::kSecondsPerDay; | 209 chromeos_metrics::kSecondsPerDay; |
| 210 new_counter->Init( | 210 new_counter->Init( |
| 211 static_cast<chromeos_metrics::TaggedCounterInterface*>( | 211 static_cast<chromeos_metrics::TaggedCounterInterface*>( |
| 212 reporter.release()), | 212 reporter.release()), |
| 213 cycle_duration); | 213 cycle_duration); |
| 214 frequency_counters_[histogram_name] = new_counter.release(); | 214 frequency_counters_[histogram_name] = new_counter.release(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib, | 217 void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib, |
| 218 const char* diskstats_path) { | 218 string diskstats_path) { |
| 219 testing_ = testing; | 219 testing_ = testing; |
| 220 DCHECK(metrics_lib != NULL); | 220 DCHECK(metrics_lib != NULL); |
| 221 metrics_lib_ = metrics_lib; | 221 metrics_lib_ = metrics_lib; |
| 222 chromeos_metrics::TaggedCounterReporter:: | 222 chromeos_metrics::TaggedCounterReporter:: |
| 223 SetMetricsLibraryInterface(metrics_lib); | 223 SetMetricsLibraryInterface(metrics_lib); |
| 224 | 224 |
| 225 static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage"; | 225 static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage"; |
| 226 daily_use_.reset(new chromeos_metrics::TaggedCounter()); | 226 daily_use_.reset(new chromeos_metrics::TaggedCounter()); |
| 227 daily_use_->Init(kDailyUseRecordFile, &ReportDailyUse, this); | 227 daily_use_->Init(kDailyUseRecordFile, &ReportDailyUse, this); |
| 228 | 228 |
| 229 ConfigureCrashIntervalReporter(kMetricKernelCrashIntervalName, | 229 ConfigureCrashIntervalReporter(kMetricKernelCrashIntervalName, |
| 230 &kernel_crash_interval_); | 230 &kernel_crash_interval_); |
| 231 ConfigureCrashIntervalReporter(kMetricUncleanShutdownIntervalName, | 231 ConfigureCrashIntervalReporter(kMetricUncleanShutdownIntervalName, |
| 232 &unclean_shutdown_interval_); | 232 &unclean_shutdown_interval_); |
| 233 ConfigureCrashIntervalReporter(kMetricUserCrashIntervalName, | 233 ConfigureCrashIntervalReporter(kMetricUserCrashIntervalName, |
| 234 &user_crash_interval_); | 234 &user_crash_interval_); |
| 235 | 235 |
| 236 DeleteFrequencyCounters(); | 236 DeleteFrequencyCounters(); |
| 237 ConfigureCrashFrequencyReporter(kMetricAnyCrashesDailyName); | 237 ConfigureCrashFrequencyReporter(kMetricAnyCrashesDailyName); |
| 238 ConfigureCrashFrequencyReporter(kMetricAnyCrashesWeeklyName); | 238 ConfigureCrashFrequencyReporter(kMetricAnyCrashesWeeklyName); |
| 239 ConfigureCrashFrequencyReporter(kMetricKernelCrashesDailyName); | 239 ConfigureCrashFrequencyReporter(kMetricKernelCrashesDailyName); |
| 240 ConfigureCrashFrequencyReporter(kMetricKernelCrashesWeeklyName); | 240 ConfigureCrashFrequencyReporter(kMetricKernelCrashesWeeklyName); |
| 241 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsDailyName); | 241 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsDailyName); |
| 242 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsWeeklyName); | 242 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsWeeklyName); |
| 243 ConfigureCrashFrequencyReporter(kMetricUserCrashesDailyName); | 243 ConfigureCrashFrequencyReporter(kMetricUserCrashesDailyName); |
| 244 ConfigureCrashFrequencyReporter(kMetricUserCrashesWeeklyName); | 244 ConfigureCrashFrequencyReporter(kMetricUserCrashesWeeklyName); |
| 245 | 245 |
| 246 diskstats_path_ = diskstats_path; | 246 // Don't attempt to collect disk stats if there is no disk stats file. |
| 247 DiskStatsReporterInit(); | 247 if (!diskstats_path.empty()) { |
| 248 diskstats_path_ = diskstats_path; | |
| 249 DiskStatsReporterInit(); | |
| 250 } | |
| 248 | 251 |
| 249 // Don't setup D-Bus and GLib in test mode. | 252 // Don't setup D-Bus and GLib in test mode. |
| 250 if (testing) | 253 if (testing) |
| 251 return; | 254 return; |
| 252 | 255 |
| 253 g_thread_init(NULL); | 256 g_thread_init(NULL); |
| 254 g_type_init(); | 257 g_type_init(); |
| 255 dbus_g_thread_init(); | 258 dbus_g_thread_init(); |
| 256 | 259 |
| 257 DBusError error; | 260 DBusError error; |
| (...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 534 return; | 537 return; |
| 535 } | 538 } |
| 536 g_timeout_add_seconds(wait, DiskStatsCallbackStatic, this); | 539 g_timeout_add_seconds(wait, DiskStatsCallbackStatic, this); |
| 537 } | 540 } |
| 538 | 541 |
| 539 void MetricsDaemon::DiskStatsReadStats(long int* read_sectors, | 542 void MetricsDaemon::DiskStatsReadStats(long int* read_sectors, |
| 540 long int* write_sectors) { | 543 long int* write_sectors) { |
| 541 int nchars; | 544 int nchars; |
| 542 int nitems; | 545 int nitems; |
| 543 char line[200]; | 546 char line[200]; |
| 544 int file = HANDLE_EINTR(open(diskstats_path_, O_RDONLY)); | 547 int file = HANDLE_EINTR(open(diskstats_path_.c_str(), O_RDONLY)); |
| 545 if (file < 0) { | 548 if (file < 0) { |
| 546 PLOG(WARNING) << "cannot open " << diskstats_path_; | 549 PLOG(WARNING) << "cannot open " << diskstats_path_; |
| 547 return; | 550 return; |
| 548 } | 551 } |
| 549 nchars = HANDLE_EINTR(read(file, line, sizeof(line))); | 552 nchars = HANDLE_EINTR(read(file, line, sizeof(line))); |
| 550 if (nchars < 0) { | 553 if (nchars < 0) { |
| 551 PLOG(WARNING) << "cannot read from " << diskstats_path_; | 554 PLOG(WARNING) << "cannot read from " << diskstats_path_; |
| 552 } else { | 555 } else { |
| 553 LOG_IF(WARNING, nchars == sizeof(line)) << "line too long in " | 556 LOG_IF(WARNING, nchars == sizeof(line)) << "line too long in " |
| 554 << diskstats_path_; | 557 << diskstats_path_; |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 627 kMetricDailyUseTimeMax, | 630 kMetricDailyUseTimeMax, |
| 628 kMetricDailyUseTimeBuckets); | 631 kMetricDailyUseTimeBuckets); |
| 629 } | 632 } |
| 630 | 633 |
| 631 void MetricsDaemon::SendMetric(const string& name, int sample, | 634 void MetricsDaemon::SendMetric(const string& name, int sample, |
| 632 int min, int max, int nbuckets) { | 635 int min, int max, int nbuckets) { |
| 633 DLOG(INFO) << "received metric: " << name << " " << sample << " " | 636 DLOG(INFO) << "received metric: " << name << " " << sample << " " |
| 634 << min << " " << max << " " << nbuckets; | 637 << min << " " << max << " " << nbuckets; |
| 635 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets); | 638 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets); |
| 636 } | 639 } |
| OLD | NEW |