| 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 #include <map> | 10 #include <map> |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 // forking. | 35 // forking. |
| 36 void Run(bool run_as_daemon); | 36 void Run(bool run_as_daemon); |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 friend class MetricsDaemonTest; | 39 friend class MetricsDaemonTest; |
| 40 FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash); | 40 FRIEND_TEST(MetricsDaemonTest, CheckSystemCrash); |
| 41 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoCurrent); | 41 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoCurrent); |
| 42 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast); | 42 FRIEND_TEST(MetricsDaemonTest, ComputeEpochNoLast); |
| 43 FRIEND_TEST(MetricsDaemonTest, GetHistogramPath); | 43 FRIEND_TEST(MetricsDaemonTest, GetHistogramPath); |
| 44 FRIEND_TEST(MetricsDaemonTest, IsNewEpoch); | 44 FRIEND_TEST(MetricsDaemonTest, IsNewEpoch); |
| 45 FRIEND_TEST(MetricsDaemonTest, LookupNetworkState); | |
| 46 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); | 45 FRIEND_TEST(MetricsDaemonTest, LookupPowerState); |
| 47 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); | 46 FRIEND_TEST(MetricsDaemonTest, LookupScreenSaverState); |
| 48 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); | 47 FRIEND_TEST(MetricsDaemonTest, LookupSessionState); |
| 49 FRIEND_TEST(MetricsDaemonTest, MessageFilter); | 48 FRIEND_TEST(MetricsDaemonTest, MessageFilter); |
| 50 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSimpleDrop); | |
| 51 FRIEND_TEST(MetricsDaemonTest, NetStateChangedSuspend); | |
| 52 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); | 49 FRIEND_TEST(MetricsDaemonTest, PowerStateChanged); |
| 53 FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash); | 50 FRIEND_TEST(MetricsDaemonTest, ProcessKernelCrash); |
| 54 FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown); | 51 FRIEND_TEST(MetricsDaemonTest, ProcessUncleanShutdown); |
| 55 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash); | 52 FRIEND_TEST(MetricsDaemonTest, ProcessUserCrash); |
| 56 FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency); | 53 FRIEND_TEST(MetricsDaemonTest, ReportCrashesDailyFrequency); |
| 57 FRIEND_TEST(MetricsDaemonTest, ReportDailyUse); | 54 FRIEND_TEST(MetricsDaemonTest, ReportDailyUse); |
| 58 FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval); | 55 FRIEND_TEST(MetricsDaemonTest, ReportKernelCrashInterval); |
| 59 FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval); | 56 FRIEND_TEST(MetricsDaemonTest, ReportUncleanShutdownInterval); |
| 60 FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval); | 57 FRIEND_TEST(MetricsDaemonTest, ReportUserCrashInterval); |
| 61 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); | 58 FRIEND_TEST(MetricsDaemonTest, ScreenSaverStateChanged); |
| 62 FRIEND_TEST(MetricsDaemonTest, SendMetric); | 59 FRIEND_TEST(MetricsDaemonTest, SendMetric); |
| 63 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); | 60 FRIEND_TEST(MetricsDaemonTest, SessionStateChanged); |
| 64 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState); | 61 FRIEND_TEST(MetricsDaemonTest, SetUserActiveState); |
| 65 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump); | 62 FRIEND_TEST(MetricsDaemonTest, SetUserActiveStateTimeJump); |
| 66 | 63 |
| 67 // The network states (see network_states.h). | |
| 68 enum NetworkState { | |
| 69 kUnknownNetworkState = -1, // Initial/unknown network state. | |
| 70 #define STATE(name, capname) kNetworkState ## capname, | |
| 71 #include "network_states.h" | |
| 72 kNumberNetworkStates | |
| 73 }; | |
| 74 | |
| 75 // The power states (see power_states.h). | 64 // The power states (see power_states.h). |
| 76 enum PowerState { | 65 enum PowerState { |
| 77 kUnknownPowerState = -1, // Initial/unknown power state. | 66 kUnknownPowerState = -1, // Initial/unknown power state. |
| 78 #define STATE(name, capname) kPowerState ## capname, | 67 #define STATE(name, capname) kPowerState ## capname, |
| 79 #include "power_states.h" | 68 #include "power_states.h" |
| 80 kNumberPowerStates | 69 kNumberPowerStates |
| 81 }; | 70 }; |
| 82 | 71 |
| 83 // The user session states (see session_states.h). | 72 // The user session states (see session_states.h). |
| 84 enum SessionState { | 73 enum SessionState { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 109 static const int kMetricCrashIntervalMax; | 98 static const int kMetricCrashIntervalMax; |
| 110 static const int kMetricCrashIntervalMin; | 99 static const int kMetricCrashIntervalMin; |
| 111 static const int kMetricDailyUseTimeBuckets; | 100 static const int kMetricDailyUseTimeBuckets; |
| 112 static const int kMetricDailyUseTimeMax; | 101 static const int kMetricDailyUseTimeMax; |
| 113 static const int kMetricDailyUseTimeMin; | 102 static const int kMetricDailyUseTimeMin; |
| 114 static const char kMetricDailyUseTimeName[]; | 103 static const char kMetricDailyUseTimeName[]; |
| 115 static const char kMetricKernelCrashesDailyName[]; | 104 static const char kMetricKernelCrashesDailyName[]; |
| 116 static const char kMetricKernelCrashesWeeklyName[]; | 105 static const char kMetricKernelCrashesWeeklyName[]; |
| 117 static const char kMetricKernelCrashIntervalName[]; | 106 static const char kMetricKernelCrashIntervalName[]; |
| 118 static const char kMetricsPath[]; | 107 static const char kMetricsPath[]; |
| 119 static const int kMetricTimeToNetworkDropBuckets; | |
| 120 static const int kMetricTimeToNetworkDropMax; | |
| 121 static const int kMetricTimeToNetworkDropMin; | |
| 122 static const char kMetricTimeToNetworkDropName[]; | |
| 123 static const char kMetricUncleanShutdownIntervalName[]; | 108 static const char kMetricUncleanShutdownIntervalName[]; |
| 124 static const char kMetricUncleanShutdownsDailyName[]; | 109 static const char kMetricUncleanShutdownsDailyName[]; |
| 125 static const char kMetricUncleanShutdownsWeeklyName[]; | 110 static const char kMetricUncleanShutdownsWeeklyName[]; |
| 126 static const char kMetricUserCrashesDailyName[]; | 111 static const char kMetricUserCrashesDailyName[]; |
| 127 static const char kMetricUserCrashesWeeklyName[]; | 112 static const char kMetricUserCrashesWeeklyName[]; |
| 128 static const char kMetricUserCrashIntervalName[]; | 113 static const char kMetricUserCrashIntervalName[]; |
| 129 | 114 |
| 130 // D-Bus message match strings. | 115 // D-Bus message match strings. |
| 131 static const char* kDBusMatches_[]; | 116 static const char* kDBusMatches_[]; |
| 132 | 117 |
| 133 // Array of network states. | |
| 134 static const char* kNetworkStates_[kNumberNetworkStates]; | |
| 135 | |
| 136 // Array of power states. | 118 // Array of power states. |
| 137 static const char* kPowerStates_[kNumberPowerStates]; | 119 static const char* kPowerStates_[kNumberPowerStates]; |
| 138 | 120 |
| 139 // Array of user session states. | 121 // Array of user session states. |
| 140 static const char* kSessionStates_[kNumberSessionStates]; | 122 static const char* kSessionStates_[kNumberSessionStates]; |
| 141 | 123 |
| 142 // Clears and deletes the data contained in frequency_counters_. | 124 // Clears and deletes the data contained in frequency_counters_. |
| 143 void DeleteFrequencyCounters(); | 125 void DeleteFrequencyCounters(); |
| 144 | 126 |
| 145 // Configures the given crash interval reporter. | 127 // Configures the given crash interval reporter. |
| 146 void ConfigureCrashIntervalReporter( | 128 void ConfigureCrashIntervalReporter( |
| 147 const char* histogram_name, | 129 const char* histogram_name, |
| 148 scoped_ptr<chromeos_metrics::TaggedCounterReporter>* reporter); | 130 scoped_ptr<chromeos_metrics::TaggedCounterReporter>* reporter); |
| 149 | 131 |
| 150 // Configures the given frequency counter reporter. | 132 // Configures the given frequency counter reporter. |
| 151 void ConfigureCrashFrequencyReporter(const char* histogram_name); | 133 void ConfigureCrashFrequencyReporter(const char* histogram_name); |
| 152 | 134 |
| 153 // Returns file path to persistent file for generating given histogram. | 135 // Returns file path to persistent file for generating given histogram. |
| 154 FilePath GetHistogramPath(const char* histogram_name); | 136 FilePath GetHistogramPath(const char* histogram_name); |
| 155 | 137 |
| 156 // Creates the event loop and enters it. | 138 // Creates the event loop and enters it. |
| 157 void Loop(); | 139 void Loop(); |
| 158 | 140 |
| 159 // D-Bus filter callback. | 141 // D-Bus filter callback. |
| 160 static DBusHandlerResult MessageFilter(DBusConnection* connection, | 142 static DBusHandlerResult MessageFilter(DBusConnection* connection, |
| 161 DBusMessage* message, | 143 DBusMessage* message, |
| 162 void* user_data); | 144 void* user_data); |
| 163 | 145 |
| 164 // Processes network state change. | |
| 165 void NetStateChanged(const char* state_name, base::TimeTicks ticks); | |
| 166 | |
| 167 // Given the state name, returns the state id. | |
| 168 NetworkState LookupNetworkState(const char* state_name); | |
| 169 | |
| 170 // Processes power state change. | 146 // Processes power state change. |
| 171 void PowerStateChanged(const char* state_name, base::Time now); | 147 void PowerStateChanged(const char* state_name, base::Time now); |
| 172 | 148 |
| 173 // Given the state name, returns the state id. | 149 // Given the state name, returns the state id. |
| 174 PowerState LookupPowerState(const char* state_name); | 150 PowerState LookupPowerState(const char* state_name); |
| 175 | 151 |
| 176 // Processes user session state change. | 152 // Processes user session state change. |
| 177 void SessionStateChanged(const char* state_name, base::Time now); | 153 void SessionStateChanged(const char* state_name, base::Time now); |
| 178 | 154 |
| 179 // Given the state name, returns the state id. | 155 // Given the state name, returns the state id. |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 240 // metrics_library.h for a description of the arguments. | 216 // metrics_library.h for a description of the arguments. |
| 241 void SendMetric(const std::string& name, int sample, | 217 void SendMetric(const std::string& name, int sample, |
| 242 int min, int max, int nbuckets); | 218 int min, int max, int nbuckets); |
| 243 | 219 |
| 244 // Test mode. | 220 // Test mode. |
| 245 bool testing_; | 221 bool testing_; |
| 246 | 222 |
| 247 // The metrics library handle. | 223 // The metrics library handle. |
| 248 MetricsLibraryInterface* metrics_lib_; | 224 MetricsLibraryInterface* metrics_lib_; |
| 249 | 225 |
| 250 // Current network state. | |
| 251 NetworkState network_state_; | |
| 252 | |
| 253 // Timestamps last network state update. This timestamp is used to | 226 // Timestamps last network state update. This timestamp is used to |
| 254 // sample the time from the network going online to going offline so | 227 // sample the time from the network going online to going offline so |
| 255 // TimeTicks ensures a monotonically increasing TimeDelta. | 228 // TimeTicks ensures a monotonically increasing TimeDelta. |
| 256 base::TimeTicks network_state_last_; | 229 base::TimeTicks network_state_last_; |
| 257 | 230 |
| 258 // Current power state. | 231 // Current power state. |
| 259 PowerState power_state_; | 232 PowerState power_state_; |
| 260 | 233 |
| 261 // Current user session state. | 234 // Current user session state. |
| 262 SessionState session_state_; | 235 SessionState session_state_; |
| (...skipping 25 matching lines...) Expand all Loading... |
| 288 | 261 |
| 289 // Sleep period until the next daily usage aggregation performed by | 262 // Sleep period until the next daily usage aggregation performed by |
| 290 // the daily use monitor (see ScheduleUseMonitor). | 263 // the daily use monitor (see ScheduleUseMonitor). |
| 291 int usemon_interval_; | 264 int usemon_interval_; |
| 292 | 265 |
| 293 // Scheduled daily use monitor source (see ScheduleUseMonitor). | 266 // Scheduled daily use monitor source (see ScheduleUseMonitor). |
| 294 GSource* usemon_source_; | 267 GSource* usemon_source_; |
| 295 }; | 268 }; |
| 296 | 269 |
| 297 #endif // METRICS_DAEMON_H_ | 270 #endif // METRICS_DAEMON_H_ |
| OLD | NEW |