1 // 2 // Copyright (C) 2012 The Android Open Source Project 3 // 4 // Licensed under the Apache License, Version 2.0 (the "License"); 5 // you may not use this file except in compliance with the License. 6 // You may obtain a copy of the License at 7 // 8 // http://www.apache.org/licenses/LICENSE-2.0 9 // 10 // Unless required by applicable law or agreed to in writing, software 11 // distributed under the License is distributed on an "AS IS" BASIS, 12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 // See the License for the specific language governing permissions and 14 // limitations under the License. 15 // 16 17 #ifndef SHILL_METRICS_H_ 18 #define SHILL_METRICS_H_ 19 20 #include <list> 21 #include <map> 22 #include <memory> 23 #include <string> 24 25 #include <base/memory/scoped_vector.h> 26 #include <metrics/metrics_library.h> 27 #include <metrics/timer.h> 28 29 #include "shill/connectivity_trial.h" 30 #include "shill/event_dispatcher.h" 31 #include "shill/portal_detector.h" 32 #include "shill/power_manager.h" 33 #include "shill/refptr_types.h" 34 #include "shill/service.h" 35 36 #if !defined(DISABLE_WIFI) 37 #include "shill/net/ieee80211.h" 38 #include "shill/wifi/wake_on_wifi.h" 39 #endif // DISABLE_WIFI 40 41 namespace shill { 42 43 class Metrics { 44 public: 45 enum WiFiChannel { 46 kWiFiChannelUndef = 0, 47 kWiFiChannel2412 = 1, 48 kWiFiChannel2417 = 2, 49 kWiFiChannel2422 = 3, 50 kWiFiChannel2427 = 4, 51 kWiFiChannel2432 = 5, 52 kWiFiChannel2437 = 6, 53 kWiFiChannel2442 = 7, 54 kWiFiChannel2447 = 8, 55 kWiFiChannel2452 = 9, 56 kWiFiChannel2457 = 10, 57 kWiFiChannel2462 = 11, 58 kWiFiChannel2467 = 12, 59 kWiFiChannel2472 = 13, 60 kWiFiChannel2484 = 14, 61 62 kWiFiChannel5180 = 15, 63 kWiFiChannel5200 = 16, 64 kWiFiChannel5220 = 17, 65 kWiFiChannel5240 = 18, 66 kWiFiChannel5260 = 19, 67 kWiFiChannel5280 = 20, 68 kWiFiChannel5300 = 21, 69 kWiFiChannel5320 = 22, 70 71 kWiFiChannel5500 = 23, 72 kWiFiChannel5520 = 24, 73 kWiFiChannel5540 = 25, 74 kWiFiChannel5560 = 26, 75 kWiFiChannel5580 = 27, 76 kWiFiChannel5600 = 28, 77 kWiFiChannel5620 = 29, 78 kWiFiChannel5640 = 30, 79 kWiFiChannel5660 = 31, 80 kWiFiChannel5680 = 32, 81 kWiFiChannel5700 = 33, 82 83 kWiFiChannel5745 = 34, 84 kWiFiChannel5765 = 35, 85 kWiFiChannel5785 = 36, 86 kWiFiChannel5805 = 37, 87 kWiFiChannel5825 = 38, 88 89 kWiFiChannel5170 = 39, 90 kWiFiChannel5190 = 40, 91 kWiFiChannel5210 = 41, 92 kWiFiChannel5230 = 42, 93 94 /* NB: ignore old 11b bands 2312..2372 and 2512..2532 */ 95 /* NB: ignore regulated bands 4920..4980 and 5020..5160 */ 96 kWiFiChannelMax 97 }; 98 99 enum WiFiNetworkPhyMode { 100 kWiFiNetworkPhyModeUndef = 0, // Unknown/undefined 101 kWiFiNetworkPhyMode11a = 1, // 802.11a 102 kWiFiNetworkPhyMode11b = 2, // 802.11b 103 kWiFiNetworkPhyMode11g = 3, // 802.11g 104 kWiFiNetworkPhyMode11n = 4, // 802.11n 105 kWiFiNetworkPhyModeHalf = 5, // PSB Half-width 106 kWiFiNetworkPhyModeQuarter = 6, // PSB Quarter-width 107 kWiFiNetworkPhyMode11ac = 7, // 802.11ac 108 109 kWiFiNetworkPhyModeMax 110 }; 111 112 enum EapOuterProtocol { 113 kEapOuterProtocolUnknown = 0, 114 kEapOuterProtocolLeap = 1, 115 kEapOuterProtocolPeap = 2, 116 kEapOuterProtocolTls = 3, 117 kEapOuterProtocolTtls = 4, 118 119 kEapOuterProtocolMax 120 }; 121 122 enum EapInnerProtocol { 123 kEapInnerProtocolUnknown = 0, 124 kEapInnerProtocolNone = 1, 125 kEapInnerProtocolPeapMd5 = 2, 126 kEapInnerProtocolPeapMschapv2 = 3, 127 kEapInnerProtocolTtlsEapMd5 = 4, 128 kEapInnerProtocolTtlsEapMschapv2 = 5, 129 kEapInnerProtocolTtlsMschapv2 = 6, 130 kEapInnerProtocolTtlsMschap = 7, 131 kEapInnerProtocolTtlsPap = 8, 132 kEapInnerProtocolTtlsChap = 9, 133 134 kEapInnerProtocolMax 135 }; 136 137 enum WiFiSecurity { 138 kWiFiSecurityUnknown = 0, 139 kWiFiSecurityNone = 1, 140 kWiFiSecurityWep = 2, 141 kWiFiSecurityWpa = 3, 142 kWiFiSecurityRsn = 4, 143 kWiFiSecurity8021x = 5, 144 kWiFiSecurityPsk = 6, 145 146 kWiFiSecurityMax 147 }; 148 149 enum WiFiApMode { 150 kWiFiApModeUnknown = 0, 151 kWiFiApModeManaged = 1, 152 kWiFiApModeAdHoc = 2, 153 154 kWiFiApModeMax 155 }; 156 157 enum PortalResult { 158 kPortalResultSuccess = 0, 159 kPortalResultDNSFailure = 1, 160 kPortalResultDNSTimeout = 2, 161 kPortalResultConnectionFailure = 3, 162 kPortalResultConnectionTimeout = 4, 163 kPortalResultHTTPFailure = 5, 164 kPortalResultHTTPTimeout = 6, 165 kPortalResultContentFailure = 7, 166 kPortalResultContentTimeout = 8, 167 kPortalResultUnknown = 9, 168 169 kPortalResultMax 170 }; 171 172 enum LinkMonitorFailure { 173 kLinkMonitorMacAddressNotFound = 0, 174 kLinkMonitorClientStartFailure = 1, 175 kLinkMonitorTransmitFailure = 2, 176 kLinkMonitorFailureThresholdReached = 3, 177 178 kLinkMonitorFailureMax 179 }; 180 181 enum WiFiStatusType { 182 kStatusCodeTypeByAp, 183 kStatusCodeTypeByClient, 184 kStatusCodeTypeByUser, 185 kStatusCodeTypeConsideredDead, 186 kStatusCodeTypeMax 187 }; 188 189 enum WiFiDisconnectByWhom { 190 kDisconnectedByAp, 191 kDisconnectedNotByAp 192 }; 193 194 enum WiFiScanResult { 195 kScanResultProgressiveConnected, 196 kScanResultProgressiveErrorAndFullFoundNothing, 197 kScanResultProgressiveErrorButFullConnected, 198 kScanResultProgressiveAndFullFoundNothing, 199 kScanResultProgressiveAndFullConnected, 200 kScanResultFullScanFoundNothing, 201 kScanResultFullScanConnected, 202 kScanResultInternalError, 203 kScanResultMax 204 }; 205 206 enum ServiceFixupProfileType { 207 kMetricServiceFixupDefaultProfile, 208 kMetricServiceFixupUserProfile, 209 kMetricServiceFixupMax 210 }; 211 212 enum TerminationActionResult { 213 kTerminationActionResultSuccess, 214 kTerminationActionResultFailure, 215 kTerminationActionResultMax 216 }; 217 218 enum SuspendActionResult { 219 kSuspendActionResultSuccess, 220 kSuspendActionResultFailure, 221 kSuspendActionResultMax 222 }; 223 224 enum DarkResumeActionResult { 225 kDarkResumeActionResultSuccess, 226 kDarkResumeActionResultFailure, 227 kDarkResumeActionResultMax 228 }; 229 230 enum DarkResumeUnmatchedScanResultReceived { 231 kDarkResumeUnmatchedScanResultsReceivedFalse = 0, 232 kDarkResumeUnmatchedScanResultsReceivedTrue = 1, 233 kDarkResumeUnmatchedScanResultsReceivedMax 234 }; 235 236 enum VerifyWakeOnWiFiSettingsResult { 237 kVerifyWakeOnWiFiSettingsResultSuccess, 238 kVerifyWakeOnWiFiSettingsResultFailure, 239 kVerifyWakeOnWiFiSettingsResultMax 240 }; 241 242 enum WiFiConnectionStatusAfterWake { 243 kWiFiConnetionStatusAfterWakeOnWiFiEnabledWakeConnected = 0, 244 kWiFiConnetionStatusAfterWakeOnWiFiEnabledWakeNotConnected = 1, 245 kWiFiConnetionStatusAfterWakeOnWiFiDisabledWakeConnected = 2, 246 kWiFiConnetionStatusAfterWakeOnWiFiDisabledWakeNotConnected = 3, 247 kWiFiConnetionStatusAfterWakeMax 248 }; 249 250 enum Cellular3GPPRegistrationDelayedDrop { 251 kCellular3GPPRegistrationDelayedDropPosted = 0, 252 kCellular3GPPRegistrationDelayedDropCanceled = 1, 253 kCellular3GPPRegistrationDelayedDropMax 254 }; 255 256 enum CellularDropTechnology { 257 kCellularDropTechnology1Xrtt = 0, 258 kCellularDropTechnologyEdge = 1, 259 kCellularDropTechnologyEvdo = 2, 260 kCellularDropTechnologyGprs = 3, 261 kCellularDropTechnologyGsm = 4, 262 kCellularDropTechnologyHspa = 5, 263 kCellularDropTechnologyHspaPlus = 6, 264 kCellularDropTechnologyLte = 7, 265 kCellularDropTechnologyUmts = 8, 266 kCellularDropTechnologyUnknown = 9, 267 kCellularDropTechnologyMax 268 }; 269 270 enum CellularOutOfCreditsReason { 271 kCellularOutOfCreditsReasonConnectDisconnectLoop = 0, 272 kCellularOutOfCreditsReasonTxCongested = 1, 273 kCellularOutOfCreditsReasonElongatedTimeWait = 2, 274 kCellularOutOfCreditsReasonMax 275 }; 276 277 enum CorruptedProfile { 278 kCorruptedProfile = 1, 279 kCorruptedProfileMax 280 }; 281 282 enum ConnectionDiagnosticsIssue { 283 kConnectionDiagnosticsIssueIPCollision = 0, 284 kConnectionDiagnosticsIssueRouting = 1, 285 kConnectionDiagnosticsIssueHTTPBrokenPortal = 2, 286 kConnectionDiagnosticsIssueDNSServerMisconfig = 3, 287 kConnectionDiagnosticsIssueDNSServerNoResponse = 4, 288 kConnectionDiagnosticsIssueNoDNSServersConfigured = 5, 289 kConnectionDiagnosticsIssueDNSServersInvalid = 6, 290 kConnectionDiagnosticsIssueNone = 7, 291 kConnectionDiagnosticsIssueCaptivePortal = 8, 292 kConnectionDiagnosticsIssueGatewayUpstream = 9, 293 kConnectionDiagnosticsIssueGatewayNotResponding = 10, 294 kConnectionDiagnosticsIssueServerNotResponding = 11, 295 kConnectionDiagnosticsIssueGatewayArpFailed = 12, 296 kConnectionDiagnosticsIssueServerArpFailed = 13, 297 kConnectionDiagnosticsIssueInternalError = 14, 298 kConnectionDiagnosticsIssueGatewayNoNeighborEntry = 15, 299 kConnectionDiagnosticsIssueServerNoNeighborEntry = 16, 300 kConnectionDiagnosticsIssueGatewayNeighborEntryNotConnected = 17, 301 kConnectionDiagnosticsIssueServerNeighborEntryNotConnected = 18, 302 kConnectionDiagnosticsIssuePlaceholder1 = 19, 303 kConnectionDiagnosticsIssuePlaceholder2 = 20, 304 kConnectionDiagnosticsIssuePlaceholder3 = 21, 305 kConnectionDiagnosticsIssuePlaceholder4 = 22, 306 kConnectionDiagnosticsIssueMax 307 }; 308 309 enum VpnDriver { 310 kVpnDriverOpenVpn = 0, 311 kVpnDriverL2tpIpsec = 1, 312 kVpnDriverMax 313 }; 314 315 enum VpnRemoteAuthenticationType { 316 kVpnRemoteAuthenticationTypeOpenVpnDefault = 0, 317 kVpnRemoteAuthenticationTypeOpenVpnCertificate = 1, 318 kVpnRemoteAuthenticationTypeL2tpIpsecDefault = 2, 319 kVpnRemoteAuthenticationTypeL2tpIpsecCertificate = 3, 320 kVpnRemoteAuthenticationTypeL2tpIpsecPsk = 4, 321 kVpnRemoteAuthenticationTypeMax 322 }; 323 324 enum VpnUserAuthenticationType { 325 kVpnUserAuthenticationTypeOpenVpnNone = 0, 326 kVpnUserAuthenticationTypeOpenVpnCertificate = 1, 327 kVpnUserAuthenticationTypeOpenVpnUsernamePassword = 2, 328 kVpnUserAuthenticationTypeOpenVpnUsernamePasswordOtp = 3, 329 kVpnUserAuthenticationTypeOpenVpnUsernameToken = 7, 330 kVpnUserAuthenticationTypeL2tpIpsecNone = 4, 331 kVpnUserAuthenticationTypeL2tpIpsecCertificate = 5, 332 kVpnUserAuthenticationTypeL2tpIpsecUsernamePassword = 6, 333 kVpnUserAuthenticationTypeMax 334 }; 335 336 enum UserInitiatedEvent { 337 kUserInitiatedEventWifiScan = 0, 338 kUserInitiatedEventReserved, 339 kUserInitiatedEventMax 340 }; 341 342 enum UserInitiatedConnectionResult { 343 kUserInitiatedConnectionResultSuccess = 0, 344 kUserInitiatedConnectionResultFailure = 1, 345 kUserInitiatedConnectionResultAborted = 2, 346 kUserInitiatedConnectionResultMax 347 }; 348 349 enum DNSTestResult { 350 kFallbackDNSTestResultSuccess = 0, 351 kFallbackDNSTestResultFailure, 352 kFallbackDNSTestResultMax 353 }; 354 355 // Network problem detected by traffic monitor. 356 enum NetworkProblem { 357 kNetworkProblemCongestedTCPTxQueue = 0, 358 kNetworkProblemDNSFailure, 359 kNetworkProblemMax 360 }; 361 362 // Device's connection status. 363 enum ConnectionStatus { 364 kConnectionStatusOffline = 0, 365 kConnectionStatusConnected = 1, 366 kConnectionStatusOnline = 2, 367 kConnectionStatusMax 368 }; 369 370 enum UserInitiatedConnectionFailureReason { 371 kUserInitiatedConnectionFailureReasonUnknown = 0, 372 kUserInitiatedConnectionFailureReasonBadPassphrase = 1, 373 kUserInitiatedConnectionFailureReasonBadWEPKey = 2, 374 kUserInitiatedConnectionFailureReasonConnect = 3, 375 kUserInitiatedConnectionFailureReasonDHCP = 4, 376 kUserInitiatedConnectionFailureReasonDNSLookup = 5, 377 kUserInitiatedConnectionFailureReasonEAPAuthentication = 6, 378 kUserInitiatedConnectionFailureReasonEAPLocalTLS = 7, 379 kUserInitiatedConnectionFailureReasonEAPRemoteTLS = 8, 380 kUserInitiatedConnectionFailureReasonOutOfRange = 9, 381 kUserInitiatedConnectionFailureReasonPinMissing = 10, 382 kUserInitiatedConnectionFailureReasonMax 383 }; 384 385 enum DhcpClientStatus { 386 kDhcpClientStatusArpGateway = 0, 387 kDhcpClientStatusArpSelf = 1, 388 kDhcpClientStatusBound = 2, 389 kDhcpClientStatusDiscover = 3, 390 kDhcpClientStatusIgnoreAdditionalOffer = 4, 391 kDhcpClientStatusIgnoreFailedOffer = 5, 392 kDhcpClientStatusIgnoreInvalidOffer = 6, 393 kDhcpClientStatusIgnoreNonOffer = 7, 394 kDhcpClientStatusInform = 8, 395 kDhcpClientStatusInit = 9, 396 kDhcpClientStatusNakDefer = 10, 397 kDhcpClientStatusRebind = 11, 398 kDhcpClientStatusReboot = 12, 399 kDhcpClientStatusRelease = 13, 400 kDhcpClientStatusRenew = 14, 401 kDhcpClientStatusRequest = 15, 402 kDhcpClientStatusMax 403 }; 404 405 enum NetworkConnectionIPType { 406 kNetworkConnectionIPTypeIPv4 = 0, 407 kNetworkConnectionIPTypeIPv6 = 1, 408 kNetworkConnectionIPTypeMax 409 }; 410 411 enum IPv6ConnectivityStatus { 412 kIPv6ConnectivityStatusNo = 0, 413 kIPv6ConnectivityStatusYes = 1, 414 kIPv6ConnectivityStatusMax 415 }; 416 417 enum DevicePresenceStatus { 418 kDevicePresenceStatusNo = 0, 419 kDevicePresenceStatusYes = 1, 420 kDevicePresenceStatusMax 421 }; 422 423 enum DeviceTechnologyType { 424 kDeviceTechnologyTypeUnknown = 0, 425 kDeviceTechnologyTypeEthernet = 1, 426 kDeviceTechnologyTypeWifi = 2, 427 kDeviceTechnologyTypeWimax = 3, 428 kDeviceTechnologyTypeCellular = 4, 429 kDeviceTechnologyTypeMax 430 }; 431 432 enum NetworkServiceError { 433 kNetworkServiceErrorUnknown = 0, 434 kNetworkServiceErrorAAA = 1, 435 kNetworkServiceErrorActivation = 2, 436 kNetworkServiceErrorBadPassphrase = 3, 437 kNetworkServiceErrorBadWEPKey = 4, 438 kNetworkServiceErrorConnect = 5, 439 kNetworkServiceErrorDHCP = 6, 440 kNetworkServiceErrorDNSLookup = 7, 441 kNetworkServiceErrorEAPAuthentication = 8, 442 kNetworkServiceErrorEAPLocalTLS = 9, 443 kNetworkServiceErrorEAPRemoteTLS = 10, 444 kNetworkServiceErrorHTTPGet = 11, 445 kNetworkServiceErrorIPSecCertAuth = 12, 446 kNetworkServiceErrorIPSecPSKAuth = 13, 447 kNetworkServiceErrorInternal = 14, 448 kNetworkServiceErrorNeedEVDO = 15, 449 kNetworkServiceErrorNeedHomeNetwork = 16, 450 kNetworkServiceErrorOTASP = 17, 451 kNetworkServiceErrorOutOfRange = 18, 452 kNetworkServiceErrorPPPAuth = 19, 453 kNetworkServiceErrorPinMissing = 20, 454 kNetworkServiceErrorMax 455 }; 456 457 enum WakeOnWiFiFeaturesEnabledState { 458 kWakeOnWiFiFeaturesEnabledStateNone = 0, 459 kWakeOnWiFiFeaturesEnabledStatePacket = 1, 460 kWakeOnWiFiFeaturesEnabledStateDarkConnect = 2, 461 kWakeOnWiFiFeaturesEnabledStatePacketDarkConnect = 3, 462 kWakeOnWiFiFeaturesEnabledStateMax 463 }; 464 465 enum WakeOnWiFiThrottled { 466 kWakeOnWiFiThrottledFalse = 0, 467 kWakeOnWiFiThrottledTrue = 1, 468 kWakeOnWiFiThrottledMax 469 }; 470 471 enum WakeReasonReceivedBeforeOnDarkResume { 472 kWakeReasonReceivedBeforeOnDarkResumeFalse = 0, 473 kWakeReasonReceivedBeforeOnDarkResumeTrue = 1, 474 kWakeReasonReceivedBeforeOnDarkResumeMax 475 }; 476 477 enum DarkResumeWakeReason { 478 kDarkResumeWakeReasonUnsupported = 0, 479 kDarkResumeWakeReasonPattern = 1, 480 kDarkResumeWakeReasonDisconnect = 2, 481 kDarkResumeWakeReasonSSID = 3, 482 kDarkResumeWakeReasonMax 483 }; 484 485 enum DarkResumeScanType { 486 kDarkResumeScanTypeActive = 0, 487 kDarkResumeScanTypePassive = 1, 488 kDarkResumeScanTypeMax 489 }; 490 491 enum DarkResumeScanRetryResult { 492 kDarkResumeScanRetryResultNotConnected = 0, 493 kDarkResumeScanRetryResultConnected = 1, 494 kDarkResumeScanRetryResultMax 495 }; 496 497 static const char kMetricDisconnectSuffix[]; 498 static const int kMetricDisconnectMax; 499 static const int kMetricDisconnectMin; 500 static const int kMetricDisconnectNumBuckets; 501 static const char kMetricSignalAtDisconnectSuffix[]; 502 static const int kMetricSignalAtDisconnectMin; 503 static const int kMetricSignalAtDisconnectMax; 504 static const int kMetricSignalAtDisconnectNumBuckets; 505 static const char kMetricNetworkApModeSuffix[]; 506 static const char kMetricNetworkChannelSuffix[]; 507 static const int kMetricNetworkChannelMax; 508 static const char kMetricNetworkEapInnerProtocolSuffix[]; 509 static const int kMetricNetworkEapInnerProtocolMax; 510 static const char kMetricNetworkEapOuterProtocolSuffix[]; 511 static const int kMetricNetworkEapOuterProtocolMax; 512 static const char kMetricNetworkPhyModeSuffix[]; 513 static const int kMetricNetworkPhyModeMax; 514 static const char kMetricNetworkSecuritySuffix[]; 515 static const int kMetricNetworkSecurityMax; 516 static const char kMetricNetworkServiceErrors[]; 517 static const char kMetricNetworkSignalStrengthSuffix[]; 518 static const int kMetricNetworkSignalStrengthMin; 519 static const int kMetricNetworkSignalStrengthMax; 520 static const int kMetricNetworkSignalStrengthNumBuckets; 521 // Histogram parameters for next two are the same as for 522 // kMetricRememberedWiFiNetworkCount. Must be constexpr, for static 523 // checking of format string. Must be defined inline, for constexpr. 524 static constexpr char 525 kMetricRememberedSystemWiFiNetworkCountBySecurityModeFormat[] = 526 "Network.Shill.WiFi.RememberedSystemNetworkCount.%s"; 527 static constexpr char 528 kMetricRememberedUserWiFiNetworkCountBySecurityModeFormat[] = 529 "Network.Shill.WiFi.RememberedUserNetworkCount.%s"; 530 static const char kMetricRememberedWiFiNetworkCount[]; 531 static const int kMetricRememberedWiFiNetworkCountMin; 532 static const int kMetricRememberedWiFiNetworkCountMax; 533 static const int kMetricRememberedWiFiNetworkCountNumBuckets; 534 static const char kMetricTimeOnlineSecondsSuffix[]; 535 static const int kMetricTimeOnlineSecondsMax; 536 static const int kMetricTimeOnlineSecondsMin; 537 static const int kMetricTimeOnlineSecondsNumBuckets; 538 static const char kMetricTimeResumeToReadyMillisecondsSuffix[]; 539 static const char kMetricTimeToConfigMillisecondsSuffix[]; 540 static const char kMetricTimeToConnectMillisecondsSuffix[]; 541 static const int kMetricTimeToConnectMillisecondsMax; 542 static const int kMetricTimeToConnectMillisecondsMin; 543 static const int kMetricTimeToConnectMillisecondsNumBuckets; 544 static const char kMetricTimeToScanAndConnectMillisecondsSuffix[]; 545 static const char kMetricTimeToDropSeconds[]; 546 static const int kMetricTimeToDropSecondsMax; 547 static const int kMetricTimeToDropSecondsMin; 548 static const char kMetricTimeToDisableMillisecondsSuffix[]; 549 static const int kMetricTimeToDisableMillisecondsMax; 550 static const int kMetricTimeToDisableMillisecondsMin; 551 static const int kMetricTimeToDisableMillisecondsNumBuckets; 552 static const char kMetricTimeToEnableMillisecondsSuffix[]; 553 static const int kMetricTimeToEnableMillisecondsMax; 554 static const int kMetricTimeToEnableMillisecondsMin; 555 static const int kMetricTimeToEnableMillisecondsNumBuckets; 556 static const char kMetricTimeToInitializeMillisecondsSuffix[]; 557 static const int kMetricTimeToInitializeMillisecondsMax; 558 static const int kMetricTimeToInitializeMillisecondsMin; 559 static const int kMetricTimeToInitializeMillisecondsNumBuckets; 560 static const char kMetricTimeToJoinMillisecondsSuffix[]; 561 static const char kMetricTimeToOnlineMillisecondsSuffix[]; 562 static const char kMetricTimeToPortalMillisecondsSuffix[]; 563 static const char kMetricTimeToScanMillisecondsSuffix[]; 564 static const int kMetricTimeToScanMillisecondsMax; 565 static const int kMetricTimeToScanMillisecondsMin; 566 static const int kMetricTimeToScanMillisecondsNumBuckets; 567 static const int kTimerHistogramMillisecondsMax; 568 static const int kTimerHistogramMillisecondsMin; 569 static const int kTimerHistogramNumBuckets; 570 571 // The number of portal detections attempted for each pass. 572 // This includes both failure/timeout attempts and successful attempt 573 // (if any). 574 static const char kMetricPortalAttemptsSuffix[]; 575 static const int kMetricPortalAttemptsMax; 576 static const int kMetricPortalAttemptsMin; 577 static const int kMetricPortalAttemptsNumBuckets; 578 579 // The total number of portal detections attempted between the Connected 580 // state and the Online state. This includes both failure/timeout attempts 581 // and the final successful attempt. 582 static const char kMetricPortalAttemptsToOnlineSuffix[]; 583 static const int kMetricPortalAttemptsToOnlineMax; 584 static const int kMetricPortalAttemptsToOnlineMin; 585 static const int kMetricPortalAttemptsToOnlineNumBuckets; 586 587 // The result of the portal detection. 588 static const char kMetricPortalResultSuffix[]; 589 590 // Wifi connection frequencies. 591 static const char kMetricFrequenciesConnectedEver[]; 592 static const int kMetricFrequenciesConnectedMax; 593 static const int kMetricFrequenciesConnectedMin; 594 static const int kMetricFrequenciesConnectedNumBuckets; 595 596 static const char kMetricScanResult[]; 597 static const char kMetricWiFiScanTimeInEbusyMilliseconds[]; 598 599 static const char kMetricPowerManagerKey[]; 600 601 // LinkMonitor statistics. 602 static const char kMetricLinkMonitorFailureSuffix[]; 603 static const char kMetricLinkMonitorResponseTimeSampleSuffix[]; 604 static const int kMetricLinkMonitorResponseTimeSampleMin; 605 static const int kMetricLinkMonitorResponseTimeSampleMax; 606 static const int kMetricLinkMonitorResponseTimeSampleNumBuckets; 607 static const char kMetricLinkMonitorSecondsToFailureSuffix[]; 608 static const int kMetricLinkMonitorSecondsToFailureMin; 609 static const int kMetricLinkMonitorSecondsToFailureMax; 610 static const int kMetricLinkMonitorSecondsToFailureNumBuckets; 611 static const char kMetricLinkMonitorBroadcastErrorsAtFailureSuffix[]; 612 static const char kMetricLinkMonitorUnicastErrorsAtFailureSuffix[]; 613 static const int kMetricLinkMonitorErrorCountMin; 614 static const int kMetricLinkMonitorErrorCountMax; 615 static const int kMetricLinkMonitorErrorCountNumBuckets; 616 617 // Signal strength when link becomes unreliable (multiple link monitor 618 // failures in short period of time). 619 static const char kMetricUnreliableLinkSignalStrengthSuffix[]; 620 static const int kMetricSerivceSignalStrengthMin; 621 static const int kMetricServiceSignalStrengthMax; 622 static const int kMetricServiceSignalStrengthNumBuckets; 623 624 static const char kMetricLinkClientDisconnectReason[]; 625 static const char kMetricLinkApDisconnectReason[]; 626 static const char kMetricLinkClientDisconnectType[]; 627 static const char kMetricLinkApDisconnectType[]; 628 629 // Shill termination action statistics. 630 static const char kMetricTerminationActionTimeTaken[]; 631 static const char kMetricTerminationActionResult[]; 632 static const int kMetricTerminationActionTimeTakenMillisecondsMax; 633 static const int kMetricTerminationActionTimeTakenMillisecondsMin; 634 635 // Shill suspend action statistics. 636 static const char kMetricSuspendActionTimeTaken[]; 637 static const char kMetricSuspendActionResult[]; 638 static const int kMetricSuspendActionTimeTakenMillisecondsMax; 639 static const int kMetricSuspendActionTimeTakenMillisecondsMin; 640 641 // Shill dark resume action statistics. 642 static const char kMetricDarkResumeActionTimeTaken[]; 643 static const char kMetricDarkResumeActionResult[]; 644 static const int kMetricDarkResumeActionTimeTakenMillisecondsMax; 645 static const int kMetricDarkResumeActionTimeTakenMillisecondsMin; 646 static const char kMetricDarkResumeUnmatchedScanResultReceived[]; 647 648 // Shill wake on WiFi feature state statistics. 649 static const char kMetricWakeOnWiFiFeaturesEnabledState[]; 650 // The result of NIC wake on WiFi settings verification. 651 static const char kMetricVerifyWakeOnWiFiSettingsResult[]; 652 static const char kMetricWiFiConnectionStatusAfterWake[]; 653 // Whether or not wake on WiFi was throttled during the last suspend. 654 static const char kMetricWakeOnWiFiThrottled[]; 655 // Whether or not a wakeup reason was received before WakeOnWiFi::OnDarkResume 656 // executes. 657 static const char kMetricWakeReasonReceivedBeforeOnDarkResume[]; 658 static const char kMetricDarkResumeWakeReason[]; 659 static const char kMetricDarkResumeScanType[]; 660 static const char kMetricDarkResumeScanRetryResult[]; 661 static const char kMetricDarkResumeScanNumRetries[]; 662 static const int kMetricDarkResumeScanNumRetriesMax; 663 static const int kMetricDarkResumeScanNumRetriesMin; 664 665 // WiFiService Entry Fixup. 666 static const char kMetricServiceFixupEntriesSuffix[]; 667 668 // Cellular specific statistics. 669 static const char kMetricCellular3GPPRegistrationDelayedDrop[]; 670 static const char kMetricCellularAutoConnectTries[]; 671 static const int kMetricCellularAutoConnectTriesMax; 672 static const int kMetricCellularAutoConnectTriesMin; 673 static const int kMetricCellularAutoConnectTriesNumBuckets; 674 static const char kMetricCellularAutoConnectTotalTime[]; 675 static const int kMetricCellularAutoConnectTotalTimeMax; 676 static const int kMetricCellularAutoConnectTotalTimeMin; 677 static const int kMetricCellularAutoConnectTotalTimeNumBuckets; 678 static const char kMetricCellularDrop[]; 679 static const char kMetricCellularDropsPerHour[]; 680 static const int kMetricCellularDropsPerHourMax; 681 static const int kMetricCellularDropsPerHourMin; 682 static const int kMetricCellularDropsPerHourNumBuckets; 683 static const char kMetricCellularFailure[]; 684 static const int kMetricCellularConnectionFailure; 685 static const int kMetricCellularDisconnectionFailure; 686 static const int kMetricCellularMaxFailure; 687 static const char kMetricCellularOutOfCreditsReason[]; 688 static const char kMetricCellularSignalStrengthBeforeDrop[]; 689 static const int kMetricCellularSignalStrengthBeforeDropMax; 690 static const int kMetricCellularSignalStrengthBeforeDropMin; 691 static const int kMetricCellularSignalStrengthBeforeDropNumBuckets; 692 693 // Profile statistics. 694 static const char kMetricCorruptedProfile[]; 695 696 // VPN connection statistics. 697 static const char kMetricVpnDriver[]; 698 static const int kMetricVpnDriverMax; 699 static const char kMetricVpnRemoteAuthenticationType[]; 700 static const int kMetricVpnRemoteAuthenticationTypeMax; 701 static const char kMetricVpnUserAuthenticationType[]; 702 static const int kMetricVpnUserAuthenticationTypeMax; 703 704 // The length in seconds of a lease that has expired while the DHCP 705 // client was attempting to renew the lease.. 706 static const char kMetricExpiredLeaseLengthSecondsSuffix[]; 707 static const int kMetricExpiredLeaseLengthSecondsMax; 708 static const int kMetricExpiredLeaseLengthSecondsMin; 709 static const int kMetricExpiredLeaseLengthSecondsNumBuckets; 710 711 // Number of wifi services available when auto-connect is initiated. 712 static const char kMetricWifiAutoConnectableServices[]; 713 static const int kMetricWifiAutoConnectableServicesMax; 714 static const int kMetricWifiAutoConnectableServicesMin; 715 static const int kMetricWifiAutoConnectableServicesNumBuckets; 716 717 // Number of BSSes available for a wifi service when we attempt to connect 718 // to that service. 719 static const char kMetricWifiAvailableBSSes[]; 720 static const int kMetricWifiAvailableBSSesMax; 721 static const int kMetricWifiAvailableBSSesMin; 722 static const int kMetricWifiAvailableBSSesNumBuckets; 723 724 // Reason that the mac80211 TX queue is stopped. 725 static const char kMetricWifiStoppedTxQueueReason[]; 726 727 // Maximal queue length amongst all stopped mac80211 TX queues. 728 static const char kMetricWifiStoppedTxQueueLength[]; 729 static const int kMetricWifiStoppedTxQueueLengthMax; 730 static const int kMetricWifiStoppedTxQueueLengthMin; 731 static const int kMetricWifiStoppedTxQueueLengthNumBuckets; 732 733 // Number of services associated with currently connected network. 734 static const char kMetricServicesOnSameNetwork[]; 735 static const int kMetricServicesOnSameNetworkMax; 736 static const int kMetricServicesOnSameNetworkMin; 737 static const int kMetricServicesOnSameNetworkNumBuckets; 738 739 // Metric for user-initiated events. 740 static const char kMetricUserInitiatedEvents[]; 741 742 // Wifi TX bitrate in Mbps. 743 static const char kMetricWifiTxBitrate[]; 744 static const int kMetricWifiTxBitrateMax; 745 static const int kMetricWifiTxBitrateMin; 746 static const int kMetricWifiTxBitrateNumBuckets; 747 748 // User-initiated wifi connection attempt result. 749 static const char kMetricWifiUserInitiatedConnectionResult[]; 750 751 // The reason of failed user-initiated wifi connection attempt. 752 static const char kMetricWifiUserInitiatedConnectionFailureReason[]; 753 754 // DNS test result. 755 static const char kMetricFallbackDNSTestResultSuffix[]; 756 757 // Network problem detected by traffic monitor 758 static const char kMetricNetworkProblemDetectedSuffix[]; 759 760 // Device's connection status. 761 static const char kMetricDeviceConnectionStatus[]; 762 763 // DHCP client status. 764 static const char kMetricDhcpClientStatus[]; 765 766 // Assigned MTU values, both from DHCP and PPP. 767 static const char kMetricDhcpClientMTUValue[]; 768 static const char kMetricPPPMTUValue[]; 769 770 // Network connection IP type. 771 static const char kMetricNetworkConnectionIPTypeSuffix[]; 772 773 // IPv6 connectivity status. 774 static const char kMetricIPv6ConnectivityStatusSuffix[]; 775 776 // Device presence. 777 static const char kMetricDevicePresenceStatusSuffix[]; 778 779 // Device removal event. 780 static const char kMetricDeviceRemovedEvent[]; 781 782 // Connection diagnostics issue. 783 static const char kMetricConnectionDiagnosticsIssue[]; 784 785 explicit Metrics(EventDispatcher* dispatcher); 786 virtual ~Metrics(); 787 788 // Converts the WiFi frequency into the associated UMA channel enumerator. 789 static WiFiChannel WiFiFrequencyToChannel(uint16_t frequency); 790 791 // Converts a flimflam security string into its UMA security enumerator. 792 static WiFiSecurity WiFiSecurityStringToEnum(const std::string& security); 793 794 // Converts a flimflam AP mode string into its UMA AP mode enumerator. 795 static WiFiApMode WiFiApModeStringToEnum(const std::string& ap_mode); 796 797 // Converts a flimflam EAP outer protocol string into its UMA enumerator. 798 static EapOuterProtocol EapOuterProtocolStringToEnum( 799 const std::string& outer); 800 801 // Converts a flimflam EAP inner protocol string into its UMA enumerator. 802 static EapInnerProtocol EapInnerProtocolStringToEnum( 803 const std::string& inner); 804 805 // Converts portal detection result to UMA portal result enumerator. 806 static PortalResult PortalDetectionResultToEnum( 807 const PortalDetector::Result& result); 808 809 // Starts this object. Call this during initialization. 810 virtual void Start(); 811 812 // Stops this object. Call this during cleanup. 813 virtual void Stop(); 814 815 // Registers a service with this object so it can use the timers to track 816 // state transition metrics. 817 void RegisterService(const Service& service); 818 819 // Deregisters the service from this class. All state transition timers 820 // will be removed. 821 void DeregisterService(const Service& service); 822 823 // Tracks the time it takes |service| to go from |start_state| to 824 // |stop_state|. When |stop_state| is reached, the time is sent to UMA. 825 virtual void AddServiceStateTransitionTimer( 826 const Service& service, const std::string& histogram_name, 827 Service::ConnectState start_state, Service::ConnectState stop_state); 828 829 // Specializes |metric_suffix| for the specified |technology_id|. 830 std::string GetFullMetricName(const char* metric_suffix, 831 Technology::Identifier technology_id); 832 833 // Notifies this object that the default service has changed. 834 // |service| is the new default service. 835 virtual void NotifyDefaultServiceChanged(const Service* service); 836 837 // Notifies this object that |service| state has changed. 838 virtual void NotifyServiceStateChanged(const Service& service, 839 Service::ConnectState new_state); 840 841 // Notifies this object that |service| has been disconnected. 842 void NotifyServiceDisconnect(const Service& service); 843 844 // Notifies this object of power at disconnect. 845 void NotifySignalAtDisconnect(const Service& service, 846 int16_t signal_strength); 847 848 // Notifies this object of the end of a suspend attempt. 849 void NotifySuspendDone(); 850 851 // Notifies this object of the current wake on WiFi features enabled 852 // represented by the WakeOnWiFiFeaturesEnabledState |state|. 853 void NotifyWakeOnWiFiFeaturesEnabledState( 854 WakeOnWiFiFeaturesEnabledState state); 855 856 // Notifies this object of the result of NIC wake on WiFi settings 857 // verification. 858 virtual void NotifyVerifyWakeOnWiFiSettingsResult( 859 VerifyWakeOnWiFiSettingsResult result); 860 861 // Notifies this object of whether or not the WiFi device is connected to a 862 // service after waking from suspend. 863 virtual void NotifyConnectedToServiceAfterWake( 864 WiFiConnectionStatusAfterWake status); 865 866 // Notifies this object that termination actions started executing. 867 void NotifyTerminationActionsStarted(); 868 869 // Notifies this object that termination actions have been completed. 870 // |success| is true, if the termination actions completed successfully. 871 void NotifyTerminationActionsCompleted(bool success); 872 873 // Notifies this object that suspend actions started executing. 874 void NotifySuspendActionsStarted(); 875 876 // Notifies this object that suspend actions have been completed. 877 // |success| is true, if the suspend actions completed successfully. 878 void NotifySuspendActionsCompleted(bool success); 879 880 // Notifies this object that dark resume actions started executing. 881 void NotifyDarkResumeActionsStarted(); 882 883 // Notifies this object that dark resume actions have been completed. 884 // |success| is true, if the dark resume actions completed successfully. 885 void NotifyDarkResumeActionsCompleted(bool success); 886 887 // Notifies this object that a scan has been initiated by shill while in dark 888 // resume. 889 virtual void NotifyDarkResumeInitiateScan(); 890 891 // Notifies this object that a scan results have been received in dark resume. 892 void NotifyDarkResumeScanResultsReceived(); 893 894 // Notifies this object of a failure in LinkMonitor. 895 void NotifyLinkMonitorFailure( 896 Technology::Identifier technology, 897 LinkMonitorFailure failure, 898 int seconds_to_failure, 899 int broadcast_error_count, 900 int unicast_error_count); 901 902 // Notifies this object that LinkMonitor has added a response time sample 903 // for |connection| with a value of |response_time_milliseconds|. 904 void NotifyLinkMonitorResponseTimeSampleAdded( 905 Technology::Identifier technology, 906 int response_time_milliseconds); 907 908 #if !defined(DISABLE_WIFI) 909 // Notifies this object of WiFi disconnect. 910 virtual void Notify80211Disconnect(WiFiDisconnectByWhom by_whom, 911 IEEE_80211::WiFiReasonCode reason); 912 #endif // DISABLE_WIFI 913 914 // Registers a device with this object so the device can use the timers to 915 // track state transition metrics. 916 void RegisterDevice(int interface_index, 917 Technology::Identifier technology); 918 919 // Checks to see if the device has already been registered. 920 bool IsDeviceRegistered(int interface_index, 921 Technology::Identifier technology); 922 923 // Deregisters the device from this class. All state transition timers 924 // will be removed. 925 virtual void DeregisterDevice(int interface_index); 926 927 // Notifies this object that a device has been initialized. 928 void NotifyDeviceInitialized(int interface_index); 929 930 // Notifies this object that a device has started the enable process. 931 void NotifyDeviceEnableStarted(int interface_index); 932 933 // Notifies this object that a device has completed the enable process. 934 void NotifyDeviceEnableFinished(int interface_index); 935 936 // Notifies this object that a device has started the disable process. 937 void NotifyDeviceDisableStarted(int interface_index); 938 939 // Notifies this object that a device has completed the disable process. 940 void NotifyDeviceDisableFinished(int interface_index); 941 942 // Notifies this object that a device has started the scanning process. 943 virtual void NotifyDeviceScanStarted(int interface_index); 944 945 // Notifies this object that a device has completed the scanning process. 946 virtual void NotifyDeviceScanFinished(int interface_index); 947 948 // Terminates an underway scan (does nothing if a scan wasn't underway). 949 virtual void ResetScanTimer(int interface_index); 950 951 // Notifies this object that a device has started the connect process. 952 virtual void NotifyDeviceConnectStarted(int interface_index, 953 bool is_auto_connecting); 954 955 // Notifies this object that a device has completed the connect process. 956 virtual void NotifyDeviceConnectFinished(int interface_index); 957 958 // Resets both the connect_timer and the scan_connect_timer the timer (the 959 // latter so that a future connect will not erroneously be associated with 960 // the previous scan). 961 virtual void ResetConnectTimer(int interface_index); 962 963 // Notifies this object that a cellular device has been dropped by the 964 // network. 965 void NotifyCellularDeviceDrop(const std::string& network_technology, 966 uint16_t signal_strength); 967 968 // Notifies this object about 3GPP registration drop events. 969 virtual void Notify3GPPRegistrationDelayedDropPosted(); 970 virtual void Notify3GPPRegistrationDelayedDropCanceled(); 971 972 // Notifies this object about a cellular connection failure. 973 void NotifyCellularDeviceConnectionFailure(); 974 975 // Notifies this object about a cellular disconnection failure. 976 void NotifyCellularDeviceDisconnectionFailure(); 977 978 // Notifies this object that a cellular service has been marked as 979 // out-of-credits. 980 void NotifyCellularOutOfCredits(Metrics::CellularOutOfCreditsReason reason); 981 982 // Notifies this object about number of wifi services available for auto 983 // connect when auto-connect is initiated. 984 virtual void NotifyWifiAutoConnectableServices(int num_services); 985 986 // Notifies this object about number of BSSes available for a wifi service 987 // when attempt to connect to that service. 988 virtual void NotifyWifiAvailableBSSes(int num_services); 989 990 // Notifies this object about number of services associated to the 991 // currently connected network. 992 virtual void NotifyServicesOnSameNetwork(int num_services); 993 994 // Notifies this object about WIFI TX bitrate in Mbps. 995 virtual void NotifyWifiTxBitrate(int bitrate); 996 997 // Notifies this object about the result of user-initiated connection 998 // attempt. 999 virtual void NotifyUserInitiatedConnectionResult(const std::string& name, 1000 int result); 1001 1002 // Notifies this object about the reason of failed user-initiated connection 1003 // attempt. 1004 virtual void NotifyUserInitiatedConnectionFailureReason( 1005 const std::string& name, const Service::ConnectFailure failure); 1006 1007 // Notifies this object about a corrupted profile. 1008 virtual void NotifyCorruptedProfile(); 1009 1010 // Notifies this object about user-initiated event. 1011 virtual void NotifyUserInitiatedEvent(int event); 1012 1013 // Notifies this object about the result of the fallback DNS test. 1014 virtual void NotifyFallbackDNSTestResult(Technology::Identifier technology_id, 1015 int result); 1016 1017 // Notifies this object about a network problem detected on the currently 1018 // connected network. 1019 virtual void NotifyNetworkProblemDetected( 1020 Technology::Identifier technology_id, int reason); 1021 1022 // Notifies this object about current connection status (online vs offline). 1023 virtual void NotifyDeviceConnectionStatus(Metrics::ConnectionStatus status); 1024 1025 // Notifies this object about the DHCP client status. 1026 virtual void NotifyDhcpClientStatus(Metrics::DhcpClientStatus status); 1027 1028 // Notifies this object about the IP type of the current network connection. 1029 virtual void NotifyNetworkConnectionIPType( 1030 Technology::Identifier technology_id, NetworkConnectionIPType type); 1031 1032 // Notifies this object about the IPv6 connectivity status. 1033 virtual void NotifyIPv6ConnectivityStatus( 1034 Technology::Identifier technology_id, bool status); 1035 1036 // Notifies this object about the presence of given technology type device. 1037 virtual void NotifyDevicePresenceStatus(Technology::Identifier technology_id, 1038 bool status); 1039 1040 // Notifies this object about the signal strength when link is unreliable. 1041 virtual void NotifyUnreliableLinkSignalStrength( 1042 Technology::Identifier technology_id, int signal_strength); 1043 1044 // Sends linear histogram data to UMA. 1045 virtual bool SendEnumToUMA(const std::string& name, int sample, int max); 1046 1047 // Send histogram data to UMA. 1048 virtual bool SendToUMA(const std::string& name, int sample, int min, 1049 int max, int num_buckets); 1050 1051 // Sends sparse histogram data to UMA. 1052 virtual bool SendSparseToUMA(const std::string& name, int sample); 1053 1054 // Notifies this object that wake on WiFi has been disabled because of 1055 // excessive dark resume wakes. 1056 virtual void NotifyWakeOnWiFiThrottled(); 1057 1058 // Notifies this object that shill has resumed from a period of suspension 1059 // where wake on WiFi functionality was enabled on the NIC. 1060 virtual void NotifySuspendWithWakeOnWiFiEnabledDone(); 1061 1062 // Notifies this object that a wakeup reason has been received. 1063 virtual void NotifyWakeupReasonReceived(); 1064 1065 #if !defined(DISABLE_WIFI) 1066 // Notifies this object that WakeOnWiFi::OnDarkResume has begun executing, 1067 // and that the dark resume was caused by |reason|. 1068 virtual void NotifyWakeOnWiFiOnDarkResume( 1069 WakeOnWiFi::WakeOnWiFiTrigger reason); 1070 #endif // DISABLE_WIFI 1071 1072 // Notifies this object that a scan was started in dark resume. If 1073 // |is_active_scan| is true, the scan started was an active scan. Otherwise 1074 // the scan started was a passive scan. 1075 // Note: Metrics::NotifyDarkResumeInitiateScan is called when shill initiates 1076 // a scan in dark resume, while Metrics::NotifyScanStartedInDarkResume is 1077 // called when the kernel notifies shill that a scan (shill-initiated or not) 1078 // has actually started. 1079 virtual void NotifyScanStartedInDarkResume(bool is_active_scan); 1080 1081 // Notifies this object that a dark resume scan retry was launched. 1082 virtual void NotifyDarkResumeScanRetry(); 1083 1084 // Notifies this object that shill is about to suspend and is executing 1085 // WakeOnWiFi::BeforeSuspendActions. |is_connected| indicates whether shill 1086 // was connected before suspending, and |in_dark_resume| indicates whether 1087 // shill is current in dark resume. 1088 // Note: this will only be called if wake on WiFi is supported and enabled. 1089 virtual void NotifyBeforeSuspendActions(bool is_connected, 1090 bool in_dark_resume); 1091 1092 // Notifies this object that connection diagnostics have been performed, and 1093 // the connection issue that was diagnosed is |issue|. 1094 virtual void NotifyConnectionDiagnosticsIssue( 1095 const std::string& issue); 1096 1097 private: 1098 friend class MetricsTest; 1099 FRIEND_TEST(MetricsTest, CellularDropsPerHour); 1100 FRIEND_TEST(MetricsTest, FrequencyToChannel); 1101 FRIEND_TEST(MetricsTest, ResetConnectTimer); 1102 FRIEND_TEST(MetricsTest, ServiceFailure); 1103 FRIEND_TEST(MetricsTest, TimeOnlineTimeToDrop); 1104 FRIEND_TEST(MetricsTest, TimeToConfig); 1105 FRIEND_TEST(MetricsTest, TimeToOnline); 1106 FRIEND_TEST(MetricsTest, TimeToPortal); 1107 FRIEND_TEST(MetricsTest, TimeToScanIgnore); 1108 FRIEND_TEST(MetricsTest, WiFiServiceChannel); 1109 FRIEND_TEST(MetricsTest, WiFiServicePostReady); 1110 FRIEND_TEST(MetricsTest, NotifySuspendWithWakeOnWiFiEnabledDone); 1111 FRIEND_TEST(MetricsTest, NotifyWakeOnWiFiThrottled); 1112 FRIEND_TEST(MetricsTest, NotifySuspendActionsCompleted_Success); 1113 FRIEND_TEST(MetricsTest, NotifySuspendActionsCompleted_Failure); 1114 FRIEND_TEST(MetricsTest, NotifyDarkResumeActionsCompleted_Success); 1115 FRIEND_TEST(MetricsTest, NotifyDarkResumeActionsCompleted_Failure); 1116 FRIEND_TEST(MetricsTest, NotifySuspendActionsStarted); 1117 FRIEND_TEST(MetricsTest, NotifyDarkResumeActionsStarted); 1118 FRIEND_TEST(MetricsTest, NotifyDarkResumeInitiateScan); 1119 FRIEND_TEST(MetricsTest, NotifyDarkResumeScanResultsReceived); 1120 FRIEND_TEST(MetricsTest, NotifyDarkResumeScanRetry); 1121 FRIEND_TEST(MetricsTest, NotifyBeforeSuspendActions_InDarkResume); 1122 FRIEND_TEST(MetricsTest, NotifyBeforeSuspendActions_NotInDarkResume); 1123 FRIEND_TEST(WiFiMainTest, GetGeolocationObjects); 1124 1125 typedef ScopedVector<chromeos_metrics::TimerReporter> TimerReporters; 1126 typedef std::list<chromeos_metrics::TimerReporter*> TimerReportersList; 1127 typedef std::map<Service::ConnectState, TimerReportersList> 1128 TimerReportersByState; 1129 struct ServiceMetrics { 1130 // All TimerReporter objects are stored in |timers| which owns the objects. 1131 // |start_on_state| and |stop_on_state| contain pointers to the 1132 // TimerReporter objects and control when to start and stop the timers. 1133 TimerReporters timers; 1134 TimerReportersByState start_on_state; 1135 TimerReportersByState stop_on_state; 1136 }; 1137 typedef std::map<const Service*, std::shared_ptr<ServiceMetrics>> 1138 ServiceMetricsLookupMap; 1139 1140 struct DeviceMetrics { 1141 DeviceMetrics() : auto_connect_tries(0) {} 1142 Technology::Identifier technology; 1143 std::unique_ptr<chromeos_metrics::TimerReporter> initialization_timer; 1144 std::unique_ptr<chromeos_metrics::TimerReporter> enable_timer; 1145 std::unique_ptr<chromeos_metrics::TimerReporter> disable_timer; 1146 std::unique_ptr<chromeos_metrics::TimerReporter> scan_timer; 1147 std::unique_ptr<chromeos_metrics::TimerReporter> connect_timer; 1148 std::unique_ptr<chromeos_metrics::TimerReporter> scan_connect_timer; 1149 std::unique_ptr<chromeos_metrics::TimerReporter> auto_connect_timer; 1150 int auto_connect_tries; 1151 }; 1152 typedef std::map<const int, std::shared_ptr<DeviceMetrics>> 1153 DeviceMetricsLookupMap; 1154 1155 static const uint16_t kWiFiBandwidth5MHz; 1156 static const uint16_t kWiFiBandwidth20MHz; 1157 static const uint16_t kWiFiFrequency2412; 1158 static const uint16_t kWiFiFrequency2472; 1159 static const uint16_t kWiFiFrequency2484; 1160 static const uint16_t kWiFiFrequency5170; 1161 static const uint16_t kWiFiFrequency5180; 1162 static const uint16_t kWiFiFrequency5230; 1163 static const uint16_t kWiFiFrequency5240; 1164 static const uint16_t kWiFiFrequency5320; 1165 static const uint16_t kWiFiFrequency5500; 1166 static const uint16_t kWiFiFrequency5700; 1167 static const uint16_t kWiFiFrequency5745; 1168 static const uint16_t kWiFiFrequency5825; 1169 1170 void InitializeCommonServiceMetrics(const Service& service); 1171 void UpdateServiceStateTransitionMetrics(ServiceMetrics* service_metrics, 1172 Service::ConnectState new_state); 1173 void SendServiceFailure(const Service& service); 1174 1175 DeviceMetrics* GetDeviceMetrics(int interface_index) const; 1176 void AutoConnectMetricsReset(DeviceMetrics* device_metrics); 1177 1178 // Notifies this object about the removal/resetting of a device with given 1179 // technology type. 1180 void NotifyDeviceRemovedEvent(Technology::Identifier technology_id); 1181 1182 // For unit test purposes. 1183 void set_library(MetricsLibraryInterface* library); 1184 void set_time_online_timer(chromeos_metrics::Timer* timer) { 1185 time_online_timer_.reset(timer); // Passes ownership 1186 } 1187 void set_time_to_drop_timer(chromeos_metrics::Timer* timer) { 1188 time_to_drop_timer_.reset(timer); // Passes ownership 1189 } 1190 void set_time_resume_to_ready_timer(chromeos_metrics::Timer* timer) { 1191 time_resume_to_ready_timer_.reset(timer); // Passes ownership 1192 } 1193 void set_time_termination_actions_timer( 1194 chromeos_metrics::Timer* timer) { 1195 time_termination_actions_timer.reset(timer); // Passes ownership 1196 } 1197 void set_time_suspend_actions_timer( 1198 chromeos_metrics::Timer* timer) { 1199 time_suspend_actions_timer.reset(timer); // Passes ownership 1200 } 1201 void set_time_dark_resume_actions_timer( 1202 chromeos_metrics::Timer* timer) { 1203 time_dark_resume_actions_timer.reset(timer); // Passes ownership 1204 } 1205 void set_time_to_scan_timer(int interface_index, 1206 chromeos_metrics::TimerReporter* timer) { 1207 DeviceMetrics* device_metrics = GetDeviceMetrics(interface_index); 1208 device_metrics->scan_timer.reset(timer); // Passes ownership 1209 } 1210 void set_time_to_connect_timer(int interface_index, 1211 chromeos_metrics::TimerReporter* timer) { 1212 DeviceMetrics* device_metrics = GetDeviceMetrics(interface_index); 1213 device_metrics->connect_timer.reset(timer); // Passes ownership 1214 } 1215 void set_time_to_scan_connect_timer(int interface_index, 1216 chromeos_metrics::TimerReporter* timer) { 1217 DeviceMetrics* device_metrics = GetDeviceMetrics(interface_index); 1218 device_metrics->scan_connect_timer.reset(timer); // Passes ownership 1219 } 1220 1221 // |library_| points to |metrics_library_| when shill runs normally. 1222 // However, in order to allow for unit testing, we point |library_| to a 1223 // MetricsLibraryMock object instead. 1224 EventDispatcher* dispatcher_; 1225 MetricsLibrary metrics_library_; 1226 MetricsLibraryInterface* library_; 1227 ServiceMetricsLookupMap services_metrics_; 1228 Technology::Identifier last_default_technology_; 1229 bool was_online_; 1230 std::unique_ptr<chromeos_metrics::Timer> time_online_timer_; 1231 std::unique_ptr<chromeos_metrics::Timer> time_to_drop_timer_; 1232 std::unique_ptr<chromeos_metrics::Timer> time_resume_to_ready_timer_; 1233 std::unique_ptr<chromeos_metrics::Timer> time_termination_actions_timer; 1234 std::unique_ptr<chromeos_metrics::Timer> time_suspend_actions_timer; 1235 std::unique_ptr<chromeos_metrics::Timer> time_dark_resume_actions_timer; 1236 bool collect_bootstats_; 1237 DeviceMetricsLookupMap devices_metrics_; 1238 int num_scan_results_expected_in_dark_resume_; 1239 bool wake_on_wifi_throttled_; 1240 bool wake_reason_received_; 1241 int dark_resume_scan_retries_; 1242 1243 DISALLOW_COPY_AND_ASSIGN(Metrics); 1244 }; 1245 1246 } // namespace shill 1247 1248 #endif // SHILL_METRICS_H_ 1249