| 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 #ifndef METRICS_DAEMON_H_ | 5 #ifndef METRICS_DAEMON_H_ |
| 6 #define METRICS_DAEMON_H_ | 6 #define METRICS_DAEMON_H_ |
| 7 | 7 |
| 8 #include <dbus/dbus.h> | 8 #include <dbus/dbus.h> |
| 9 #include <glib.h> | 9 #include <glib.h> |
| 10 | 10 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // Initializes. | 25 // Initializes. |
| 26 void Init(bool testing, MetricsLibraryInterface* metrics_lib); | 26 void Init(bool testing, MetricsLibraryInterface* metrics_lib); |
| 27 | 27 |
| 28 // Does all the work. If |run_as_daemon| is true, daemonizes by | 28 // Does all the work. If |run_as_daemon| is true, daemonizes by |
| 29 // forking. | 29 // forking. |
| 30 void Run(bool run_as_daemon); | 30 void Run(bool run_as_daemon); |
| 31 | 31 |
| 32 private: | 32 private: |
| 33 friend class MetricsDaemonTest; | 33 friend class MetricsDaemonTest; |
| 34 FRIEND_TEST(MetricsDaemonTest, CheckKernelCrash); |
| 34 FRIEND_TEST(MetricsDaemonTest, DailyUseReporter); | 35 FRIEND_TEST(MetricsDaemonTest, DailyUseReporter); |
| 36 FRIEND_TEST(MetricsDaemonTest, KernelCrashIntervalReporter); |
| 35 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState); | 37 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState); |
| 36 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); | 38 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); |
| 37 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); | 39 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); |
| 38 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); | 40 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); |
| 39 FRIEND_TEST(MetricsDaemonTest, MessageFilter); | 41 FRIEND_TEST(MetricsDaemonTest, MessageFilter); |
| 40 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop); | 42 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop); |
| 41 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend); | 43 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend); |
| 42 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); | 44 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); |
| 45 FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash); |
| 43 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash); | 46 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash); |
| 44 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); | 47 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); |
| 45 FRIEND_TEST(MetricsDaemonTest, SendMetric); | 48 FRIEND_TEST(MetricsDaemonTest, SendMetric); |
| 46 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); | 49 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); |
| 47 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState); | 50 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState); |
| 48 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump); | 51 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump); |
| 49 FRIEND_TEST(MetricsDaemonTest, UserCrashIntervalReporter); | 52 FRIEND_TEST(MetricsDaemonTest, UserCrashIntervalReporter); |
| 50 | 53 |
| 51 // The network states (see network_states.h). | 54 // The network states (see network_states.h). |
| 52 enum NetworkState { | 55 enum NetworkState { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 78 UseRecord() : day_(0), seconds_(0) {} | 81 UseRecord() : day_(0), seconds_(0) {} |
| 79 int day_; | 82 int day_; |
| 80 int seconds_; | 83 int seconds_; |
| 81 }; | 84 }; |
| 82 | 85 |
| 83 // Metric parameters. | 86 // Metric parameters. |
| 84 static const char kMetricDailyUseTimeName[]; | 87 static const char kMetricDailyUseTimeName[]; |
| 85 static const int kMetricDailyUseTimeMin; | 88 static const int kMetricDailyUseTimeMin; |
| 86 static const int kMetricDailyUseTimeMax; | 89 static const int kMetricDailyUseTimeMax; |
| 87 static const int kMetricDailyUseTimeBuckets; | 90 static const int kMetricDailyUseTimeBuckets; |
| 91 static const char kMetricKernelCrashIntervalName[]; |
| 92 static const int kMetricKernelCrashIntervalMin; |
| 93 static const int kMetricKernelCrashIntervalMax; |
| 94 static const int kMetricKernelCrashIntervalBuckets; |
| 88 static const char kMetricTimeToNetworkDropName[]; | 95 static const char kMetricTimeToNetworkDropName[]; |
| 89 static const int kMetricTimeToNetworkDropMin; | 96 static const int kMetricTimeToNetworkDropMin; |
| 90 static const int kMetricTimeToNetworkDropMax; | 97 static const int kMetricTimeToNetworkDropMax; |
| 91 static const int kMetricTimeToNetworkDropBuckets; | 98 static const int kMetricTimeToNetworkDropBuckets; |
| 92 static const char kMetricUserCrashIntervalName[]; | 99 static const char kMetricUserCrashIntervalName[]; |
| 93 static const int kMetricUserCrashIntervalMin; | 100 static const int kMetricUserCrashIntervalMin; |
| 94 static const int kMetricUserCrashIntervalMax; | 101 static const int kMetricUserCrashIntervalMax; |
| 95 static const int kMetricUserCrashIntervalBuckets; | 102 static const int kMetricUserCrashIntervalBuckets; |
| 96 | 103 |
| 97 // D-Bus message match strings. | 104 // D-Bus message match strings. |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 // of active use to the |day| since Epoch. If there's usage data for | 152 // of active use to the |day| since Epoch. If there's usage data for |
| 146 // day in the past in the usage file, that data is sent to UMA and | 153 // day in the past in the usage file, that data is sent to UMA and |
| 147 // removed from the file. If there's already usage data for |day| in | 154 // removed from the file. If there's already usage data for |day| in |
| 148 // the usage file, the |seconds| are accumulated. | 155 // the usage file, the |seconds| are accumulated. |
| 149 void LogDailyUseRecord(int day, int seconds); | 156 void LogDailyUseRecord(int day, int seconds); |
| 150 | 157 |
| 151 // Updates the active use time and logs time between user-space | 158 // Updates the active use time and logs time between user-space |
| 152 // process crashes. | 159 // process crashes. |
| 153 void ProcessUserCrash(); | 160 void ProcessUserCrash(); |
| 154 | 161 |
| 162 // Updates the active use time and logs time between kernel crashes. |
| 163 void ProcessKernelCrash(); |
| 164 |
| 165 // Checks if a kernel crash has been detected and processes if so. |
| 166 // The method assumes that a kernel crash has happened if |
| 167 // |crash_file| exists. |
| 168 void CheckKernelCrash(const std::string& crash_file); |
| 169 |
| 155 // Callbacks for the daily use monitor. The daily use monitor uses | 170 // Callbacks for the daily use monitor. The daily use monitor uses |
| 156 // LogDailyUseRecord to aggregate current usage data and send it to | 171 // LogDailyUseRecord to aggregate current usage data and send it to |
| 157 // UMA, if necessary. It also reschedules itself using an | 172 // UMA, if necessary. It also reschedules itself using an |
| 158 // exponentially bigger interval (up to a certain maximum) -- so | 173 // exponentially bigger interval (up to a certain maximum) -- so |
| 159 // usage is monitored less frequently with longer active use. | 174 // usage is monitored less frequently with longer active use. |
| 160 static gboolean UseMonitorStatic(gpointer data); | 175 static gboolean UseMonitorStatic(gpointer data); |
| 161 bool UseMonitor(); | 176 bool UseMonitor(); |
| 162 | 177 |
| 163 // Schedules or reschedules a daily use monitor for |interval| | 178 // Schedules or reschedules a daily use monitor for |interval| |
| 164 // seconds from now. |backoff| mode is used by the use monitor to | 179 // seconds from now. |backoff| mode is used by the use monitor to |
| (...skipping 15 matching lines...) Expand all Loading... |
| 180 int min, int max, int nbuckets); | 195 int min, int max, int nbuckets); |
| 181 | 196 |
| 182 // TaggedCounter callback to process aggregated daily usage data and | 197 // TaggedCounter callback to process aggregated daily usage data and |
| 183 // send to UMA. | 198 // send to UMA. |
| 184 static void DailyUseReporter(void* data, int tag, int count); | 199 static void DailyUseReporter(void* data, int tag, int count); |
| 185 | 200 |
| 186 // TaggedCounter callback to process time between user-space process | 201 // TaggedCounter callback to process time between user-space process |
| 187 // crashes and send to UMA. | 202 // crashes and send to UMA. |
| 188 static void UserCrashIntervalReporter(void* data, int tag, int count); | 203 static void UserCrashIntervalReporter(void* data, int tag, int count); |
| 189 | 204 |
| 205 // TaggedCounter callback to process time between kernel crashes and |
| 206 // send to UMA. |
| 207 static void KernelCrashIntervalReporter(void* data, int tag, int count); |
| 208 |
| 190 // Test mode. | 209 // Test mode. |
| 191 bool testing_; | 210 bool testing_; |
| 192 | 211 |
| 193 // The metrics library handle. | 212 // The metrics library handle. |
| 194 MetricsLibraryInterface* metrics_lib_; | 213 MetricsLibraryInterface* metrics_lib_; |
| 195 | 214 |
| 196 // Current network state. | 215 // Current network state. |
| 197 NetworkState network_state_; | 216 NetworkState network_state_; |
| 198 | 217 |
| 199 // Timestamps last network state update. This timestamp is used to | 218 // Timestamps last network state update. This timestamp is used to |
| (...skipping 15 matching lines...) Expand all Loading... |
| 215 // each day before sending to UMA so using time since the epoch as | 234 // each day before sending to UMA so using time since the epoch as |
| 216 // the timestamp. | 235 // the timestamp. |
| 217 base::Time user_active_last_; | 236 base::Time user_active_last_; |
| 218 | 237 |
| 219 // Daily active use time in seconds. | 238 // Daily active use time in seconds. |
| 220 scoped_ptr<chromeos_metrics::TaggedCounterInterface> daily_use_; | 239 scoped_ptr<chromeos_metrics::TaggedCounterInterface> daily_use_; |
| 221 | 240 |
| 222 // Active use time between user-space process crashes. | 241 // Active use time between user-space process crashes. |
| 223 scoped_ptr<chromeos_metrics::TaggedCounterInterface> user_crash_interval_; | 242 scoped_ptr<chromeos_metrics::TaggedCounterInterface> user_crash_interval_; |
| 224 | 243 |
| 244 // Active use time between kernel crashes. |
| 245 scoped_ptr<chromeos_metrics::TaggedCounterInterface> kernel_crash_interval_; |
| 246 |
| 225 // Sleep period until the next daily usage aggregation performed by | 247 // Sleep period until the next daily usage aggregation performed by |
| 226 // the daily use monitor (see ScheduleUseMonitor). | 248 // the daily use monitor (see ScheduleUseMonitor). |
| 227 int usemon_interval_; | 249 int usemon_interval_; |
| 228 | 250 |
| 229 // Scheduled daily use monitor source (see ScheduleUseMonitor). | 251 // Scheduled daily use monitor source (see ScheduleUseMonitor). |
| 230 GSource* usemon_source_; | 252 GSource* usemon_source_; |
| 231 }; | 253 }; |
| 232 | 254 |
| 233 #endif // METRICS_DAEMON_H_ | 255 #endif // METRICS_DAEMON_H_ |
| OLD | NEW |