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 <dbus/dbus-glib-lowlevel.h> | 7 #include <string.h> |
8 | 8 |
9 #include <base/file_util.h> | 9 #include <base/file_util.h> |
10 #include <base/logging.h> | 10 #include <base/logging.h> |
| 11 #include <dbus/dbus-glib-lowlevel.h> |
11 | 12 |
12 #include "counter.h" | 13 #include "counter.h" |
13 | 14 |
14 using base::Time; | 15 using base::Time; |
15 using base::TimeDelta; | 16 using base::TimeDelta; |
16 using base::TimeTicks; | 17 using base::TimeTicks; |
17 using std::string; | 18 using std::string; |
18 | 19 |
19 #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error") | 20 #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error") |
20 #define DBUS_IFACE_CRASH_REPORTER "org.chromium.CrashReporter" | 21 #define DBUS_IFACE_CRASH_REPORTER "org.chromium.CrashReporter" |
(...skipping 15 matching lines...) Expand all Loading... |
36 // implemented because the histogram buckets are spaced exponentially | 37 // implemented because the histogram buckets are spaced exponentially |
37 // anyway and to avoid too frequent metrics daemon process wake-ups | 38 // anyway and to avoid too frequent metrics daemon process wake-ups |
38 // and file I/O. | 39 // and file I/O. |
39 static const int kUseMonitorIntervalInit = 1 * kSecondsPerMinute; | 40 static const int kUseMonitorIntervalInit = 1 * kSecondsPerMinute; |
40 static const int kUseMonitorIntervalMax = 10 * kSecondsPerMinute; | 41 static const int kUseMonitorIntervalMax = 10 * kSecondsPerMinute; |
41 | 42 |
42 const char kKernelCrashDetectedFile[] = "/tmp/kernel-crash-detected"; | 43 const char kKernelCrashDetectedFile[] = "/tmp/kernel-crash-detected"; |
43 static const char kUncleanShutdownDetectedFile[] = | 44 static const char kUncleanShutdownDetectedFile[] = |
44 "/tmp/unclean-shutdown-detected"; | 45 "/tmp/unclean-shutdown-detected"; |
45 | 46 |
46 // static metrics parameters. | 47 // static metrics parameters |
47 const char MetricsDaemon::kMetricDailyUseTimeName[] = | 48 const char MetricsDaemon::kMetricDailyUseTimeName[] = |
48 "Logging.DailyUseTime"; | 49 "Logging.DailyUseTime"; |
49 const int MetricsDaemon::kMetricDailyUseTimeMin = 1; | 50 const int MetricsDaemon::kMetricDailyUseTimeMin = 1; |
50 const int MetricsDaemon::kMetricDailyUseTimeMax = kMinutesPerDay; | 51 const int MetricsDaemon::kMetricDailyUseTimeMax = kMinutesPerDay; |
51 const int MetricsDaemon::kMetricDailyUseTimeBuckets = 50; | 52 const int MetricsDaemon::kMetricDailyUseTimeBuckets = 50; |
52 | 53 |
53 const char MetricsDaemon::kMetricTimeToNetworkDropName[] = | 54 const char MetricsDaemon::kMetricTimeToNetworkDropName[] = |
54 "Network.TimeToDrop"; | 55 "Network.TimeToDrop"; |
55 const int MetricsDaemon::kMetricTimeToNetworkDropMin = 1; | 56 const int MetricsDaemon::kMetricTimeToNetworkDropMin = 1; |
56 const int MetricsDaemon::kMetricTimeToNetworkDropMax = | 57 const int MetricsDaemon::kMetricTimeToNetworkDropMax = |
57 8 /* hours */ * kMinutesPerHour * kSecondsPerMinute; | 58 8 /* hours */ * kMinutesPerHour * kSecondsPerMinute; |
58 const int MetricsDaemon::kMetricTimeToNetworkDropBuckets = 50; | 59 const int MetricsDaemon::kMetricTimeToNetworkDropBuckets = 50; |
59 | 60 |
60 // crash interval metrics | 61 // crash interval metrics |
61 const char MetricsDaemon::kMetricKernelCrashIntervalName[] = | 62 const char MetricsDaemon::kMetricKernelCrashIntervalName[] = |
62 "Logging.KernelCrashInterval"; | 63 "Logging.KernelCrashInterval"; |
63 const char MetricsDaemon::kMetricUncleanShutdownIntervalName[] = | 64 const char MetricsDaemon::kMetricUncleanShutdownIntervalName[] = |
64 "Logging.UncleanShutdownInterval"; | 65 "Logging.UncleanShutdownInterval"; |
65 const char MetricsDaemon::kMetricUserCrashIntervalName[] = | 66 const char MetricsDaemon::kMetricUserCrashIntervalName[] = |
66 "Logging.UserCrashInterval"; | 67 "Logging.UserCrashInterval"; |
67 | 68 |
68 const int MetricsDaemon::kMetricCrashIntervalMin = 1; | 69 const int MetricsDaemon::kMetricCrashIntervalMin = 1; |
69 const int MetricsDaemon::kMetricCrashIntervalMax = | 70 const int MetricsDaemon::kMetricCrashIntervalMax = |
70 4 * kSecondsPerWeek; | 71 4 * kSecondsPerWeek; |
71 const int MetricsDaemon::kMetricCrashIntervalBuckets = 50; | 72 const int MetricsDaemon::kMetricCrashIntervalBuckets = 50; |
72 | 73 |
73 // crash frequency metrics | 74 // crash frequency metrics |
74 const char MetricsDaemon::kMetricAnyCrashesDailyName[] = | 75 const char MetricsDaemon::kMetricAnyCrashesDailyName[] = |
75 "Logging.AnyCrashesDaily"; | 76 "Logging.AnyCrashesDaily"; |
| 77 const char MetricsDaemon::kMetricAnyCrashesWeeklyName[] = |
| 78 "Logging.AnyCrashesWeekly"; |
76 const char MetricsDaemon::kMetricKernelCrashesDailyName[] = | 79 const char MetricsDaemon::kMetricKernelCrashesDailyName[] = |
77 "Logging.KernelCrashesDaily"; | 80 "Logging.KernelCrashesDaily"; |
| 81 const char MetricsDaemon::kMetricKernelCrashesWeeklyName[] = |
| 82 "Logging.KernelCrashesWeekly"; |
78 const char MetricsDaemon::kMetricUncleanShutdownsDailyName[] = | 83 const char MetricsDaemon::kMetricUncleanShutdownsDailyName[] = |
79 "Logging.UncleanShutdownsDaily"; | 84 "Logging.UncleanShutdownsDaily"; |
| 85 const char MetricsDaemon::kMetricUncleanShutdownsWeeklyName[] = |
| 86 "Logging.UncleanShutdownsWeekly"; |
80 const char MetricsDaemon::kMetricUserCrashesDailyName[] = | 87 const char MetricsDaemon::kMetricUserCrashesDailyName[] = |
81 "Logging.UserCrashesDaily"; | 88 "Logging.UserCrashesDaily"; |
82 const char MetricsDaemon::kMetricCrashesDailyMin = 1; | 89 const char MetricsDaemon::kMetricUserCrashesWeeklyName[] = |
83 const char MetricsDaemon::kMetricCrashesDailyMax = 100; | 90 "Logging.UserCrashesWeekly"; |
84 const char MetricsDaemon::kMetricCrashesDailyBuckets = 50; | 91 const char MetricsDaemon::kMetricCrashFrequencyMin = 1; |
| 92 const char MetricsDaemon::kMetricCrashFrequencyMax = 100; |
| 93 const char MetricsDaemon::kMetricCrashFrequencyBuckets = 50; |
85 | 94 |
| 95 // persistent metrics path |
| 96 const char MetricsDaemon::kMetricsPath[] = "/var/log/metrics"; |
86 | 97 |
87 | 98 |
88 // static | 99 // static |
89 const char* MetricsDaemon::kDBusMatches_[] = { | 100 const char* MetricsDaemon::kDBusMatches_[] = { |
90 "type='signal'," | 101 "type='signal'," |
91 "interface='" DBUS_IFACE_CRASH_REPORTER "'," | 102 "interface='" DBUS_IFACE_CRASH_REPORTER "'," |
92 "path='/'," | 103 "path='/'," |
93 "member='UserCrash'", | 104 "member='UserCrash'", |
94 | 105 |
95 "type='signal'," | 106 "type='signal'," |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 } | 186 } |
176 | 187 |
177 MetricsDaemon::MetricsDaemon() | 188 MetricsDaemon::MetricsDaemon() |
178 : network_state_(kUnknownNetworkState), | 189 : network_state_(kUnknownNetworkState), |
179 power_state_(kUnknownPowerState), | 190 power_state_(kUnknownPowerState), |
180 session_state_(kUnknownSessionState), | 191 session_state_(kUnknownSessionState), |
181 user_active_(false), | 192 user_active_(false), |
182 usemon_interval_(0), | 193 usemon_interval_(0), |
183 usemon_source_(NULL) {} | 194 usemon_source_(NULL) {} |
184 | 195 |
185 MetricsDaemon::~MetricsDaemon() {} | 196 MetricsDaemon::~MetricsDaemon() { |
| 197 DeleteFrequencyCounters(); |
| 198 } |
| 199 |
| 200 void MetricsDaemon::DeleteFrequencyCounters() { |
| 201 for (FrequencyCounters::iterator i = frequency_counters_.begin(); |
| 202 i != frequency_counters_.end(); ++i) { |
| 203 delete i->second; |
| 204 i->second = NULL; |
| 205 } |
| 206 } |
186 | 207 |
187 void MetricsDaemon::Run(bool run_as_daemon) { | 208 void MetricsDaemon::Run(bool run_as_daemon) { |
188 if (run_as_daemon && daemon(0, 0) != 0) | 209 if (run_as_daemon && daemon(0, 0) != 0) |
189 return; | 210 return; |
190 | 211 |
191 if (CheckSystemCrash(kKernelCrashDetectedFile)) { | 212 if (CheckSystemCrash(kKernelCrashDetectedFile)) { |
192 ProcessKernelCrash(); | 213 ProcessKernelCrash(); |
193 } | 214 } |
194 | 215 |
195 if (CheckSystemCrash(kUncleanShutdownDetectedFile)) { | 216 if (CheckSystemCrash(kUncleanShutdownDetectedFile)) { |
196 ProcessUncleanShutdown(); | 217 ProcessUncleanShutdown(); |
197 } | 218 } |
198 | 219 |
199 Loop(); | 220 Loop(); |
200 } | 221 } |
201 | 222 |
| 223 FilePath MetricsDaemon::GetHistogramPath(const char* histogram_name) { |
| 224 return FilePath(kMetricsPath).Append(histogram_name); |
| 225 } |
| 226 |
| 227 void MetricsDaemon::ConfigureCrashIntervalReporter( |
| 228 const char* histogram_name, |
| 229 scoped_ptr<chromeos_metrics::TaggedCounterReporter>* reporter) { |
| 230 reporter->reset(new chromeos_metrics::TaggedCounterReporter()); |
| 231 FilePath file_path = GetHistogramPath(histogram_name); |
| 232 (*reporter)->Init(file_path.value().c_str(), |
| 233 histogram_name, |
| 234 kMetricCrashIntervalMin, |
| 235 kMetricCrashIntervalMax, |
| 236 kMetricCrashIntervalBuckets); |
| 237 } |
| 238 |
| 239 void MetricsDaemon::ConfigureCrashFrequencyReporter( |
| 240 const char* histogram_name) { |
| 241 scoped_ptr<chromeos_metrics::TaggedCounterReporter> reporter( |
| 242 new chromeos_metrics::TaggedCounterReporter()); |
| 243 FilePath file_path = GetHistogramPath(histogram_name); |
| 244 reporter->Init(file_path.value().c_str(), |
| 245 histogram_name, |
| 246 kMetricCrashFrequencyMin, |
| 247 kMetricCrashFrequencyMax, |
| 248 kMetricCrashFrequencyBuckets); |
| 249 scoped_ptr<chromeos_metrics::FrequencyCounter> new_counter( |
| 250 new chromeos_metrics::FrequencyCounter()); |
| 251 time_t cycle_duration = strstr(histogram_name, "Weekly") != NULL ? |
| 252 chromeos_metrics::kSecondsPerWeek : |
| 253 chromeos_metrics::kSecondsPerDay; |
| 254 new_counter->Init( |
| 255 static_cast<chromeos_metrics::TaggedCounterInterface*>( |
| 256 reporter.release()), |
| 257 cycle_duration); |
| 258 frequency_counters_[histogram_name] = new_counter.release(); |
| 259 } |
| 260 |
202 void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib) { | 261 void MetricsDaemon::Init(bool testing, MetricsLibraryInterface* metrics_lib) { |
203 testing_ = testing; | 262 testing_ = testing; |
204 DCHECK(metrics_lib != NULL); | 263 DCHECK(metrics_lib != NULL); |
205 metrics_lib_ = metrics_lib; | 264 metrics_lib_ = metrics_lib; |
| 265 chromeos_metrics::TaggedCounterReporter:: |
| 266 SetMetricsLibraryInterface(metrics_lib); |
206 | 267 |
207 static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage"; | 268 static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage"; |
208 daily_use_.reset(new chromeos_metrics::TaggedCounter()); | 269 daily_use_.reset(new chromeos_metrics::TaggedCounter()); |
209 daily_use_->Init(kDailyUseRecordFile, &ReportDailyUse, this); | 270 daily_use_->Init(kDailyUseRecordFile, &ReportDailyUse, this); |
210 | 271 |
211 static const char kUserCrashIntervalRecordFile[] = | 272 ConfigureCrashIntervalReporter(kMetricKernelCrashIntervalName, |
212 "/var/log/metrics/user-crash-interval"; | 273 &kernel_crash_interval_); |
213 user_crash_interval_.reset(new chromeos_metrics::TaggedCounter()); | 274 ConfigureCrashIntervalReporter(kMetricUncleanShutdownIntervalName, |
214 user_crash_interval_->Init(kUserCrashIntervalRecordFile, | 275 &unclean_shutdown_interval_); |
215 &ReportUserCrashInterval, this); | 276 ConfigureCrashIntervalReporter(kMetricUserCrashIntervalName, |
| 277 &user_crash_interval_); |
216 | 278 |
217 static const char kKernelCrashIntervalRecordFile[] = | 279 DeleteFrequencyCounters(); |
218 "/var/log/metrics/kernel-crash-interval"; | 280 ConfigureCrashFrequencyReporter(kMetricAnyCrashesDailyName); |
219 kernel_crash_interval_.reset(new chromeos_metrics::TaggedCounter()); | 281 ConfigureCrashFrequencyReporter(kMetricAnyCrashesDailyName); |
220 kernel_crash_interval_->Init(kKernelCrashIntervalRecordFile, | 282 ConfigureCrashFrequencyReporter(kMetricAnyCrashesWeeklyName); |
221 &ReportKernelCrashInterval, this); | 283 ConfigureCrashFrequencyReporter(kMetricKernelCrashesDailyName); |
222 | 284 ConfigureCrashFrequencyReporter(kMetricKernelCrashesWeeklyName); |
223 static const char kUncleanShutdownDetectedFile[] = | 285 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsDailyName); |
224 "/var/log/metrics/unclean-shutdown-interval"; | 286 ConfigureCrashFrequencyReporter(kMetricUncleanShutdownsWeeklyName); |
225 unclean_shutdown_interval_.reset(new chromeos_metrics::TaggedCounter()); | 287 ConfigureCrashFrequencyReporter(kMetricUserCrashesDailyName); |
226 unclean_shutdown_interval_->Init(kUncleanShutdownDetectedFile, | 288 ConfigureCrashFrequencyReporter(kMetricUserCrashesWeeklyName); |
227 &ReportUncleanShutdownInterval, this); | |
228 | |
229 static const char kUserCrashesDailyRecordFile[] = | |
230 "/var/log/metrics/user-crashes-daily"; | |
231 user_crashes_daily_.reset(new chromeos_metrics::FrequencyCounter()); | |
232 user_crashes_daily_->Init(kUserCrashesDailyRecordFile, | |
233 &ReportUserCrashesDaily, | |
234 this, | |
235 chromeos_metrics::kSecondsPerDay); | |
236 | |
237 static const char kKernelCrashesDailyRecordFile[] = | |
238 "/var/log/metrics/kernel-crashes-daily"; | |
239 kernel_crashes_daily_.reset(new chromeos_metrics::FrequencyCounter()); | |
240 kernel_crashes_daily_->Init(kKernelCrashesDailyRecordFile, | |
241 &ReportKernelCrashesDaily, | |
242 this, | |
243 chromeos_metrics::kSecondsPerDay); | |
244 | |
245 static const char kUncleanShutdownsDailyRecordFile[] = | |
246 "/var/log/metrics/unclean-shutdowns-daily"; | |
247 unclean_shutdowns_daily_.reset(new chromeos_metrics::FrequencyCounter()); | |
248 unclean_shutdowns_daily_->Init(kUncleanShutdownsDailyRecordFile, | |
249 &ReportUncleanShutdownsDaily, | |
250 this, | |
251 chromeos_metrics::kSecondsPerDay); | |
252 | |
253 static const char kAnyCrashesUserCrashDailyRecordFile[] = | |
254 "/var/log/metrics/any-crashes-daily"; | |
255 any_crashes_daily_.reset(new chromeos_metrics::FrequencyCounter()); | |
256 any_crashes_daily_->Init(kAnyCrashesUserCrashDailyRecordFile, | |
257 &ReportAnyCrashesDaily, | |
258 this, | |
259 chromeos_metrics::kSecondsPerDay); | |
260 | 289 |
261 // Don't setup D-Bus and GLib in test mode. | 290 // Don't setup D-Bus and GLib in test mode. |
262 if (testing) | 291 if (testing) |
263 return; | 292 return; |
264 | 293 |
265 g_thread_init(NULL); | 294 g_thread_init(NULL); |
266 g_type_init(); | 295 g_type_init(); |
267 dbus_g_thread_init(); | 296 dbus_g_thread_init(); |
268 | 297 |
269 DBusError error; | 298 DBusError error; |
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
446 kUseMonitorIntervalMax + kSecondsPerMinute)) { | 475 kUseMonitorIntervalMax + kSecondsPerMinute)) { |
447 seconds = static_cast<int>(since_active.InSeconds()); | 476 seconds = static_cast<int>(since_active.InSeconds()); |
448 } | 477 } |
449 } | 478 } |
450 TimeDelta since_epoch = now - Time(); | 479 TimeDelta since_epoch = now - Time(); |
451 int day = since_epoch.InDays(); | 480 int day = since_epoch.InDays(); |
452 daily_use_->Update(day, seconds); | 481 daily_use_->Update(day, seconds); |
453 user_crash_interval_->Update(0, seconds); | 482 user_crash_interval_->Update(0, seconds); |
454 kernel_crash_interval_->Update(0, seconds); | 483 kernel_crash_interval_->Update(0, seconds); |
455 | 484 |
| 485 // Flush finished cycles of all frequency counters. |
| 486 for (FrequencyCounters::iterator i = frequency_counters_.begin(); |
| 487 i != frequency_counters_.end(); ++i) { |
| 488 i->second->FlushFinishedCycles(); |
| 489 } |
| 490 |
456 // Schedules a use monitor on inactive->active transitions and | 491 // Schedules a use monitor on inactive->active transitions and |
457 // unschedules it on active->inactive transitions. | 492 // unschedules it on active->inactive transitions. |
458 if (!user_active_ && active) | 493 if (!user_active_ && active) |
459 ScheduleUseMonitor(kUseMonitorIntervalInit, /* backoff */ false); | 494 ScheduleUseMonitor(kUseMonitorIntervalInit, /* backoff */ false); |
460 else if (user_active_ && !active) | 495 else if (user_active_ && !active) |
461 UnscheduleUseMonitor(); | 496 UnscheduleUseMonitor(); |
462 | 497 |
463 // Remembers the current active state and the time of the last | 498 // Remembers the current active state and the time of the last |
464 // activity update. | 499 // activity update. |
465 user_active_ = active; | 500 user_active_ = active; |
466 user_active_last_ = now; | 501 user_active_last_ = now; |
467 } | 502 } |
468 | 503 |
469 void MetricsDaemon::ProcessUserCrash() { | 504 void MetricsDaemon::ProcessUserCrash() { |
470 // Counts the active use time up to now. | 505 // Counts the active use time up to now. |
471 SetUserActiveState(user_active_, Time::Now()); | 506 SetUserActiveState(user_active_, Time::Now()); |
472 | 507 |
473 // Reports the active use time since the last crash and resets it. | 508 // Reports the active use time since the last crash and resets it. |
474 user_crash_interval_->Flush(); | 509 user_crash_interval_->Flush(); |
475 | 510 |
476 user_crashes_daily_->Update(1); | 511 frequency_counters_[kMetricUserCrashesDailyName]->Update(1); |
477 any_crashes_daily_->Update(1); | 512 frequency_counters_[kMetricUserCrashesWeeklyName]->Update(1); |
| 513 frequency_counters_[kMetricAnyCrashesDailyName]->Update(1); |
| 514 frequency_counters_[kMetricAnyCrashesWeeklyName]->Update(1); |
478 } | 515 } |
479 | 516 |
480 void MetricsDaemon::ProcessKernelCrash() { | 517 void MetricsDaemon::ProcessKernelCrash() { |
481 // Counts the active use time up to now. | 518 // Counts the active use time up to now. |
482 SetUserActiveState(user_active_, Time::Now()); | 519 SetUserActiveState(user_active_, Time::Now()); |
483 | 520 |
484 // Reports the active use time since the last crash and resets it. | 521 // Reports the active use time since the last crash and resets it. |
485 kernel_crash_interval_->Flush(); | 522 kernel_crash_interval_->Flush(); |
486 | 523 |
487 kernel_crashes_daily_->Update(1); | 524 frequency_counters_[kMetricKernelCrashesDailyName]->Update(1); |
488 any_crashes_daily_->Update(1); | 525 frequency_counters_[kMetricKernelCrashesWeeklyName]->Update(1); |
| 526 frequency_counters_[kMetricAnyCrashesDailyName]->Update(1); |
| 527 frequency_counters_[kMetricAnyCrashesWeeklyName]->Update(1); |
489 } | 528 } |
490 | 529 |
491 void MetricsDaemon::ProcessUncleanShutdown() { | 530 void MetricsDaemon::ProcessUncleanShutdown() { |
492 // Counts the active use time up to now. | 531 // Counts the active use time up to now. |
493 SetUserActiveState(user_active_, Time::Now()); | 532 SetUserActiveState(user_active_, Time::Now()); |
494 | 533 |
495 // Reports the active use time since the last crash and resets it. | 534 // Reports the active use time since the last crash and resets it. |
496 unclean_shutdown_interval_->Flush(); | 535 unclean_shutdown_interval_->Flush(); |
497 | 536 |
498 unclean_shutdowns_daily_->Update(1); | 537 frequency_counters_[kMetricUncleanShutdownsDailyName]->Update(1); |
499 any_crashes_daily_->Update(1); | 538 frequency_counters_[kMetricUncleanShutdownsWeeklyName]->Update(1); |
| 539 frequency_counters_[kMetricAnyCrashesDailyName]->Update(1); |
| 540 frequency_counters_[kMetricAnyCrashesWeeklyName]->Update(1); |
500 } | 541 } |
501 | 542 |
502 bool MetricsDaemon::CheckSystemCrash(const std::string& crash_file) { | 543 bool MetricsDaemon::CheckSystemCrash(const std::string& crash_file) { |
503 FilePath crash_detected(crash_file); | 544 FilePath crash_detected(crash_file); |
504 if (!file_util::PathExists(crash_detected)) | 545 if (!file_util::PathExists(crash_detected)) |
505 return false; | 546 return false; |
506 | 547 |
507 // Deletes the crash-detected file so that the daemon doesn't report | 548 // Deletes the crash-detected file so that the daemon doesn't report |
508 // another kernel crash in case it's restarted. | 549 // another kernel crash in case it's restarted. |
509 file_util::Delete(crash_detected, | 550 file_util::Delete(crash_detected, |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
577 return; | 618 return; |
578 | 619 |
579 MetricsDaemon* daemon = static_cast<MetricsDaemon*>(handle); | 620 MetricsDaemon* daemon = static_cast<MetricsDaemon*>(handle); |
580 int minutes = (count + kSecondsPerMinute / 2) / kSecondsPerMinute; | 621 int minutes = (count + kSecondsPerMinute / 2) / kSecondsPerMinute; |
581 daemon->SendMetric(kMetricDailyUseTimeName, minutes, | 622 daemon->SendMetric(kMetricDailyUseTimeName, minutes, |
582 kMetricDailyUseTimeMin, | 623 kMetricDailyUseTimeMin, |
583 kMetricDailyUseTimeMax, | 624 kMetricDailyUseTimeMax, |
584 kMetricDailyUseTimeBuckets); | 625 kMetricDailyUseTimeBuckets); |
585 } | 626 } |
586 | 627 |
587 // static | |
588 void MetricsDaemon::ReportCrashInterval(const char* histogram_name, | |
589 void* handle, int count) { | |
590 MetricsDaemon* daemon = static_cast<MetricsDaemon*>(handle); | |
591 daemon->SendMetric(histogram_name, count, | |
592 kMetricCrashIntervalMin, | |
593 kMetricCrashIntervalMax, | |
594 kMetricCrashIntervalBuckets); | |
595 } | |
596 | |
597 // static | |
598 void MetricsDaemon::ReportUserCrashInterval(void* handle, | |
599 int tag, int count) { | |
600 ReportCrashInterval(kMetricUserCrashIntervalName, handle, count); | |
601 } | |
602 | |
603 // static | |
604 void MetricsDaemon::ReportKernelCrashInterval(void* handle, | |
605 int tag, int count) { | |
606 ReportCrashInterval(kMetricKernelCrashIntervalName, handle, count); | |
607 } | |
608 | |
609 // static | |
610 void MetricsDaemon::ReportUncleanShutdownInterval(void* handle, | |
611 int tag, int count) { | |
612 ReportCrashInterval(kMetricUncleanShutdownIntervalName, handle, count); | |
613 } | |
614 | |
615 // static | |
616 void MetricsDaemon::ReportCrashesDailyFrequency(const char* histogram_name, | |
617 void* handle, | |
618 int count) { | |
619 MetricsDaemon* daemon = static_cast<MetricsDaemon*>(handle); | |
620 daemon->SendMetric(histogram_name, count, | |
621 kMetricCrashesDailyMin, | |
622 kMetricCrashesDailyMax, | |
623 kMetricCrashesDailyBuckets); | |
624 } | |
625 | |
626 // static | |
627 void MetricsDaemon::ReportUserCrashesDaily(void* handle, | |
628 int tag, int count) { | |
629 ReportCrashesDailyFrequency(kMetricUserCrashesDailyName, handle, count); | |
630 } | |
631 | |
632 // static | |
633 void MetricsDaemon::ReportKernelCrashesDaily(void* handle, | |
634 int tag, int count) { | |
635 ReportCrashesDailyFrequency(kMetricKernelCrashesDailyName, handle, count); | |
636 } | |
637 | |
638 // static | |
639 void MetricsDaemon::ReportUncleanShutdownsDaily(void* handle, | |
640 int tag, int count) { | |
641 ReportCrashesDailyFrequency(kMetricUncleanShutdownsDailyName, handle, count); | |
642 } | |
643 | |
644 // static | |
645 void MetricsDaemon::ReportAnyCrashesDaily(void* handle, int tag, int count) { | |
646 ReportCrashesDailyFrequency(kMetricAnyCrashesDailyName, handle, count); | |
647 } | |
648 | |
649 | |
650 void MetricsDaemon::SendMetric(const string& name, int sample, | 628 void MetricsDaemon::SendMetric(const string& name, int sample, |
651 int min, int max, int nbuckets) { | 629 int min, int max, int nbuckets) { |
652 DLOG(INFO) << "received metric: " << name << " " << sample << " " | 630 DLOG(INFO) << "received metric: " << name << " " << sample << " " |
653 << min << " " << max << " " << nbuckets; | 631 << min << " " << max << " " << nbuckets; |
654 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets); | 632 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets); |
655 } | 633 } |
OLD | NEW |