Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(314)

Side by Side Diff: metrics_daemon.cc

Issue 6541007: Find device-dependent disk stats file, and skip disk stats if not available. (Closed) Base URL: http://git.chromium.org/git/metrics.git@master
Patch Set: More small changes Created 9 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « metrics_daemon.h ('k') | metrics_daemon_main.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 const char* MetricsDaemon::kSessionStates_[] = { 139 const char* MetricsDaemon::kSessionStates_[] = {
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) {}
151 150
152 MetricsDaemon::~MetricsDaemon() { 151 MetricsDaemon::~MetricsDaemon() {
153 DeleteFrequencyCounters(); 152 DeleteFrequencyCounters();
154 } 153 }
155 154
156 void MetricsDaemon::DeleteFrequencyCounters() { 155 void MetricsDaemon::DeleteFrequencyCounters() {
157 for (FrequencyCounters::iterator i = frequency_counters_.begin(); 156 for (FrequencyCounters::iterator i = frequency_counters_.begin();
158 i != frequency_counters_.end(); ++i) { 157 i != frequency_counters_.end(); ++i) {
159 delete i->second; 158 delete i->second;
160 i->second = NULL; 159 i->second = NULL;
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 chromeos_metrics::kSecondsPerWeek : 207 chromeos_metrics::kSecondsPerWeek :
209 chromeos_metrics::kSecondsPerDay; 208 chromeos_metrics::kSecondsPerDay;
210 new_counter->Init( 209 new_counter->Init(
211 static_cast<chromeos_metrics::TaggedCounterInterface*>( 210 static_cast<chromeos_metrics::TaggedCounterInterface*>(
212 reporter.release()), 211 reporter.release()),
213 cycle_duration); 212 cycle_duration);
214 frequency_counters_[histogram_name] = new_counter.release(); 213 frequency_counters_[histogram_name] = new_counter.release();
215 } 214 }
216 215
217 void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib, 216 void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib,
218 const char* diskstats_path) { 217 string diskstats_path) {
219 testing_ = testing; 218 testing_ = testing;
220 DCHECK(metrics_lib != NULL); 219 DCHECK(metrics_lib != NULL);
221 metrics_lib_ = metrics_lib; 220 metrics_lib_ = metrics_lib;
222 chromeos_metrics::TaggedCounterReporter:: 221 chromeos_metrics::TaggedCounterReporter::
223 SetMetricsLibraryInterface(metrics_lib); 222 SetMetricsLibraryInterface(metrics_lib);
224 223
225 static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage"; 224 static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage";
226 daily_use_.reset(new chromeos_metrics::TaggedCounter()); 225 daily_use_.reset(new chromeos_metrics::TaggedCounter());
227 daily_use_->Init(kDailyUseRecordFile, &ReportDailyUse, this); 226 daily_use_->Init(kDailyUseRecordFile, &ReportDailyUse, this);
228 227
229 ConfigureCrashIntervalReporter(kMetricKernelCrashIntervalName, 228 ConfigureCrashIntervalReporter(kMetricKernelCrashIntervalName,
230 &kernel_crash_interval_); 229 &kernel_crash_interval_);
231 ConfigureCrashIntervalReporter(kMetricUncleanShutdownIntervalName, 230 ConfigureCrashIntervalReporter(kMetricUncleanShutdownIntervalName,
232 &unclean_shutdown_interval_); 231 &unclean_shutdown_interval_);
233 ConfigureCrashIntervalReporter(kMetricUserCrashIntervalName, 232 ConfigureCrashIntervalReporter(kMetricUserCrashIntervalName,
234 &user_crash_interval_); 233 &user_crash_interval_);
235 234
236 DeleteFrequencyCounters(); 235 DeleteFrequencyCounters();
237 ConfigureCrashFrequencyReporter(kMetricAnyCrashesDailyName); 236 ConfigureCrashFrequencyReporter(kMetricAnyCrashesDailyName);
238 ConfigureCrashFrequencyReporter(kMetricAnyCrashesWeeklyName); 237 ConfigureCrashFrequencyReporter(kMetricAnyCrashesWeeklyName);
239 ConfigureCrashFrequencyReporter(kMetricKernelCrashesDailyName); 238 ConfigureCrashFrequencyReporter(kMetricKernelCrashesDailyName);
240 ConfigureCrashFrequencyReporter(kMetricKernelCrashesWeeklyName); 239 ConfigureCrashFrequencyReporter(kMetricKernelCrashesWeeklyName);
241 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsDailyName); 240 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsDailyName);
242 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsWeeklyName); 241 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsWeeklyName);
243 ConfigureCrashFrequencyReporter(kMetricUserCrashesDailyName); 242 ConfigureCrashFrequencyReporter(kMetricUserCrashesDailyName);
244 ConfigureCrashFrequencyReporter(kMetricUserCrashesWeeklyName); 243 ConfigureCrashFrequencyReporter(kMetricUserCrashesWeeklyName);
245 244
246 diskstats_path_ = diskstats_path; 245 // Don't attempt to collect disk stats if there is no disk stats file.
247 DiskStatsReporterInit(); 246 if (!diskstats_path.empty()) {
247 diskstats_path_ = diskstats_path;
248 DiskStatsReporterInit();
249 }
248 250
249 // Don't setup D-Bus and GLib in test mode. 251 // Don't setup D-Bus and GLib in test mode.
250 if (testing) 252 if (testing)
251 return; 253 return;
252 254
253 g_thread_init(NULL); 255 g_thread_init(NULL);
254 g_type_init(); 256 g_type_init();
255 dbus_g_thread_init(); 257 dbus_g_thread_init();
256 258
257 DBusError error; 259 DBusError error;
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after
534 return; 536 return;
535 } 537 }
536 g_timeout_add_seconds(wait, DiskStatsCallbackStatic, this); 538 g_timeout_add_seconds(wait, DiskStatsCallbackStatic, this);
537 } 539 }
538 540
539 void MetricsDaemon::DiskStatsReadStats(long int* read_sectors, 541 void MetricsDaemon::DiskStatsReadStats(long int* read_sectors,
540 long int* write_sectors) { 542 long int* write_sectors) {
541 int nchars; 543 int nchars;
542 int nitems; 544 int nitems;
543 char line[200]; 545 char line[200];
544 int file = HANDLE_EINTR(open(diskstats_path_, O_RDONLY)); 546 int file = HANDLE_EINTR(open(diskstats_path_.c_str(), O_RDONLY));
545 if (file < 0) { 547 if (file < 0) {
546 PLOG(WARNING) << "cannot open " << diskstats_path_; 548 PLOG(WARNING) << "cannot open " << diskstats_path_;
547 return; 549 return;
548 } 550 }
549 nchars = HANDLE_EINTR(read(file, line, sizeof(line))); 551 nchars = HANDLE_EINTR(read(file, line, sizeof(line)));
550 if (nchars < 0) { 552 if (nchars < 0) {
551 PLOG(WARNING) << "cannot read from " << diskstats_path_; 553 PLOG(WARNING) << "cannot read from " << diskstats_path_;
552 } else { 554 } else {
553 LOG_IF(WARNING, nchars == sizeof(line)) << "line too long in " 555 LOG_IF(WARNING, nchars == sizeof(line)) << "line too long in "
554 << diskstats_path_; 556 << diskstats_path_;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
627 kMetricDailyUseTimeMax, 629 kMetricDailyUseTimeMax,
628 kMetricDailyUseTimeBuckets); 630 kMetricDailyUseTimeBuckets);
629 } 631 }
630 632
631 void MetricsDaemon::SendMetric(const string& name, int sample, 633 void MetricsDaemon::SendMetric(const string& name, int sample,
632 int min, int max, int nbuckets) { 634 int min, int max, int nbuckets) {
633 DLOG(INFO) << "received metric: " << name << " " << sample << " " 635 DLOG(INFO) << "received metric: " << name << " " << sample << " "
634 << min << " " << max << " " << nbuckets; 636 << min << " " << max << " " << nbuckets;
635 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets); 637 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets);
636 } 638 }
OLDNEW
« no previous file with comments | « metrics_daemon.h ('k') | metrics_daemon_main.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698