Thieu Le | 3426c8f | 2012-01-11 17:35:11 -0800 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium OS Authors. All rights reserved. |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #ifndef SHILL_METRICS_ |
| 6 | #define SHILL_METRICS_ |
| 7 | |
| 8 | #include <list> |
| 9 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 10 | #include <base/memory/scoped_vector.h> |
| 11 | #include <metrics/metrics_library.h> |
| 12 | #include <metrics/timer.h> |
| 13 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 14 | #include "shill/event_dispatcher.h" |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 15 | #include "shill/ieee80211.h" |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 16 | #include "shill/portal_detector.h" |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 17 | #include "shill/power_manager.h" |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 18 | #include "shill/refptr_types.h" |
| 19 | #include "shill/service.h" |
| 20 | |
| 21 | namespace shill { |
| 22 | |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 23 | class WiFiMainTest; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 24 | class WiFiService; |
| 25 | |
| 26 | class Metrics { |
| 27 | public: |
| 28 | enum WiFiChannel { |
| 29 | kWiFiChannelUndef = 0, |
| 30 | kWiFiChannel2412 = 1, |
| 31 | kWiFiChannel2417 = 2, |
| 32 | kWiFiChannel2422 = 3, |
| 33 | kWiFiChannel2427 = 4, |
| 34 | kWiFiChannel2432 = 5, |
| 35 | kWiFiChannel2437 = 6, |
| 36 | kWiFiChannel2442 = 7, |
| 37 | kWiFiChannel2447 = 8, |
| 38 | kWiFiChannel2452 = 9, |
| 39 | kWiFiChannel2457 = 10, |
| 40 | kWiFiChannel2462 = 11, |
| 41 | kWiFiChannel2467 = 12, |
| 42 | kWiFiChannel2472 = 13, |
| 43 | kWiFiChannel2484 = 14, |
| 44 | |
| 45 | kWiFiChannel5180 = 15, |
| 46 | kWiFiChannel5200 = 16, |
| 47 | kWiFiChannel5220 = 17, |
| 48 | kWiFiChannel5240 = 18, |
| 49 | kWiFiChannel5260 = 19, |
| 50 | kWiFiChannel5280 = 20, |
| 51 | kWiFiChannel5300 = 21, |
| 52 | kWiFiChannel5320 = 22, |
| 53 | |
| 54 | kWiFiChannel5500 = 23, |
| 55 | kWiFiChannel5520 = 24, |
| 56 | kWiFiChannel5540 = 25, |
| 57 | kWiFiChannel5560 = 26, |
| 58 | kWiFiChannel5580 = 27, |
| 59 | kWiFiChannel5600 = 28, |
| 60 | kWiFiChannel5620 = 29, |
| 61 | kWiFiChannel5640 = 30, |
| 62 | kWiFiChannel5660 = 31, |
| 63 | kWiFiChannel5680 = 32, |
| 64 | kWiFiChannel5700 = 33, |
| 65 | |
| 66 | kWiFiChannel5745 = 34, |
| 67 | kWiFiChannel5765 = 35, |
| 68 | kWiFiChannel5785 = 36, |
| 69 | kWiFiChannel5805 = 37, |
| 70 | kWiFiChannel5825 = 38, |
| 71 | |
| 72 | kWiFiChannel5170 = 39, |
| 73 | kWiFiChannel5190 = 40, |
| 74 | kWiFiChannel5210 = 41, |
| 75 | kWiFiChannel5230 = 42, |
| 76 | |
| 77 | /* NB: ignore old 11b bands 2312..2372 and 2512..2532 */ |
| 78 | /* NB: ignore regulated bands 4920..4980 and 5020..5160 */ |
| 79 | kWiFiChannelMax |
| 80 | }; |
| 81 | |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 82 | enum WiFiNetworkPhyMode { |
| 83 | kWiFiNetworkPhyModeUndef = 0, // Unknown/undefined |
| 84 | kWiFiNetworkPhyMode11a = 1, // 802.11a |
| 85 | kWiFiNetworkPhyMode11b = 2, // 802.11b |
| 86 | kWiFiNetworkPhyMode11g = 3, // 802.11g |
| 87 | kWiFiNetworkPhyMode11n = 4, // 802.11n |
| 88 | kWiFiNetworkPhyModeHalf = 5, // PSB Half-width |
| 89 | kWiFiNetworkPhyModeQuarter = 6, // PSB Quarter-width |
| 90 | kWiFiNetworkPhyModeTurbo = 7, // Atheros Turbo mode |
| 91 | |
| 92 | kWiFiNetworkPhyModeMax |
| 93 | }; |
| 94 | |
| 95 | enum WiFiSecurity { |
| 96 | kWiFiSecurityUnknown = 0, |
| 97 | kWiFiSecurityNone = 1, |
| 98 | kWiFiSecurityWep = 2, |
| 99 | kWiFiSecurityWpa = 3, |
| 100 | kWiFiSecurityRsn = 4, |
| 101 | kWiFiSecurity8021x = 5, |
| 102 | kWiFiSecurityPsk = 6, |
| 103 | |
| 104 | kWiFiSecurityMax |
| 105 | }; |
| 106 | |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 107 | enum PortalResult { |
| 108 | kPortalResultSuccess = 0, |
| 109 | kPortalResultDNSFailure = 1, |
| 110 | kPortalResultDNSTimeout = 2, |
| 111 | kPortalResultConnectionFailure = 3, |
| 112 | kPortalResultConnectionTimeout = 4, |
| 113 | kPortalResultHTTPFailure = 5, |
| 114 | kPortalResultHTTPTimeout = 6, |
| 115 | kPortalResultContentFailure = 7, |
| 116 | kPortalResultContentTimeout = 8, |
| 117 | kPortalResultUnknown = 9, |
| 118 | |
| 119 | kPortalResultMax |
| 120 | }; |
| 121 | |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 122 | enum LinkMonitorFailure { |
| 123 | kLinkMonitorMacAddressNotFound = 0, |
| 124 | kLinkMonitorClientStartFailure = 1, |
| 125 | kLinkMonitorTransmitFailure = 2, |
| 126 | kLinkMonitorFailureThresholdReached = 3, |
| 127 | |
| 128 | kLinkMonitorFailureMax |
| 129 | }; |
| 130 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 131 | enum WiFiStatusType { |
| 132 | kStatusCodeTypeByAp, |
| 133 | kStatusCodeTypeByClient, |
| 134 | kStatusCodeTypeByUser, |
| 135 | kStatusCodeTypeConsideredDead, |
| 136 | kStatusCodeTypeMax |
| 137 | }; |
| 138 | |
| 139 | enum WiFiDisconnectByWhom { |
| 140 | kDisconnectedByAp, |
| 141 | kDisconnectedNotByAp |
| 142 | }; |
| 143 | |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 144 | enum ServiceFixupProfileType { |
| 145 | kMetricServiceFixupDefaultProfile, |
| 146 | kMetricServiceFixupUserProfile, |
| 147 | kMetricServiceFixupMax |
| 148 | }; |
| 149 | |
Arman Uguray | 6d528f1 | 2012-09-13 13:44:55 -0700 | [diff] [blame] | 150 | enum TerminationActionResult { |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 151 | kTerminationActionResultSuccess, |
| 152 | kTerminationActionResultFailure, |
Arman Uguray | 6d528f1 | 2012-09-13 13:44:55 -0700 | [diff] [blame] | 153 | kTerminationActionResultMax |
| 154 | }; |
| 155 | |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 156 | enum TerminationActionReason { |
| 157 | kTerminationActionReasonSuspend, |
| 158 | kTerminationActionReasonTerminate |
| 159 | }; |
| 160 | |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 161 | enum CellularDropTechnology { |
| 162 | kCellularDropTechnology1Xrtt = 0, |
| 163 | kCellularDropTechnologyEdge = 1, |
| 164 | kCellularDropTechnologyEvdo = 2, |
| 165 | kCellularDropTechnologyGprs = 3, |
| 166 | kCellularDropTechnologyGsm = 4, |
| 167 | kCellularDropTechnologyHspa = 5, |
| 168 | kCellularDropTechnologyHspaPlus = 6, |
| 169 | kCellularDropTechnologyLte = 7, |
| 170 | kCellularDropTechnologyUmts = 8, |
| 171 | kCellularDropTechnologyUnknown = 9, |
| 172 | kCellularDropTechnologyMax |
| 173 | }; |
| 174 | |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 175 | static const char kMetricDisconnect[]; |
| 176 | static const int kMetricDisconnectMax; |
| 177 | static const int kMetricDisconnectMin; |
| 178 | static const int kMetricDisconnectNumBuckets; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 179 | static const char kMetricNetworkChannel[]; |
| 180 | static const int kMetricNetworkChannelMax; |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 181 | static const char kMetricNetworkPhyMode[]; |
| 182 | static const int kMetricNetworkPhyModeMax; |
| 183 | static const char kMetricNetworkSecurity[]; |
| 184 | static const int kMetricNetworkSecurityMax; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 185 | static const char kMetricNetworkServiceErrors[]; |
| 186 | static const int kMetricNetworkServiceErrorsMax; |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 187 | static const char kMetricNetworkSignalStrength[]; |
| 188 | static const int kMetricNetworkSignalStrengthMin; |
| 189 | static const int kMetricNetworkSignalStrengthMax; |
| 190 | static const int kMetricNetworkSignalStrengthNumBuckets; |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 191 | static const char kMetricTimeOnlineSeconds[]; |
| 192 | static const int kMetricTimeOnlineSecondsMax; |
| 193 | static const int kMetricTimeOnlineSecondsMin; |
| 194 | static const int kMetricTimeOnlineSecondsNumBuckets; |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 195 | static const char kMetricTimeResumeToReadyMilliseconds[]; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 196 | static const char kMetricTimeToConfigMilliseconds[]; |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 197 | static const char kMetricTimeToConnectMilliseconds[]; |
| 198 | static const int kMetricTimeToConnectMillisecondsMax; |
| 199 | static const int kMetricTimeToConnectMillisecondsMin; |
| 200 | static const int kMetricTimeToConnectMillisecondsNumBuckets; |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 201 | static const char kMetricTimeToDropSeconds[]; |
| 202 | static const int kMetricTimeToDropSecondsMax; |
| 203 | static const int kMetricTimeToDropSecondsMin; |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 204 | static const char kMetricTimeToDisableMilliseconds[]; |
| 205 | static const int kMetricTimeToDisableMillisecondsMax; |
| 206 | static const int kMetricTimeToDisableMillisecondsMin; |
| 207 | static const int kMetricTimeToDisableMillisecondsNumBuckets; |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 208 | static const char kMetricTimeToEnableMilliseconds[]; |
| 209 | static const int kMetricTimeToEnableMillisecondsMax; |
| 210 | static const int kMetricTimeToEnableMillisecondsMin; |
| 211 | static const int kMetricTimeToEnableMillisecondsNumBuckets; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 212 | static const char kMetricTimeToInitializeMilliseconds[]; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 213 | static const int kMetricTimeToInitializeMillisecondsMax; |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 214 | static const int kMetricTimeToInitializeMillisecondsMin; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 215 | static const int kMetricTimeToInitializeMillisecondsNumBuckets; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 216 | static const char kMetricTimeToJoinMilliseconds[]; |
| 217 | static const char kMetricTimeToOnlineMilliseconds[]; |
| 218 | static const char kMetricTimeToPortalMilliseconds[]; |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 219 | static const char kMetricTimeToScanMilliseconds[]; |
| 220 | static const int kMetricTimeToScanMillisecondsMax; |
| 221 | static const int kMetricTimeToScanMillisecondsMin; |
| 222 | static const int kMetricTimeToScanMillisecondsNumBuckets; |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 223 | static const int kTimerHistogramMillisecondsMax; |
| 224 | static const int kTimerHistogramMillisecondsMin; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 225 | static const int kTimerHistogramNumBuckets; |
| 226 | |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 227 | // The number of portal detections attempted for each pass. |
| 228 | // This includes both failure/timeout attempts and successful attempt |
| 229 | // (if any). |
| 230 | static const char kMetricPortalAttempts[]; |
| 231 | static const int kMetricPortalAttemptsMax; |
| 232 | static const int kMetricPortalAttemptsMin; |
| 233 | static const int kMetricPortalAttemptsNumBuckets; |
| 234 | |
| 235 | // The total number of portal detections attempted between the Connected |
| 236 | // state and the Online state. This includes both failure/timeout attempts |
| 237 | // and the final successful attempt. |
| 238 | static const char kMetricPortalAttemptsToOnline[]; |
| 239 | static const int kMetricPortalAttemptsToOnlineMax; |
| 240 | static const int kMetricPortalAttemptsToOnlineMin; |
| 241 | static const int kMetricPortalAttemptsToOnlineNumBuckets; |
| 242 | |
| 243 | // The result of the portal detection. |
| 244 | static const char kMetricPortalResult[]; |
| 245 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 246 | static const char kMetricPowerManagerKey[]; |
| 247 | |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 248 | // LinkMonitor statistics. |
| 249 | static const char kMetricLinkMonitorFailure[]; |
| 250 | static const char kMetricLinkMonitorResponseTimeSample[]; |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 251 | static const int kMetricLinkMonitorResponseTimeSampleMin; |
| 252 | static const int kMetricLinkMonitorResponseTimeSampleMax; |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 253 | static const int kMetricLinkMonitorResponseTimeSampleNumBuckets; |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 254 | static const char kMetricLinkMonitorSecondsToFailure[]; |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 255 | static const int kMetricLinkMonitorSecondsToFailureMin; |
| 256 | static const int kMetricLinkMonitorSecondsToFailureMax; |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 257 | static const int kMetricLinkMonitorSecondsToFailureNumBuckets; |
| 258 | static const char kMetricLinkMonitorBroadcastErrorsAtFailure[]; |
| 259 | static const char kMetricLinkMonitorUnicastErrorsAtFailure[]; |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 260 | static const int kMetricLinkMonitorErrorCountMin; |
| 261 | static const int kMetricLinkMonitorErrorCountMax; |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 262 | static const int kMetricLinkMonitorErrorCountNumBuckets; |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 263 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 264 | static const char kMetricLinkClientDisconnectReason[]; |
| 265 | static const char kMetricLinkApDisconnectReason[]; |
| 266 | static const char kMetricLinkClientDisconnectType[]; |
| 267 | static const char kMetricLinkApDisconnectType[]; |
| 268 | |
Arman Uguray | 6d528f1 | 2012-09-13 13:44:55 -0700 | [diff] [blame] | 269 | // Shill termination action statistics. |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 270 | static const char kMetricTerminationActionTimeOnTerminate[]; |
| 271 | static const char kMetricTerminationActionResultOnTerminate[]; |
| 272 | static const char kMetricTerminationActionTimeOnSuspend[]; |
| 273 | static const char kMetricTerminationActionResultOnSuspend[]; |
| 274 | static const int kMetricTerminationActionTimeMillisecondsMax; |
| 275 | static const int kMetricTerminationActionTimeMillisecondsMin; |
Arman Uguray | 6d528f1 | 2012-09-13 13:44:55 -0700 | [diff] [blame] | 276 | |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 277 | // WiFiService Entry Fixup. |
| 278 | static const char kMetricServiceFixupEntries[]; |
| 279 | |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 280 | // Cellular specific statistics. |
| 281 | static const char kMetricCellularDrop[]; |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 282 | static const char kMetricCellularDropsPerHour[]; |
| 283 | static const int kMetricCellularDropsPerHourMax; |
| 284 | static const int kMetricCellularDropsPerHourMin; |
| 285 | static const int kMetricCellularDropsPerHourNumBuckets; |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 286 | static const char kMetricCellularFailureReason[]; |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 287 | static const char kMetricCellularSignalStrengthBeforeDrop[]; |
| 288 | static const int kMetricCellularSignalStrengthBeforeDropMax; |
| 289 | static const int kMetricCellularSignalStrengthBeforeDropMin; |
| 290 | static const int kMetricCellularSignalStrengthBeforeDropNumBuckets; |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 291 | static const char kMetricCellularAutoConnectTries[]; |
| 292 | static const int kMetricCellularAutoConnectTriesMax; |
| 293 | static const int kMetricCellularAutoConnectTriesMin; |
| 294 | static const int kMetricCellularAutoConnectTriesNumBuckets; |
| 295 | static const char kMetricCellularAutoConnectTotalTime[]; |
| 296 | static const int kMetricCellularAutoConnectTotalTimeMax; |
| 297 | static const int kMetricCellularAutoConnectTotalTimeMin; |
| 298 | static const int kMetricCellularAutoConnectTotalTimeNumBuckets; |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 299 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 300 | explicit Metrics(EventDispatcher *dispatcher); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 301 | virtual ~Metrics(); |
| 302 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 303 | // Converts the WiFi frequency into the associated UMA channel enumerator. |
| 304 | static WiFiChannel WiFiFrequencyToChannel(uint16 frequency); |
| 305 | |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 306 | // Converts a flimflam security string into its UMA security enumerator. |
| 307 | static WiFiSecurity WiFiSecurityStringToEnum(const std::string &security); |
| 308 | |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 309 | // Converts portal detection result to UMA portal result enumerator. |
| 310 | static PortalResult PortalDetectionResultToEnum( |
| 311 | const PortalDetector::Result &result); |
| 312 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 313 | // Starts this object. Call this during initialization. |
| 314 | virtual void Start(); |
| 315 | |
| 316 | // Stops this object. Call this during cleanup. |
| 317 | virtual void Stop(); |
| 318 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 319 | // Registers a service with this object so it can use the timers to track |
| 320 | // state transition metrics. |
| 321 | void RegisterService(const Service *service); |
| 322 | |
| 323 | // Deregisters the service from this class. All state transition timers |
| 324 | // will be removed. |
| 325 | void DeregisterService(const Service *service); |
| 326 | |
| 327 | // Tracks the time it takes |service| to go from |start_state| to |
| 328 | // |stop_state|. When |stop_state| is reached, the time is sent to UMA. |
| 329 | void AddServiceStateTransitionTimer(const Service *service, |
| 330 | const std::string &histogram_name, |
| 331 | Service::ConnectState start_state, |
| 332 | Service::ConnectState stop_state); |
| 333 | |
| 334 | // Specializes |metric_name| for the specified |technology_id|. |
| 335 | std::string GetFullMetricName(const char *metric_name, |
| 336 | Technology::Identifier technology_id); |
| 337 | |
| 338 | // Notifies this object that the default service has changed. |
| 339 | // |service| is the new default service. |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 340 | virtual void NotifyDefaultServiceChanged(const Service *service); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 341 | |
| 342 | // Notifies this object that |service| state has changed. |
| 343 | virtual void NotifyServiceStateChanged(const Service *service, |
| 344 | Service::ConnectState new_state); |
| 345 | |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 346 | // Notifies this object that |service| has been disconnected. |
| 347 | void NotifyServiceDisconnect(const Service *service); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 348 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 349 | // Notifies this object of a power management state change. |
| 350 | void NotifyPowerStateChange(PowerManager::SuspendState new_state); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 351 | |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 352 | // Notifies this object that termination actions started executing. |
| 353 | void NotifyTerminationActionsStarted(TerminationActionReason reason); |
| 354 | |
| 355 | // Notifies this object that termination actions have been completed. |
| 356 | // |success| is true, if the termination actions completed successfully. |
| 357 | void NotifyTerminationActionsCompleted( |
| 358 | TerminationActionReason reason, bool success); |
| 359 | |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 360 | // Notifies this object of a failure in LinkMonitor. |
| 361 | void NotifyLinkMonitorFailure( |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 362 | Technology::Identifier technology, |
| 363 | LinkMonitorFailure failure, |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 364 | int seconds_to_failure, |
| 365 | int broadcast_error_count, |
| 366 | int unicast_error_count); |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 367 | |
| 368 | // Notifies this object that LinkMonitor has added a response time sample |
| 369 | // for |connection| with a value of |response_time_milliseconds|. |
| 370 | void NotifyLinkMonitorResponseTimeSampleAdded( |
| 371 | Technology::Identifier technology, |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 372 | int response_time_milliseconds); |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 373 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 374 | // Notifies this object of WiFi disconnect. |
| 375 | void Notify80211Disconnect(WiFiDisconnectByWhom by_whom, |
| 376 | IEEE_80211::WiFiReasonCode reason); |
| 377 | |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 378 | // Registers a device with this object so the device can use the timers to |
| 379 | // track state transition metrics. |
| 380 | void RegisterDevice(int interface_index, |
| 381 | Technology::Identifier technology); |
| 382 | |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 383 | // Checks to see if the device has already been registered. |
| 384 | bool IsDeviceRegistered(int interface_index, |
| 385 | Technology::Identifier technology); |
| 386 | |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 387 | // Deregisters the device from this class. All state transition timers |
| 388 | // will be removed. |
| 389 | void DeregisterDevice(int interface_index); |
| 390 | |
| 391 | // Notifies this object that a device has been initialized. |
| 392 | void NotifyDeviceInitialized(int interface_index); |
| 393 | |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 394 | // Notifies this object that a device has started the enable process. |
| 395 | void NotifyDeviceEnableStarted(int interface_index); |
| 396 | |
| 397 | // Notifies this object that a device has completed the enable process. |
| 398 | void NotifyDeviceEnableFinished(int interface_index); |
| 399 | |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 400 | // Notifies this object that a device has started the disable process. |
| 401 | void NotifyDeviceDisableStarted(int interface_index); |
| 402 | |
| 403 | // Notifies this object that a device has completed the disable process. |
| 404 | void NotifyDeviceDisableFinished(int interface_index); |
| 405 | |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 406 | // Notifies this object that a device has started the scanning process. |
| 407 | void NotifyDeviceScanStarted(int interface_index); |
| 408 | |
| 409 | // Notifies this object that a device has completed the scanning process. |
| 410 | void NotifyDeviceScanFinished(int interface_index); |
| 411 | |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 412 | // Notifies this object that a device has started the connect process. |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 413 | void NotifyDeviceConnectStarted(int interface_index, |
| 414 | bool is_auto_connecting); |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 415 | |
| 416 | // Notifies this object that a device has completed the connect process. |
| 417 | void NotifyDeviceConnectFinished(int interface_index); |
| 418 | |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 419 | // Notifies this object that a cellular device has been dropped by the |
| 420 | // network. |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 421 | void NotifyCellularDeviceDrop(int interface_index, |
| 422 | const std::string &network_technology, |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 423 | uint16 signal_strength); |
| 424 | |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 425 | // Notifies this object about a cellular device failure code. |
| 426 | void NotifyCellularDeviceFailure(const Error &error); |
| 427 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 428 | // Sends linear histogram data to UMA. |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 429 | virtual bool SendEnumToUMA(const std::string &name, int sample, int max); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 430 | |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 431 | // Send histogram data to UMA. |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 432 | virtual bool SendToUMA(const std::string &name, int sample, int min, |
| 433 | int max, int num_buckets); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 434 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 435 | private: |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 436 | friend class MetricsTest; |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 437 | FRIEND_TEST(MetricsTest, CellularDropsPerHour); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 438 | FRIEND_TEST(MetricsTest, FrequencyToChannel); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 439 | FRIEND_TEST(MetricsTest, ServiceFailure); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 440 | FRIEND_TEST(MetricsTest, TimeOnlineTimeToDrop); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 441 | FRIEND_TEST(MetricsTest, TimeToConfig); |
| 442 | FRIEND_TEST(MetricsTest, TimeToOnline); |
| 443 | FRIEND_TEST(MetricsTest, TimeToPortal); |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 444 | FRIEND_TEST(MetricsTest, TimeToScanIgnore); |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 445 | FRIEND_TEST(MetricsTest, WiFiServiceChannel); |
| 446 | FRIEND_TEST(MetricsTest, WiFiServicePostReady); |
Gaurav Shah | 6d2c72d | 2012-10-16 16:30:44 -0700 | [diff] [blame] | 447 | FRIEND_TEST(WiFiMainTest, GetGeolocationObjects); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 448 | |
| 449 | typedef ScopedVector<chromeos_metrics::TimerReporter> TimerReporters; |
| 450 | typedef std::list<chromeos_metrics::TimerReporter *> TimerReportersList; |
| 451 | typedef std::map<Service::ConnectState, TimerReportersList> |
| 452 | TimerReportersByState; |
| 453 | struct ServiceMetrics { |
| 454 | ServiceMetrics() : service(NULL) {} |
| 455 | // The service is registered/deregistered in the Service |
| 456 | // constructor/destructor, therefore there is no need to keep a ref count. |
| 457 | const Service *service; |
| 458 | // All TimerReporter objects are stored in |timers| which owns the objects. |
| 459 | // |start_on_state| and |stop_on_state| contain pointers to the |
| 460 | // TimerReporter objects and control when to start and stop the timers. |
| 461 | TimerReporters timers; |
| 462 | TimerReportersByState start_on_state; |
| 463 | TimerReportersByState stop_on_state; |
| 464 | }; |
| 465 | typedef std::map<const Service *, std::tr1::shared_ptr<ServiceMetrics> > |
| 466 | ServiceMetricsLookupMap; |
| 467 | |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 468 | struct DeviceMetrics { |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 469 | DeviceMetrics() : auto_connect_tries(0), num_drops(0) {} |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 470 | Technology::Identifier technology; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 471 | scoped_ptr<chromeos_metrics::TimerReporter> initialization_timer; |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 472 | scoped_ptr<chromeos_metrics::TimerReporter> enable_timer; |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 473 | scoped_ptr<chromeos_metrics::TimerReporter> disable_timer; |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 474 | scoped_ptr<chromeos_metrics::TimerReporter> scan_timer; |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 475 | scoped_ptr<chromeos_metrics::TimerReporter> connect_timer; |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 476 | scoped_ptr<chromeos_metrics::TimerReporter> auto_connect_timer; |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 477 | int auto_connect_tries; |
| 478 | int num_drops; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 479 | }; |
| 480 | typedef std::map<const int, std::tr1::shared_ptr<DeviceMetrics> > |
| 481 | DeviceMetricsLookupMap; |
| 482 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 483 | static const uint16 kWiFiBandwidth5MHz; |
| 484 | static const uint16 kWiFiBandwidth20MHz; |
| 485 | static const uint16 kWiFiFrequency2412; |
| 486 | static const uint16 kWiFiFrequency2472; |
| 487 | static const uint16 kWiFiFrequency2484; |
| 488 | static const uint16 kWiFiFrequency5170; |
| 489 | static const uint16 kWiFiFrequency5180; |
| 490 | static const uint16 kWiFiFrequency5230; |
| 491 | static const uint16 kWiFiFrequency5240; |
| 492 | static const uint16 kWiFiFrequency5320; |
| 493 | static const uint16 kWiFiFrequency5500; |
| 494 | static const uint16 kWiFiFrequency5700; |
| 495 | static const uint16 kWiFiFrequency5745; |
| 496 | static const uint16 kWiFiFrequency5825; |
| 497 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 498 | static const int kHourlyTimeoutMilliseconds; |
| 499 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 500 | void InitializeCommonServiceMetrics(const Service *service); |
| 501 | void UpdateServiceStateTransitionMetrics(ServiceMetrics *service_metrics, |
| 502 | Service::ConnectState new_state); |
| 503 | void SendServiceFailure(const Service *service); |
| 504 | |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 505 | DeviceMetrics *GetDeviceMetrics (int interface_index) const; |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 506 | void AutoConnectMetricsReset(DeviceMetrics *device_metrics); |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 507 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 508 | void HourlyTimeoutHandler(); |
| 509 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 510 | // For unit test purposes. |
| 511 | void set_library(MetricsLibraryInterface *library); |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 512 | void set_time_online_timer(chromeos_metrics::Timer *timer) { |
| 513 | time_online_timer_.reset(timer); // Passes ownership |
| 514 | } |
| 515 | void set_time_to_drop_timer(chromeos_metrics::Timer *timer) { |
| 516 | time_to_drop_timer_.reset(timer); // Passes ownership |
| 517 | } |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 518 | void set_time_resume_to_ready_timer(chromeos_metrics::Timer *timer) { |
| 519 | time_resume_to_ready_timer_.reset(timer); // Passes ownership |
| 520 | } |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 521 | void set_time_termination_actions_timer( |
| 522 | chromeos_metrics::Timer *timer) { |
| 523 | time_termination_actions_timer.reset(timer); // Passes ownership |
| 524 | } |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 525 | void set_time_to_scan_timer(int interface_index, |
| 526 | chromeos_metrics::TimerReporter *timer) { |
| 527 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 528 | device_metrics->scan_timer.reset(timer); // Passes ownership |
| 529 | } |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 530 | |
| 531 | // |library_| points to |metrics_library_| when shill runs normally. |
| 532 | // However, in order to allow for unit testing, we point |library_| to a |
| 533 | // MetricsLibraryMock object instead. |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 534 | EventDispatcher *dispatcher_; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 535 | MetricsLibrary metrics_library_; |
| 536 | MetricsLibraryInterface *library_; |
| 537 | ServiceMetricsLookupMap services_metrics_; |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 538 | Technology::Identifier last_default_technology_; |
| 539 | bool was_online_; |
| 540 | scoped_ptr<chromeos_metrics::Timer> time_online_timer_; |
| 541 | scoped_ptr<chromeos_metrics::Timer> time_to_drop_timer_; |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 542 | scoped_ptr<chromeos_metrics::Timer> time_resume_to_ready_timer_; |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 543 | scoped_ptr<chromeos_metrics::Timer> time_termination_actions_timer; |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 544 | bool collect_bootstats_; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 545 | DeviceMetricsLookupMap devices_metrics_; |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame^] | 546 | base::CancelableClosure hourly_timeout_handler_; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 547 | |
| 548 | DISALLOW_COPY_AND_ASSIGN(Metrics); |
| 549 | }; |
| 550 | |
| 551 | } // namespace shill |
| 552 | |
| 553 | #endif // SHILL_METRICS_ |