| 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 <dbus/dbus-glib-lowlevel.h> |
| 8 #include <sys/file.h> | 8 #include <sys/file.h> |
| 9 | 9 |
| 10 #include <base/eintr_wrapper.h> | 10 #include <base/eintr_wrapper.h> |
| 11 #include <base/logging.h> | 11 #include <base/logging.h> |
| 12 | 12 |
| 13 using base::Time; | 13 using base::Time; |
| 14 using base::TimeDelta; | 14 using base::TimeDelta; |
| 15 using base::TimeTicks; | 15 using base::TimeTicks; |
| 16 | 16 |
| 17 #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error") | 17 #define SAFE_MESSAGE(e) (e.message ? e.message : "unknown error") |
| 18 #define DBUS_IFACE_CONNMAN_MANAGER "org.moblin.connman.Manager" | 18 #define DBUS_IFACE_FLIMFLAM_MANAGER "org.chromium.flimflam.Manager" |
| 19 #define DBUS_IFACE_POWER_MANAGER "org.chromium.Power.Manager" | 19 #define DBUS_IFACE_POWER_MANAGER "org.chromium.Power.Manager" |
| 20 #define DBUS_IFACE_SCREENSAVER_MANAGER "org.chromium.ScreenSaver.Manager" | 20 #define DBUS_IFACE_SCREENSAVER_MANAGER "org.chromium.ScreenSaver.Manager" |
| 21 #define DBUS_IFACE_SESSION_MANAGER "org.chromium.SessionManagerInterface" | 21 #define DBUS_IFACE_SESSION_MANAGER "org.chromium.SessionManagerInterface" |
| 22 | 22 |
| 23 // File to aggregate daily usage before sending to UMA. | 23 // File to aggregate daily usage before sending to UMA. |
| 24 // TODO(petkov): This file should probably live in a user-specific stateful | 24 // TODO(petkov): This file should probably live in a user-specific stateful |
| 25 // location, e.g., /home/chronos/user. | 25 // location, e.g., /home/chronos/user. |
| 26 static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage"; | 26 static const char kDailyUseRecordFile[] = "/var/log/metrics/daily-usage"; |
| 27 | 27 |
| 28 static const int kSecondsPerMinute = 60; | 28 static const int kSecondsPerMinute = 60; |
| (...skipping 20 matching lines...) Expand all Loading... |
| 49 const char MetricsDaemon::kMetricTimeToNetworkDropName[] = | 49 const char MetricsDaemon::kMetricTimeToNetworkDropName[] = |
| 50 "Network.TimeToDrop"; | 50 "Network.TimeToDrop"; |
| 51 const int MetricsDaemon::kMetricTimeToNetworkDropMin = 1; | 51 const int MetricsDaemon::kMetricTimeToNetworkDropMin = 1; |
| 52 const int MetricsDaemon::kMetricTimeToNetworkDropMax = | 52 const int MetricsDaemon::kMetricTimeToNetworkDropMax = |
| 53 8 /* hours */ * kMinutesPerHour * kSecondsPerMinute; | 53 8 /* hours */ * kMinutesPerHour * kSecondsPerMinute; |
| 54 const int MetricsDaemon::kMetricTimeToNetworkDropBuckets = 50; | 54 const int MetricsDaemon::kMetricTimeToNetworkDropBuckets = 50; |
| 55 | 55 |
| 56 // static | 56 // static |
| 57 const char* MetricsDaemon::kDBusMatches_[] = { | 57 const char* MetricsDaemon::kDBusMatches_[] = { |
| 58 "type='signal'," | 58 "type='signal'," |
| 59 "sender='org.moblin.connman'," | 59 "sender='org.chromium.flimflam'," |
| 60 "interface='" DBUS_IFACE_CONNMAN_MANAGER "'," | 60 "interface='" DBUS_IFACE_FLIMFLAM_MANAGER "'," |
| 61 "path='/'," | 61 "path='/'," |
| 62 "member='StateChanged'", | 62 "member='StateChanged'", |
| 63 | 63 |
| 64 "type='signal'," | 64 "type='signal'," |
| 65 "interface='" DBUS_IFACE_POWER_MANAGER "'," | 65 "interface='" DBUS_IFACE_POWER_MANAGER "'," |
| 66 "path='/'," | 66 "path='/'," |
| 67 "member='PowerStateChanged'", | 67 "member='PowerStateChanged'", |
| 68 | 68 |
| 69 "type='signal'," | 69 "type='signal'," |
| 70 "interface='" DBUS_IFACE_SCREENSAVER_MANAGER "'," | 70 "interface='" DBUS_IFACE_SCREENSAVER_MANAGER "'," |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 166 } | 166 } |
| 167 | 167 |
| 168 // Signal messages always have interfaces. | 168 // Signal messages always have interfaces. |
| 169 const char* interface = dbus_message_get_interface(message); | 169 const char* interface = dbus_message_get_interface(message); |
| 170 CHECK(interface != NULL); | 170 CHECK(interface != NULL); |
| 171 | 171 |
| 172 MetricsDaemon* daemon = static_cast<MetricsDaemon*>(user_data); | 172 MetricsDaemon* daemon = static_cast<MetricsDaemon*>(user_data); |
| 173 | 173 |
| 174 DBusMessageIter iter; | 174 DBusMessageIter iter; |
| 175 dbus_message_iter_init(message, &iter); | 175 dbus_message_iter_init(message, &iter); |
| 176 if (strcmp(interface, DBUS_IFACE_CONNMAN_MANAGER) == 0) { | 176 if (strcmp(interface, DBUS_IFACE_FLIMFLAM_MANAGER) == 0) { |
| 177 CHECK(strcmp(dbus_message_get_member(message), | 177 CHECK(strcmp(dbus_message_get_member(message), |
| 178 "StateChanged") == 0); | 178 "StateChanged") == 0); |
| 179 | 179 |
| 180 char *state_name; | 180 char *state_name; |
| 181 dbus_message_iter_get_basic(&iter, &state_name); | 181 dbus_message_iter_get_basic(&iter, &state_name); |
| 182 daemon->NetStateChanged(state_name, ticks); | 182 daemon->NetStateChanged(state_name, ticks); |
| 183 } else if (strcmp(interface, DBUS_IFACE_POWER_MANAGER) == 0) { | 183 } else if (strcmp(interface, DBUS_IFACE_POWER_MANAGER) == 0) { |
| 184 CHECK(strcmp(dbus_message_get_member(message), | 184 CHECK(strcmp(dbus_message_get_member(message), |
| 185 "PowerStateChanged") == 0); | 185 "PowerStateChanged") == 0); |
| 186 | 186 |
| (...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 usemon_source_ = NULL; | 454 usemon_source_ = NULL; |
| 455 usemon_interval_ = 0; | 455 usemon_interval_ = 0; |
| 456 } | 456 } |
| 457 | 457 |
| 458 void MetricsDaemon::SendMetric(const std::string& name, int sample, | 458 void MetricsDaemon::SendMetric(const std::string& name, int sample, |
| 459 int min, int max, int nbuckets) { | 459 int min, int max, int nbuckets) { |
| 460 DLOG(INFO) << "received metric: " << name << " " << sample << " " | 460 DLOG(INFO) << "received metric: " << name << " " << sample << " " |
| 461 << min << " " << max << " " << nbuckets; | 461 << min << " " << max << " " << nbuckets; |
| 462 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets); | 462 metrics_lib_->SendToUMA(name, sample, min, max, nbuckets); |
| 463 } | 463 } |
| OLD | NEW |