Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [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 | #include "shill/metrics.h" |
| 6 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 7 | #include <base/bind.h> |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 8 | #include <base/string_util.h> |
| 9 | #include <base/stringprintf.h> |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 10 | #include <chromeos/dbus/service_constants.h> |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 11 | #include <metrics/bootstat.h> |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 12 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 13 | #include "shill/ieee80211.h" |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 14 | #include "shill/link_monitor.h" |
Christopher Wiley | b691efd | 2012-08-09 13:51:51 -0700 | [diff] [blame] | 15 | #include "shill/logging.h" |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 16 | #include "shill/wifi_service.h" |
| 17 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 18 | using base::Bind; |
| 19 | using base::Unretained; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 20 | using std::string; |
| 21 | using std::tr1::shared_ptr; |
| 22 | |
| 23 | namespace shill { |
| 24 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 25 | // static |
Thieu Le | c31e6f9 | 2012-08-03 13:08:58 -0700 | [diff] [blame] | 26 | // Our disconnect enumeration values are 0 (System Disconnect) and |
| 27 | // 1 (User Disconnect), see histograms.xml, but Chrome needs a minimum |
| 28 | // enum value of 1 and the minimum number of buckets needs to be 3 (see |
| 29 | // histogram.h). Instead of remapping System Disconnect to 1 and |
| 30 | // User Disconnect to 2, we can just leave the enumerated values as-is |
| 31 | // because Chrome implicitly creates a [0-1) bucket for us. Using Min=1, |
| 32 | // Max=2 and NumBuckets=3 gives us the following three buckets: |
| 33 | // [0-1), [1-2), [2-INT_MAX). We end up with an extra bucket [2-INT_MAX) |
| 34 | // that we can safely ignore. |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 35 | const char Metrics::kMetricDisconnect[] = "Network.Shill.%s.Disconnect"; |
Thieu Le | c31e6f9 | 2012-08-03 13:08:58 -0700 | [diff] [blame] | 36 | const int Metrics::kMetricDisconnectMax = 2; |
| 37 | const int Metrics::kMetricDisconnectMin = 1; |
| 38 | const int Metrics::kMetricDisconnectNumBuckets = 3; |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 39 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 40 | const char Metrics::kMetricNetworkChannel[] = "Network.Shill.%s.Channel"; |
| 41 | const int Metrics::kMetricNetworkChannelMax = Metrics::kWiFiChannelMax; |
Paul Stewart | 21f4096 | 2013-03-01 14:27:28 -0800 | [diff] [blame] | 42 | const char Metrics::kMetricNetworkEapInnerProtocol[] = |
| 43 | "Network.Shill.%s.EapInnerProtocol"; |
| 44 | const int Metrics::kMetricNetworkEapInnerProtocolMax = |
| 45 | Metrics::kEapInnerProtocolMax; |
| 46 | const char Metrics::kMetricNetworkEapOuterProtocol[] = |
| 47 | "Network.Shill.%s.EapOuterProtocol"; |
| 48 | const int Metrics::kMetricNetworkEapOuterProtocolMax = |
| 49 | Metrics::kEapOuterProtocolMax; |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 50 | const char Metrics::kMetricNetworkPhyMode[] = "Network.Shill.%s.PhyMode"; |
| 51 | const int Metrics::kMetricNetworkPhyModeMax = Metrics::kWiFiNetworkPhyModeMax; |
| 52 | const char Metrics::kMetricNetworkSecurity[] = "Network.Shill.%s.Security"; |
| 53 | const int Metrics::kMetricNetworkSecurityMax = Metrics::kWiFiSecurityMax; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 54 | const char Metrics::kMetricNetworkServiceErrors[] = |
| 55 | "Network.Shill.ServiceErrors"; |
| 56 | const int Metrics::kMetricNetworkServiceErrorsMax = Service::kFailureMax; |
Paul Stewart | 23b393a | 2012-09-25 21:21:06 -0700 | [diff] [blame] | 57 | const char Metrics::kMetricNetworkSignalStrength[] = |
| 58 | "Network.Shill.%s.SignalStrength"; |
| 59 | const int Metrics::kMetricNetworkSignalStrengthMax = 200; |
| 60 | const int Metrics::kMetricNetworkSignalStrengthMin = 0; |
| 61 | const int Metrics::kMetricNetworkSignalStrengthNumBuckets = 40; |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 62 | |
| 63 | const char Metrics::kMetricTimeOnlineSeconds[] = "Network.Shill.%s.TimeOnline"; |
| 64 | const int Metrics::kMetricTimeOnlineSecondsMax = 8 * 60 * 60; // 8 hours |
| 65 | const int Metrics::kMetricTimeOnlineSecondsMin = 1; |
| 66 | |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 67 | const char Metrics::kMetricTimeToConnectMilliseconds[] = |
| 68 | "Network.Shill.%s.TimeToConnect"; |
| 69 | const int Metrics::kMetricTimeToConnectMillisecondsMax = |
| 70 | 60 * 1000; // 60 seconds |
| 71 | const int Metrics::kMetricTimeToConnectMillisecondsMin = 1; |
| 72 | const int Metrics::kMetricTimeToConnectMillisecondsNumBuckets = 60; |
| 73 | |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 74 | const char Metrics::kMetricTimeToDropSeconds[] = "Network.Shill.TimeToDrop";; |
| 75 | const int Metrics::kMetricTimeToDropSecondsMax = 8 * 60 * 60; // 8 hours |
| 76 | const int Metrics::kMetricTimeToDropSecondsMin = 1; |
| 77 | |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 78 | const char Metrics::kMetricTimeToDisableMilliseconds[] = |
| 79 | "Network.Shill.%s.TimeToDisable"; |
| 80 | const int Metrics::kMetricTimeToDisableMillisecondsMax = |
| 81 | 60 * 1000; // 60 seconds |
| 82 | const int Metrics::kMetricTimeToDisableMillisecondsMin = 1; |
| 83 | const int Metrics::kMetricTimeToDisableMillisecondsNumBuckets = 60; |
| 84 | |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 85 | const char Metrics::kMetricTimeToEnableMilliseconds[] = |
| 86 | "Network.Shill.%s.TimeToEnable"; |
| 87 | const int Metrics::kMetricTimeToEnableMillisecondsMax = |
| 88 | 60 * 1000; // 60 seconds |
| 89 | const int Metrics::kMetricTimeToEnableMillisecondsMin = 1; |
| 90 | const int Metrics::kMetricTimeToEnableMillisecondsNumBuckets = 60; |
| 91 | |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 92 | const char Metrics::kMetricTimeToInitializeMilliseconds[] = |
| 93 | "Network.Shill.%s.TimeToInitialize"; |
Thieu Le | 769d50d | 2013-01-23 17:11:59 -0800 | [diff] [blame] | 94 | const int Metrics::kMetricTimeToInitializeMillisecondsMax = |
| 95 | 30 * 1000; // 30 seconds |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 96 | const int Metrics::kMetricTimeToInitializeMillisecondsMin = 1; |
Thieu Le | 769d50d | 2013-01-23 17:11:59 -0800 | [diff] [blame] | 97 | const int Metrics::kMetricTimeToInitializeMillisecondsNumBuckets = 30; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 98 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 99 | const char Metrics::kMetricTimeResumeToReadyMilliseconds[] = |
| 100 | "Network.Shill.%s.TimeResumeToReady"; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 101 | const char Metrics::kMetricTimeToConfigMilliseconds[] = |
| 102 | "Network.Shill.%s.TimeToConfig"; |
| 103 | const char Metrics::kMetricTimeToJoinMilliseconds[] = |
| 104 | "Network.Shill.%s.TimeToJoin"; |
| 105 | const char Metrics::kMetricTimeToOnlineMilliseconds[] = |
| 106 | "Network.Shill.%s.TimeToOnline"; |
| 107 | const char Metrics::kMetricTimeToPortalMilliseconds[] = |
| 108 | "Network.Shill.%s.TimeToPortal"; |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 109 | |
| 110 | const char Metrics::kMetricTimeToScanMilliseconds[] = |
| 111 | "Network.Shill.%s.TimeToScan"; |
| 112 | const int Metrics::kMetricTimeToScanMillisecondsMax = 180 * 1000; // 3 minutes |
| 113 | const int Metrics::kMetricTimeToScanMillisecondsMin = 1; |
| 114 | const int Metrics::kMetricTimeToScanMillisecondsNumBuckets = 90; |
| 115 | |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 116 | const int Metrics::kTimerHistogramMillisecondsMax = 45 * 1000; |
| 117 | const int Metrics::kTimerHistogramMillisecondsMin = 1; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 118 | const int Metrics::kTimerHistogramNumBuckets = 50; |
| 119 | |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 120 | const char Metrics::kMetricPortalAttempts[] = |
| 121 | "Network.Shill.%s.PortalAttempts"; |
| 122 | const int Metrics::kMetricPortalAttemptsMax = |
| 123 | PortalDetector::kMaxRequestAttempts; |
| 124 | const int Metrics::kMetricPortalAttemptsMin = 1; |
| 125 | const int Metrics::kMetricPortalAttemptsNumBuckets = |
| 126 | Metrics::kMetricPortalAttemptsMax; |
| 127 | |
| 128 | const char Metrics::kMetricPortalAttemptsToOnline[] = |
| 129 | "Network.Shill.%s.PortalAttemptsToOnline"; |
| 130 | const int Metrics::kMetricPortalAttemptsToOnlineMax = 100; |
| 131 | const int Metrics::kMetricPortalAttemptsToOnlineMin = 1; |
| 132 | const int Metrics::kMetricPortalAttemptsToOnlineNumBuckets = 10; |
| 133 | |
| 134 | const char Metrics::kMetricPortalResult[] = "Network.Shill.%s.PortalResult"; |
| 135 | |
Wade Guthrie | 60a3706 | 2013-04-02 11:39:09 -0700 | [diff] [blame] | 136 | const char Metrics::kMetricFrequenciesConnectedEver[] = |
| 137 | "Network.Shill.WiFi.FrequenciesConnectedEver"; |
| 138 | const int Metrics::kMetricFrequenciesConnectedMax = 50; |
| 139 | const int Metrics::kMetricFrequenciesConnectedMin = 1; |
| 140 | const int Metrics::kMetricFrequenciesConnectedNumBuckets = 50; |
| 141 | |
Wade Guthrie | f22681f | 2013-05-31 11:46:31 -0700 | [diff] [blame] | 142 | const char Metrics::kMetricWiFiScanTimeInEbusyMilliseconds[] = |
| 143 | "Network.Shill.WiFi.ScanTimeInEbusy"; |
| 144 | |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 145 | const char Metrics::kMetricTerminationActionTimeOnTerminate[] = |
| 146 | "Network.Shill.TerminationActionTime.OnTerminate"; |
| 147 | const char Metrics::kMetricTerminationActionResultOnTerminate[] = |
| 148 | "Network.Shill.TerminationActionResult.OnTerminate"; |
| 149 | const char Metrics::kMetricTerminationActionTimeOnSuspend[] = |
| 150 | "Network.Shill.TerminationActionTime.OnSuspend"; |
| 151 | const char Metrics::kMetricTerminationActionResultOnSuspend[] = |
| 152 | "Network.Shill.TerminationActionResult.OnSuspend"; |
| 153 | const int Metrics::kMetricTerminationActionTimeMillisecondsMax = 10000; |
| 154 | const int Metrics::kMetricTerminationActionTimeMillisecondsMin = 1; |
Arman Uguray | 6d528f1 | 2012-09-13 13:44:55 -0700 | [diff] [blame] | 155 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 156 | // static |
Paul Stewart | 85aea15 | 2013-01-22 09:31:56 -0800 | [diff] [blame] | 157 | const char Metrics::kMetricServiceFixupEntries[] = |
| 158 | "Network.Shill.%s.ServiceFixupEntries"; |
| 159 | |
| 160 | // static |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 161 | const uint16 Metrics::kWiFiBandwidth5MHz = 5; |
| 162 | const uint16 Metrics::kWiFiBandwidth20MHz = 20; |
| 163 | const uint16 Metrics::kWiFiFrequency2412 = 2412; |
| 164 | const uint16 Metrics::kWiFiFrequency2472 = 2472; |
| 165 | const uint16 Metrics::kWiFiFrequency2484 = 2484; |
| 166 | const uint16 Metrics::kWiFiFrequency5170 = 5170; |
| 167 | const uint16 Metrics::kWiFiFrequency5180 = 5180; |
| 168 | const uint16 Metrics::kWiFiFrequency5230 = 5230; |
| 169 | const uint16 Metrics::kWiFiFrequency5240 = 5240; |
| 170 | const uint16 Metrics::kWiFiFrequency5320 = 5320; |
| 171 | const uint16 Metrics::kWiFiFrequency5500 = 5500; |
| 172 | const uint16 Metrics::kWiFiFrequency5700 = 5700; |
| 173 | const uint16 Metrics::kWiFiFrequency5745 = 5745; |
| 174 | const uint16 Metrics::kWiFiFrequency5825 = 5825; |
| 175 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 176 | // static |
| 177 | const char Metrics::kMetricPowerManagerKey[] = "metrics"; |
| 178 | |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 179 | // static |
| 180 | const char Metrics::kMetricLinkMonitorFailure[] = |
| 181 | "Network.Shill.%s.LinkMonitorFailure"; |
| 182 | const char Metrics::kMetricLinkMonitorResponseTimeSample[] = |
| 183 | "Network.Shill.%s.LinkMonitorResponseTimeSample"; |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 184 | const int Metrics::kMetricLinkMonitorResponseTimeSampleMin = 0; |
| 185 | const int Metrics::kMetricLinkMonitorResponseTimeSampleMax = |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 186 | LinkMonitor::kTestPeriodMilliseconds; |
| 187 | const int Metrics::kMetricLinkMonitorResponseTimeSampleNumBuckets = 50; |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 188 | const char Metrics::kMetricLinkMonitorSecondsToFailure[] = |
| 189 | "Network.Shill.%s.LinkMonitorSecondsToFailure"; |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 190 | const int Metrics::kMetricLinkMonitorSecondsToFailureMin = 0; |
| 191 | const int Metrics::kMetricLinkMonitorSecondsToFailureMax = 7200; |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 192 | const int Metrics::kMetricLinkMonitorSecondsToFailureNumBuckets = 50; |
| 193 | const char Metrics::kMetricLinkMonitorBroadcastErrorsAtFailure[] = |
| 194 | "Network.Shill.%s.LinkMonitorBroadcastErrorsAtFailure"; |
| 195 | const char Metrics::kMetricLinkMonitorUnicastErrorsAtFailure[] = |
| 196 | "Network.Shill.%s.LinkMonitorUnicastErrorsAtFailure"; |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 197 | const int Metrics::kMetricLinkMonitorErrorCountMin = 0; |
| 198 | const int Metrics::kMetricLinkMonitorErrorCountMax = |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 199 | LinkMonitor::kFailureThreshold; |
| 200 | const int Metrics::kMetricLinkMonitorErrorCountNumBuckets = |
| 201 | LinkMonitor::kFailureThreshold + 1; |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 202 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 203 | // static |
| 204 | const char Metrics::kMetricLinkClientDisconnectReason[] = |
| 205 | "Network.Shill.WiFi.ClientDisconnectReason"; |
| 206 | const char Metrics::kMetricLinkApDisconnectReason[] = |
| 207 | "Network.Shill.WiFi.ApDisconnectReason"; |
| 208 | const char Metrics::kMetricLinkClientDisconnectType[] = |
| 209 | "Network.Shill.WiFi.ClientDisconnectType"; |
| 210 | const char Metrics::kMetricLinkApDisconnectType[] = |
| 211 | "Network.Shill.WiFi.ApDisconnectType"; |
| 212 | |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 213 | // static |
Thieu Le | 91fccf6 | 2013-04-22 15:23:16 -0700 | [diff] [blame] | 214 | const char Metrics::kMetricCellularAutoConnectTries[] = |
| 215 | "Network.Shill.Cellular.AutoConnectTries"; |
| 216 | const int Metrics::kMetricCellularAutoConnectTriesMax = 20; |
| 217 | const int Metrics::kMetricCellularAutoConnectTriesMin = 1; |
| 218 | const int Metrics::kMetricCellularAutoConnectTriesNumBuckets = 20; |
| 219 | const char Metrics::kMetricCellularAutoConnectTotalTime[] = |
| 220 | "Network.Shill.Cellular.AutoConnectTotalTime"; |
| 221 | const int Metrics::kMetricCellularAutoConnectTotalTimeMax = |
| 222 | 60 * 1000; // 60 seconds |
| 223 | const int Metrics::kMetricCellularAutoConnectTotalTimeMin = 0; |
| 224 | const int Metrics::kMetricCellularAutoConnectTotalTimeNumBuckets = 60; |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 225 | const char Metrics::kMetricCellularDrop[] = |
| 226 | "Network.Shill.Cellular.Drop"; |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 227 | const char Metrics::kMetricCellularDropsPerHour[] = |
| 228 | "Network.Shill.Cellular.DropsPerHour"; |
| 229 | const int Metrics::kMetricCellularDropsPerHourMax = 60; |
| 230 | const int Metrics::kMetricCellularDropsPerHourMin = 1; |
| 231 | const int Metrics::kMetricCellularDropsPerHourNumBuckets = 10; |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 232 | // The format of FailureReason is different to other metrics because this |
| 233 | // name is prepended to the error message before the entire string is sent |
| 234 | // via SendUserActionToUMA. |
| 235 | const char Metrics::kMetricCellularFailureReason[] = |
| 236 | "Network.Shill.Cellular.FailureReason: "; |
Thieu Le | 91fccf6 | 2013-04-22 15:23:16 -0700 | [diff] [blame] | 237 | const char Metrics::kMetricCellularOutOfCreditsReason[] = |
| 238 | "Network.Shill.Cellular.OutOfCreditsReason"; |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 239 | const char Metrics::kMetricCellularSignalStrengthBeforeDrop[] = |
| 240 | "Network.Shill.Cellular.SignalStrengthBeforeDrop"; |
| 241 | const int Metrics::kMetricCellularSignalStrengthBeforeDropMax = 100; |
| 242 | const int Metrics::kMetricCellularSignalStrengthBeforeDropMin = 0; |
| 243 | const int Metrics::kMetricCellularSignalStrengthBeforeDropNumBuckets = 10; |
| 244 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 245 | // static |
Thieu Le | 5133b71 | 2013-02-19 14:47:21 -0800 | [diff] [blame] | 246 | const char Metrics::kMetricCorruptedProfile[] = |
| 247 | "Network.Shill.CorruptedProfile"; |
| 248 | |
| 249 | // static |
Paul Stewart | 91a43cb | 2013-03-02 21:34:15 -0800 | [diff] [blame] | 250 | const char Metrics::kMetricVpnDriver[] = |
| 251 | "Network.Shill.Vpn.Driver"; |
| 252 | const int Metrics::kMetricVpnDriverMax = Metrics::kVpnDriverMax; |
| 253 | const char Metrics::kMetricVpnRemoteAuthenticationType[] = |
| 254 | "Network.Shill.Vpn.RemoteAuthenticationType"; |
| 255 | const int Metrics::kMetricVpnRemoteAuthenticationTypeMax = |
| 256 | Metrics::kVpnRemoteAuthenticationTypeMax; |
| 257 | const char Metrics::kMetricVpnUserAuthenticationType[] = |
| 258 | "Network.Shill.Vpn.UserAuthenticationType"; |
| 259 | const int Metrics::kMetricVpnUserAuthenticationTypeMax = |
| 260 | Metrics::kVpnUserAuthenticationTypeMax; |
| 261 | |
| 262 | // static |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 263 | const int Metrics::kHourlyTimeoutMilliseconds = 3600 * 1000; // One hour |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 264 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 265 | |
| 266 | Metrics::Metrics(EventDispatcher *dispatcher) |
| 267 | : dispatcher_(dispatcher), |
| 268 | library_(&metrics_library_), |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 269 | last_default_technology_(Technology::kUnknown), |
| 270 | was_online_(false), |
| 271 | time_online_timer_(new chromeos_metrics::Timer), |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 272 | time_to_drop_timer_(new chromeos_metrics::Timer), |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 273 | time_resume_to_ready_timer_(new chromeos_metrics::Timer), |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 274 | time_termination_actions_timer(new chromeos_metrics::Timer), |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 275 | collect_bootstats_(true) { |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 276 | metrics_library_.Init(); |
| 277 | chromeos_metrics::TimerReporter::set_metrics_lib(library_); |
| 278 | } |
| 279 | |
| 280 | Metrics::~Metrics() {} |
| 281 | |
| 282 | // static |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 283 | Metrics::WiFiChannel Metrics::WiFiFrequencyToChannel(uint16 frequency) { |
| 284 | WiFiChannel channel = kWiFiChannelUndef; |
| 285 | if (kWiFiFrequency2412 <= frequency && frequency <= kWiFiFrequency2472) { |
| 286 | if (((frequency - kWiFiFrequency2412) % kWiFiBandwidth5MHz) == 0) |
| 287 | channel = static_cast<WiFiChannel>( |
| 288 | kWiFiChannel2412 + |
| 289 | (frequency - kWiFiFrequency2412) / kWiFiBandwidth5MHz); |
| 290 | } else if (frequency == kWiFiFrequency2484) { |
| 291 | channel = kWiFiChannel2484; |
| 292 | } else if (kWiFiFrequency5170 <= frequency && |
| 293 | frequency <= kWiFiFrequency5230) { |
| 294 | if ((frequency % kWiFiBandwidth20MHz) == 0) |
| 295 | channel = static_cast<WiFiChannel>( |
| 296 | kWiFiChannel5180 + |
| 297 | (frequency - kWiFiFrequency5180) / kWiFiBandwidth20MHz); |
| 298 | if ((frequency % kWiFiBandwidth20MHz) == 10) |
| 299 | channel = static_cast<WiFiChannel>( |
| 300 | kWiFiChannel5170 + |
| 301 | (frequency - kWiFiFrequency5170) / kWiFiBandwidth20MHz); |
| 302 | } else if (kWiFiFrequency5240 <= frequency && |
| 303 | frequency <= kWiFiFrequency5320) { |
| 304 | if (((frequency - kWiFiFrequency5180) % kWiFiBandwidth20MHz) == 0) |
| 305 | channel = static_cast<WiFiChannel>( |
| 306 | kWiFiChannel5180 + |
| 307 | (frequency - kWiFiFrequency5180) / kWiFiBandwidth20MHz); |
| 308 | } else if (kWiFiFrequency5500 <= frequency && |
| 309 | frequency <= kWiFiFrequency5700) { |
| 310 | if (((frequency - kWiFiFrequency5500) % kWiFiBandwidth20MHz) == 0) |
| 311 | channel = static_cast<WiFiChannel>( |
| 312 | kWiFiChannel5500 + |
| 313 | (frequency - kWiFiFrequency5500) / kWiFiBandwidth20MHz); |
| 314 | } else if (kWiFiFrequency5745 <= frequency && |
| 315 | frequency <= kWiFiFrequency5825) { |
| 316 | if (((frequency - kWiFiFrequency5745) % kWiFiBandwidth20MHz) == 0) |
| 317 | channel = static_cast<WiFiChannel>( |
| 318 | kWiFiChannel5745 + |
| 319 | (frequency - kWiFiFrequency5745) / kWiFiBandwidth20MHz); |
| 320 | } |
| 321 | CHECK(kWiFiChannelUndef <= channel && channel < kWiFiChannelMax); |
| 322 | |
| 323 | if (channel == kWiFiChannelUndef) |
| 324 | LOG(WARNING) << "no mapping for frequency " << frequency; |
| 325 | else |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 326 | SLOG(Metrics, 3) << "map " << frequency << " to " << channel; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 327 | |
| 328 | return channel; |
| 329 | } |
| 330 | |
Thieu Le | ad1ec2c | 2012-01-05 23:39:48 +0000 | [diff] [blame] | 331 | // static |
| 332 | Metrics::WiFiSecurity Metrics::WiFiSecurityStringToEnum( |
| 333 | const std::string &security) { |
| 334 | if (security == flimflam::kSecurityNone) { |
| 335 | return kWiFiSecurityNone; |
| 336 | } else if (security == flimflam::kSecurityWep) { |
| 337 | return kWiFiSecurityWep; |
| 338 | } else if (security == flimflam::kSecurityWpa) { |
| 339 | return kWiFiSecurityWpa; |
| 340 | } else if (security == flimflam::kSecurityRsn) { |
| 341 | return kWiFiSecurityRsn; |
| 342 | } else if (security == flimflam::kSecurity8021x) { |
| 343 | return kWiFiSecurity8021x; |
| 344 | } else if (security == flimflam::kSecurityPsk) { |
| 345 | return kWiFiSecurityPsk; |
| 346 | } else { |
| 347 | return kWiFiSecurityUnknown; |
| 348 | } |
| 349 | } |
| 350 | |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 351 | // static |
Paul Stewart | 21f4096 | 2013-03-01 14:27:28 -0800 | [diff] [blame] | 352 | Metrics::EapOuterProtocol Metrics::EapOuterProtocolStringToEnum( |
| 353 | const std::string &outer) { |
| 354 | if (outer == flimflam::kEapMethodPEAP) { |
| 355 | return kEapOuterProtocolPeap; |
| 356 | } else if (outer == flimflam::kEapMethodTLS) { |
| 357 | return kEapOuterProtocolTls; |
| 358 | } else if (outer == flimflam::kEapMethodTTLS) { |
| 359 | return kEapOuterProtocolTtls; |
| 360 | } else if (outer == flimflam::kEapMethodLEAP) { |
| 361 | return kEapOuterProtocolLeap; |
| 362 | } else { |
| 363 | return kEapOuterProtocolUnknown; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | // static |
| 368 | Metrics::EapInnerProtocol Metrics::EapInnerProtocolStringToEnum( |
| 369 | const std::string &inner) { |
| 370 | if (inner.empty()) { |
| 371 | return kEapInnerProtocolNone; |
| 372 | } else if (inner == flimflam::kEapPhase2AuthPEAPMD5) { |
| 373 | return kEapInnerProtocolPeapMd5; |
| 374 | } else if (inner == flimflam::kEapPhase2AuthPEAPMSCHAPV2) { |
| 375 | return kEapInnerProtocolPeapMschapv2; |
| 376 | } else if (inner == flimflam::kEapPhase2AuthTTLSEAPMD5) { |
| 377 | return kEapInnerProtocolTtlsEapMd5; |
| 378 | } else if (inner == flimflam::kEapPhase2AuthTTLSEAPMSCHAPV2) { |
| 379 | return kEapInnerProtocolTtlsEapMschapv2; |
| 380 | } else if (inner == flimflam::kEapPhase2AuthTTLSMSCHAPV2) { |
| 381 | return kEapInnerProtocolTtlsMschapv2; |
| 382 | } else if (inner == flimflam::kEapPhase2AuthTTLSMSCHAP) { |
| 383 | return kEapInnerProtocolTtlsMschap; |
| 384 | } else if (inner == flimflam::kEapPhase2AuthTTLSPAP) { |
| 385 | return kEapInnerProtocolTtlsPap; |
| 386 | } else if (inner == flimflam::kEapPhase2AuthTTLSCHAP) { |
| 387 | return kEapInnerProtocolTtlsChap; |
| 388 | } else { |
| 389 | return kEapInnerProtocolUnknown; |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | // static |
Thieu Le | 85e050b | 2012-03-13 15:04:38 -0700 | [diff] [blame] | 394 | Metrics::PortalResult Metrics::PortalDetectionResultToEnum( |
| 395 | const PortalDetector::Result &result) { |
| 396 | DCHECK(result.final); |
| 397 | PortalResult retval = kPortalResultUnknown; |
| 398 | // The only time we should end a successful portal detection is when we're |
| 399 | // in the Content phase. If we end with kStatusSuccess in any other phase, |
| 400 | // then this indicates that something bad has happened. |
| 401 | switch (result.phase) { |
| 402 | case PortalDetector::kPhaseDNS: |
| 403 | if (result.status == PortalDetector::kStatusFailure) |
| 404 | retval = kPortalResultDNSFailure; |
| 405 | else if (result.status == PortalDetector::kStatusTimeout) |
| 406 | retval = kPortalResultDNSTimeout; |
| 407 | else |
| 408 | LOG(DFATAL) << __func__ << ": Final result status " << result.status |
| 409 | << " is not allowed in the DNS phase"; |
| 410 | break; |
| 411 | |
| 412 | case PortalDetector::kPhaseConnection: |
| 413 | if (result.status == PortalDetector::kStatusFailure) |
| 414 | retval = kPortalResultConnectionFailure; |
| 415 | else if (result.status == PortalDetector::kStatusTimeout) |
| 416 | retval = kPortalResultConnectionTimeout; |
| 417 | else |
| 418 | LOG(DFATAL) << __func__ << ": Final result status " << result.status |
| 419 | << " is not allowed in the Connection phase"; |
| 420 | break; |
| 421 | |
| 422 | case PortalDetector::kPhaseHTTP: |
| 423 | if (result.status == PortalDetector::kStatusFailure) |
| 424 | retval = kPortalResultHTTPFailure; |
| 425 | else if (result.status == PortalDetector::kStatusTimeout) |
| 426 | retval = kPortalResultHTTPTimeout; |
| 427 | else |
| 428 | LOG(DFATAL) << __func__ << ": Final result status " << result.status |
| 429 | << " is not allowed in the HTTP phase"; |
| 430 | break; |
| 431 | |
| 432 | case PortalDetector::kPhaseContent: |
| 433 | if (result.status == PortalDetector::kStatusSuccess) |
| 434 | retval = kPortalResultSuccess; |
| 435 | else if (result.status == PortalDetector::kStatusFailure) |
| 436 | retval = kPortalResultContentFailure; |
| 437 | else if (result.status == PortalDetector::kStatusTimeout) |
| 438 | retval = kPortalResultContentTimeout; |
| 439 | else |
| 440 | LOG(DFATAL) << __func__ << ": Final result status " << result.status |
| 441 | << " is not allowed in the Content phase"; |
| 442 | break; |
| 443 | |
| 444 | case PortalDetector::kPhaseUnknown: |
| 445 | retval = kPortalResultUnknown; |
| 446 | break; |
| 447 | |
| 448 | default: |
| 449 | LOG(DFATAL) << __func__ << ": Invalid phase " << result.phase; |
| 450 | break; |
| 451 | } |
| 452 | |
| 453 | return retval; |
| 454 | } |
| 455 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 456 | void Metrics::Start() { |
| 457 | SLOG(Metrics, 2) << __func__; |
| 458 | hourly_timeout_handler_.Reset( |
| 459 | Bind(&Metrics::HourlyTimeoutHandler, Unretained(this))); |
| 460 | dispatcher_->PostDelayedTask(hourly_timeout_handler_.callback(), |
| 461 | kHourlyTimeoutMilliseconds); |
| 462 | } |
| 463 | |
| 464 | void Metrics::Stop() { |
| 465 | SLOG(Metrics, 2) << __func__; |
| 466 | hourly_timeout_handler_.Cancel(); |
| 467 | } |
| 468 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 469 | void Metrics::RegisterService(const Service *service) { |
| 470 | shared_ptr<ServiceMetrics> service_metrics(new ServiceMetrics); |
| 471 | services_metrics_[service] = service_metrics; |
| 472 | service_metrics->service = service; |
| 473 | InitializeCommonServiceMetrics(service); |
| 474 | service->InitializeCustomMetrics(); |
| 475 | } |
| 476 | |
| 477 | void Metrics::DeregisterService(const Service *service) { |
| 478 | services_metrics_.erase(service); |
| 479 | } |
| 480 | |
| 481 | void Metrics::AddServiceStateTransitionTimer( |
| 482 | const Service *service, |
| 483 | const string &histogram_name, |
| 484 | Service::ConnectState start_state, |
| 485 | Service::ConnectState stop_state) { |
| 486 | ServiceMetricsLookupMap::iterator it = services_metrics_.find(service); |
| 487 | if (it == services_metrics_.end()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 488 | SLOG(Metrics, 1) << "service not found"; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 489 | DCHECK(false); |
| 490 | return; |
| 491 | } |
| 492 | ServiceMetrics *service_metrics = it->second.get(); |
| 493 | CHECK(start_state < stop_state); |
| 494 | chromeos_metrics::TimerReporter *timer = |
| 495 | new chromeos_metrics::TimerReporter(histogram_name, |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 496 | kTimerHistogramMillisecondsMin, |
| 497 | kTimerHistogramMillisecondsMax, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 498 | kTimerHistogramNumBuckets); |
| 499 | service_metrics->timers.push_back(timer); // passes ownership. |
| 500 | service_metrics->start_on_state[start_state].push_back(timer); |
| 501 | service_metrics->stop_on_state[stop_state].push_back(timer); |
| 502 | } |
| 503 | |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 504 | void Metrics::NotifyDefaultServiceChanged(const Service *service) { |
| 505 | base::TimeDelta elapsed_seconds; |
| 506 | |
| 507 | Technology::Identifier technology = (service) ? service->technology() : |
| 508 | Technology::kUnknown; |
| 509 | if (technology != last_default_technology_) { |
| 510 | if (last_default_technology_ != Technology::kUnknown) { |
| 511 | string histogram = GetFullMetricName(kMetricTimeOnlineSeconds, |
| 512 | last_default_technology_); |
| 513 | time_online_timer_->GetElapsedTime(&elapsed_seconds); |
| 514 | SendToUMA(histogram, |
| 515 | elapsed_seconds.InSeconds(), |
| 516 | kMetricTimeOnlineSecondsMin, |
| 517 | kMetricTimeOnlineSecondsMax, |
| 518 | kTimerHistogramNumBuckets); |
| 519 | } |
| 520 | last_default_technology_ = technology; |
| 521 | time_online_timer_->Start(); |
| 522 | } |
| 523 | |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 524 | // Ignore changes that are not online/offline transitions; e.g. |
| 525 | // switching between wired and wireless. TimeToDrop measures |
| 526 | // time online regardless of how we are connected. |
| 527 | if ((service == NULL && !was_online_) || (service != NULL && was_online_)) |
| 528 | return; |
| 529 | |
| 530 | if (service == NULL) { |
| 531 | time_to_drop_timer_->GetElapsedTime(&elapsed_seconds); |
| 532 | SendToUMA(kMetricTimeToDropSeconds, |
| 533 | elapsed_seconds.InSeconds(), |
| 534 | kMetricTimeToDropSecondsMin, |
| 535 | kMetricTimeToDropSecondsMax, |
| 536 | kTimerHistogramNumBuckets); |
| 537 | } else { |
| 538 | time_to_drop_timer_->Start(); |
| 539 | } |
| 540 | |
| 541 | was_online_ = (service != NULL); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 542 | } |
| 543 | |
| 544 | void Metrics::NotifyServiceStateChanged(const Service *service, |
| 545 | Service::ConnectState new_state) { |
| 546 | ServiceMetricsLookupMap::iterator it = services_metrics_.find(service); |
| 547 | if (it == services_metrics_.end()) { |
Ben Chan | fad4a0b | 2012-04-18 15:49:59 -0700 | [diff] [blame] | 548 | SLOG(Metrics, 1) << "service not found"; |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 549 | DCHECK(false); |
| 550 | return; |
| 551 | } |
| 552 | ServiceMetrics *service_metrics = it->second.get(); |
| 553 | UpdateServiceStateTransitionMetrics(service_metrics, new_state); |
| 554 | |
| 555 | if (new_state == Service::kStateFailure) |
| 556 | SendServiceFailure(service); |
| 557 | |
Darin Petkov | 58f0b6d | 2012-06-12 12:52:30 +0200 | [diff] [blame] | 558 | if (collect_bootstats_) { |
| 559 | bootstat_log( |
| 560 | StringPrintf("network-%s-%s", |
| 561 | Technology::NameFromIdentifier( |
| 562 | service->technology()).c_str(), |
| 563 | service->GetStateString().c_str()).c_str()); |
| 564 | } |
| 565 | |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 566 | if (new_state != Service::kStateConnected) |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 567 | return; |
| 568 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 569 | base::TimeDelta time_resume_to_ready; |
| 570 | time_resume_to_ready_timer_->GetElapsedTime(&time_resume_to_ready); |
| 571 | time_resume_to_ready_timer_->Reset(); |
| 572 | service->SendPostReadyStateMetrics(time_resume_to_ready.InMilliseconds()); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 573 | } |
| 574 | |
| 575 | string Metrics::GetFullMetricName(const char *metric_name, |
| 576 | Technology::Identifier technology_id) { |
| 577 | string technology = Technology::NameFromIdentifier(technology_id); |
| 578 | technology[0] = base::ToUpperASCII(technology[0]); |
| 579 | return base::StringPrintf(metric_name, technology.c_str()); |
| 580 | } |
| 581 | |
Thieu Le | 67370f6 | 2012-02-14 23:01:42 +0000 | [diff] [blame] | 582 | void Metrics::NotifyServiceDisconnect(const Service *service) { |
| 583 | Technology::Identifier technology = service->technology(); |
| 584 | string histogram = GetFullMetricName(kMetricDisconnect, technology); |
| 585 | SendToUMA(histogram, |
| 586 | service->explicitly_disconnected(), |
| 587 | kMetricDisconnectMin, |
| 588 | kMetricDisconnectMax, |
| 589 | kMetricDisconnectNumBuckets); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 590 | } |
| 591 | |
Thieu Le | b84ba34 | 2012-03-02 15:15:19 -0800 | [diff] [blame] | 592 | void Metrics::NotifyPowerStateChange(PowerManager::SuspendState new_state) { |
| 593 | if (new_state == PowerManagerProxyDelegate::kOn) { |
| 594 | time_resume_to_ready_timer_->Start(); |
| 595 | } else { |
| 596 | time_resume_to_ready_timer_->Reset(); |
| 597 | } |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 598 | } |
| 599 | |
Arman Uguray | ab22c16 | 2012-10-08 19:08:38 -0700 | [diff] [blame] | 600 | void Metrics::NotifyTerminationActionsStarted( |
| 601 | TerminationActionReason /*reason*/) { |
| 602 | if (time_termination_actions_timer->HasStarted()) |
| 603 | return; |
| 604 | time_termination_actions_timer->Start(); |
| 605 | } |
| 606 | |
| 607 | void Metrics::NotifyTerminationActionsCompleted( |
| 608 | TerminationActionReason reason, bool success) { |
| 609 | if (!time_termination_actions_timer->HasStarted()) |
| 610 | return; |
| 611 | |
| 612 | int result = success ? kTerminationActionResultSuccess : |
| 613 | kTerminationActionResultFailure; |
| 614 | |
| 615 | base::TimeDelta elapsed_time; |
| 616 | time_termination_actions_timer->GetElapsedTime(&elapsed_time); |
| 617 | time_termination_actions_timer->Reset(); |
| 618 | string time_metric, result_metric; |
| 619 | switch (reason) { |
| 620 | case kTerminationActionReasonSuspend: |
| 621 | time_metric = kMetricTerminationActionTimeOnSuspend; |
| 622 | result_metric = kMetricTerminationActionResultOnSuspend; |
| 623 | break; |
| 624 | case kTerminationActionReasonTerminate: |
| 625 | time_metric = kMetricTerminationActionTimeOnTerminate; |
| 626 | result_metric = kMetricTerminationActionResultOnTerminate; |
| 627 | break; |
| 628 | } |
| 629 | |
| 630 | SendToUMA(time_metric, |
| 631 | elapsed_time.InMilliseconds(), |
| 632 | kMetricTerminationActionTimeMillisecondsMin, |
| 633 | kMetricTerminationActionTimeMillisecondsMax, |
| 634 | kTimerHistogramNumBuckets); |
| 635 | |
| 636 | SendEnumToUMA(result_metric, |
| 637 | result, |
| 638 | kTerminationActionResultMax); |
| 639 | } |
| 640 | |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 641 | void Metrics::NotifyLinkMonitorFailure( |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 642 | Technology::Identifier technology, |
| 643 | LinkMonitorFailure failure, |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 644 | int seconds_to_failure, |
| 645 | int broadcast_error_count, |
| 646 | int unicast_error_count) { |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 647 | string histogram = GetFullMetricName(kMetricLinkMonitorFailure, |
| 648 | technology); |
| 649 | SendEnumToUMA(histogram, failure, kLinkMonitorFailureMax); |
Paul Stewart | 0443aa5 | 2012-08-09 10:43:50 -0700 | [diff] [blame] | 650 | |
| 651 | if (failure == kLinkMonitorFailureThresholdReached) { |
| 652 | if (seconds_to_failure > kMetricLinkMonitorSecondsToFailureMax) { |
| 653 | seconds_to_failure = kMetricLinkMonitorSecondsToFailureMax; |
| 654 | } |
| 655 | histogram = GetFullMetricName(kMetricLinkMonitorSecondsToFailure, |
| 656 | technology); |
| 657 | SendToUMA(histogram, |
| 658 | seconds_to_failure, |
| 659 | kMetricLinkMonitorSecondsToFailureMin, |
| 660 | kMetricLinkMonitorSecondsToFailureMax, |
| 661 | kMetricLinkMonitorSecondsToFailureNumBuckets); |
| 662 | histogram = GetFullMetricName(kMetricLinkMonitorBroadcastErrorsAtFailure, |
| 663 | technology); |
| 664 | SendToUMA(histogram, |
| 665 | broadcast_error_count, |
| 666 | kMetricLinkMonitorErrorCountMin, |
| 667 | kMetricLinkMonitorErrorCountMax, |
| 668 | kMetricLinkMonitorErrorCountNumBuckets); |
| 669 | histogram = GetFullMetricName(kMetricLinkMonitorUnicastErrorsAtFailure, |
| 670 | technology); |
| 671 | SendToUMA(histogram, |
| 672 | unicast_error_count, |
| 673 | kMetricLinkMonitorErrorCountMin, |
| 674 | kMetricLinkMonitorErrorCountMax, |
| 675 | kMetricLinkMonitorErrorCountNumBuckets); |
| 676 | } |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | void Metrics::NotifyLinkMonitorResponseTimeSampleAdded( |
| 680 | Technology::Identifier technology, |
Paul Stewart | f1961f8 | 2012-09-11 20:45:39 -0700 | [diff] [blame] | 681 | int response_time_milliseconds) { |
Paul Stewart | ff845fc | 2012-08-07 07:28:44 -0700 | [diff] [blame] | 682 | string histogram = GetFullMetricName(kMetricLinkMonitorResponseTimeSample, |
| 683 | technology); |
| 684 | SendToUMA(histogram, |
| 685 | response_time_milliseconds, |
| 686 | kMetricLinkMonitorResponseTimeSampleMin, |
| 687 | kMetricLinkMonitorResponseTimeSampleMax, |
| 688 | kMetricLinkMonitorResponseTimeSampleNumBuckets); |
| 689 | } |
| 690 | |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 691 | void Metrics::Notify80211Disconnect(WiFiDisconnectByWhom by_whom, |
| 692 | IEEE_80211::WiFiReasonCode reason) { |
| 693 | string metric_disconnect_reason; |
| 694 | string metric_disconnect_type; |
| 695 | WiFiStatusType type; |
| 696 | |
| 697 | if (by_whom == kDisconnectedByAp) { |
| 698 | metric_disconnect_reason = kMetricLinkApDisconnectReason; |
| 699 | metric_disconnect_type = kMetricLinkApDisconnectType; |
| 700 | type = kStatusCodeTypeByAp; |
| 701 | } else { |
| 702 | metric_disconnect_reason = kMetricLinkClientDisconnectReason; |
| 703 | metric_disconnect_type = kMetricLinkClientDisconnectType; |
Wade Guthrie | 60a3706 | 2013-04-02 11:39:09 -0700 | [diff] [blame] | 704 | switch (reason) { |
Wade Guthrie | d4977f2 | 2012-08-22 12:37:54 -0700 | [diff] [blame] | 705 | case IEEE_80211::kReasonCodeSenderHasLeft: |
| 706 | case IEEE_80211::kReasonCodeDisassociatedHasLeft: |
| 707 | type = kStatusCodeTypeByUser; |
| 708 | break; |
| 709 | |
| 710 | case IEEE_80211::kReasonCodeInactivity: |
| 711 | type = kStatusCodeTypeConsideredDead; |
| 712 | break; |
| 713 | |
| 714 | default: |
| 715 | type = kStatusCodeTypeByClient; |
| 716 | break; |
| 717 | } |
| 718 | } |
| 719 | SendEnumToUMA(metric_disconnect_reason, reason, |
| 720 | IEEE_80211::kStatusCodeMax); |
| 721 | SendEnumToUMA(metric_disconnect_type, type, kStatusCodeTypeMax); |
| 722 | } |
| 723 | |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 724 | void Metrics::RegisterDevice(int interface_index, |
| 725 | Technology::Identifier technology) { |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 726 | SLOG(Metrics, 2) << __func__ << ": " << interface_index; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 727 | shared_ptr<DeviceMetrics> device_metrics(new DeviceMetrics); |
| 728 | devices_metrics_[interface_index] = device_metrics; |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 729 | device_metrics->technology = technology; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 730 | string histogram = GetFullMetricName(kMetricTimeToInitializeMilliseconds, |
| 731 | technology); |
| 732 | device_metrics->initialization_timer.reset( |
| 733 | new chromeos_metrics::TimerReporter( |
| 734 | histogram, |
| 735 | kMetricTimeToInitializeMillisecondsMin, |
| 736 | kMetricTimeToInitializeMillisecondsMax, |
| 737 | kMetricTimeToInitializeMillisecondsNumBuckets)); |
| 738 | device_metrics->initialization_timer->Start(); |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 739 | histogram = GetFullMetricName(kMetricTimeToEnableMilliseconds, |
| 740 | technology); |
| 741 | device_metrics->enable_timer.reset( |
| 742 | new chromeos_metrics::TimerReporter( |
| 743 | histogram, |
| 744 | kMetricTimeToEnableMillisecondsMin, |
| 745 | kMetricTimeToEnableMillisecondsMax, |
| 746 | kMetricTimeToEnableMillisecondsNumBuckets)); |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 747 | histogram = GetFullMetricName(kMetricTimeToDisableMilliseconds, |
| 748 | technology); |
| 749 | device_metrics->disable_timer.reset( |
| 750 | new chromeos_metrics::TimerReporter( |
| 751 | histogram, |
| 752 | kMetricTimeToDisableMillisecondsMin, |
| 753 | kMetricTimeToDisableMillisecondsMax, |
| 754 | kMetricTimeToDisableMillisecondsNumBuckets)); |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 755 | histogram = GetFullMetricName(kMetricTimeToScanMilliseconds, |
| 756 | technology); |
| 757 | device_metrics->scan_timer.reset( |
| 758 | new chromeos_metrics::TimerReporter( |
| 759 | histogram, |
| 760 | kMetricTimeToScanMillisecondsMin, |
| 761 | kMetricTimeToScanMillisecondsMax, |
| 762 | kMetricTimeToScanMillisecondsNumBuckets)); |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 763 | histogram = GetFullMetricName(kMetricTimeToConnectMilliseconds, |
| 764 | technology); |
| 765 | device_metrics->connect_timer.reset( |
| 766 | new chromeos_metrics::TimerReporter( |
| 767 | histogram, |
| 768 | kMetricTimeToConnectMillisecondsMin, |
| 769 | kMetricTimeToConnectMillisecondsMax, |
| 770 | kMetricTimeToConnectMillisecondsNumBuckets)); |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 771 | device_metrics->auto_connect_timer.reset( |
| 772 | new chromeos_metrics::TimerReporter( |
| 773 | kMetricCellularAutoConnectTotalTime, |
| 774 | kMetricCellularAutoConnectTotalTimeMin, |
| 775 | kMetricCellularAutoConnectTotalTimeMax, |
| 776 | kMetricCellularAutoConnectTotalTimeNumBuckets)); |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 777 | } |
| 778 | |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 779 | bool Metrics::IsDeviceRegistered(int interface_index, |
| 780 | Technology::Identifier technology) { |
| 781 | SLOG(Metrics, 2) << __func__ << ": interface index: " << interface_index |
| 782 | << ", technology: " << technology; |
| 783 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 784 | if (device_metrics == NULL) |
| 785 | return false; |
| 786 | // Make sure the device technologies match. |
| 787 | return (technology == device_metrics->technology); |
| 788 | } |
| 789 | |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 790 | void Metrics::DeregisterDevice(int interface_index) { |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 791 | SLOG(Metrics, 2) << __func__ << ": interface index: " << interface_index; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 792 | devices_metrics_.erase(interface_index); |
| 793 | } |
| 794 | |
| 795 | void Metrics::NotifyDeviceInitialized(int interface_index) { |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 796 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 797 | if (device_metrics == NULL) |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 798 | return; |
Wade Guthrie | 091c41c | 2013-03-22 15:48:53 -0700 | [diff] [blame] | 799 | if (!device_metrics->initialization_timer->Stop()) |
| 800 | return; |
Thieu Le | c8078a6 | 2013-01-22 18:01:12 -0800 | [diff] [blame] | 801 | device_metrics->initialization_timer->ReportMilliseconds(); |
| 802 | } |
| 803 | |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 804 | void Metrics::NotifyDeviceEnableStarted(int interface_index) { |
| 805 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 806 | if (device_metrics == NULL) |
| 807 | return; |
| 808 | device_metrics->enable_timer->Start(); |
| 809 | } |
| 810 | |
| 811 | void Metrics::NotifyDeviceEnableFinished(int interface_index) { |
| 812 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 813 | if (device_metrics == NULL) |
| 814 | return; |
Wade Guthrie | 091c41c | 2013-03-22 15:48:53 -0700 | [diff] [blame] | 815 | if (!device_metrics->enable_timer->Stop()) |
| 816 | return; |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 817 | device_metrics->enable_timer->ReportMilliseconds(); |
| 818 | } |
| 819 | |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 820 | void Metrics::NotifyDeviceDisableStarted(int interface_index) { |
| 821 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 822 | if (device_metrics == NULL) |
| 823 | return; |
| 824 | device_metrics->disable_timer->Start(); |
| 825 | } |
| 826 | |
| 827 | void Metrics::NotifyDeviceDisableFinished(int interface_index) { |
| 828 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 829 | if (device_metrics == NULL) |
| 830 | return; |
Wade Guthrie | 091c41c | 2013-03-22 15:48:53 -0700 | [diff] [blame] | 831 | if (!device_metrics->disable_timer->Stop()) |
| 832 | return; |
Thieu Le | a2519bf | 2013-01-23 16:51:54 -0800 | [diff] [blame] | 833 | device_metrics->disable_timer->ReportMilliseconds(); |
| 834 | } |
| 835 | |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 836 | void Metrics::NotifyDeviceScanStarted(int interface_index) { |
| 837 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 838 | if (device_metrics == NULL) |
| 839 | return; |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 840 | device_metrics->scan_timer->Start(); |
| 841 | } |
| 842 | |
| 843 | void Metrics::NotifyDeviceScanFinished(int interface_index) { |
| 844 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 845 | if (device_metrics == NULL) |
| 846 | return; |
Wade Guthrie | 091c41c | 2013-03-22 15:48:53 -0700 | [diff] [blame] | 847 | if (!device_metrics->scan_timer->Stop()) |
| 848 | return; |
Wade Guthrie | 68d4109 | 2013-04-02 12:56:02 -0700 | [diff] [blame] | 849 | // Don't send TimeToScan metrics if the elapsed time exceeds the max metrics |
| 850 | // value. Huge scan times usually mean something's gone awry; for cellular, |
| 851 | // for instance, this usually means that the modem is in an area without |
| 852 | // service and we're not interested in this scenario. |
Thieu Le | 18c1107 | 2013-01-28 17:21:37 -0800 | [diff] [blame] | 853 | base::TimeDelta elapsed_time; |
| 854 | device_metrics->scan_timer->GetElapsedTime(&elapsed_time); |
| 855 | if (elapsed_time.InMilliseconds() <= kMetricTimeToScanMillisecondsMax) |
| 856 | device_metrics->scan_timer->ReportMilliseconds(); |
| 857 | } |
| 858 | |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 859 | void Metrics::NotifyDeviceConnectStarted(int interface_index, |
| 860 | bool is_auto_connecting) { |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 861 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 862 | if (device_metrics == NULL) |
| 863 | return; |
| 864 | device_metrics->connect_timer->Start(); |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 865 | |
| 866 | if (is_auto_connecting) { |
| 867 | device_metrics->auto_connect_tries++; |
| 868 | if (device_metrics->auto_connect_tries == 1) |
| 869 | device_metrics->auto_connect_timer->Start(); |
| 870 | } else { |
| 871 | AutoConnectMetricsReset(device_metrics); |
| 872 | } |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | void Metrics::NotifyDeviceConnectFinished(int interface_index) { |
| 876 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 877 | if (device_metrics == NULL) |
| 878 | return; |
Wade Guthrie | 091c41c | 2013-03-22 15:48:53 -0700 | [diff] [blame] | 879 | if (!device_metrics->connect_timer->Stop()) |
| 880 | return; |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 881 | device_metrics->connect_timer->ReportMilliseconds(); |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 882 | |
| 883 | if (device_metrics->auto_connect_tries > 0) { |
Wade Guthrie | 091c41c | 2013-03-22 15:48:53 -0700 | [diff] [blame] | 884 | if (!device_metrics->auto_connect_timer->Stop()) |
| 885 | return; |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 886 | base::TimeDelta elapsed_time; |
| 887 | device_metrics->auto_connect_timer->GetElapsedTime(&elapsed_time); |
| 888 | if (elapsed_time.InMilliseconds() > kMetricCellularAutoConnectTotalTimeMax) |
| 889 | return; |
| 890 | device_metrics->auto_connect_timer->ReportMilliseconds(); |
| 891 | SendToUMA(kMetricCellularAutoConnectTries, |
| 892 | device_metrics->auto_connect_tries, |
| 893 | kMetricCellularAutoConnectTriesMin, |
| 894 | kMetricCellularAutoConnectTriesMax, |
| 895 | kMetricCellularAutoConnectTriesNumBuckets); |
| 896 | AutoConnectMetricsReset(device_metrics); |
| 897 | } |
Thieu Le | cdb5a21 | 2013-01-25 11:17:18 -0800 | [diff] [blame] | 898 | } |
| 899 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 900 | void Metrics::NotifyCellularDeviceDrop(int interface_index, |
| 901 | const string &network_technology, |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 902 | uint16 signal_strength) { |
| 903 | SLOG(Metrics, 2) << __func__ << ": " << network_technology |
| 904 | << ", " << signal_strength; |
| 905 | CellularDropTechnology drop_technology = kCellularDropTechnologyUnknown; |
| 906 | if (network_technology == flimflam::kNetworkTechnology1Xrtt) { |
| 907 | drop_technology = kCellularDropTechnology1Xrtt; |
| 908 | } else if (network_technology == flimflam::kNetworkTechnologyEdge) { |
| 909 | drop_technology = kCellularDropTechnologyEdge; |
| 910 | } else if (network_technology == flimflam::kNetworkTechnologyEvdo) { |
| 911 | drop_technology = kCellularDropTechnologyEvdo; |
| 912 | } else if (network_technology == flimflam::kNetworkTechnologyGprs) { |
| 913 | drop_technology = kCellularDropTechnologyGprs; |
| 914 | } else if (network_technology == flimflam::kNetworkTechnologyGsm) { |
| 915 | drop_technology = kCellularDropTechnologyGsm; |
| 916 | } else if (network_technology == flimflam::kNetworkTechnologyHspa) { |
| 917 | drop_technology = kCellularDropTechnologyHspa; |
| 918 | } else if (network_technology == flimflam::kNetworkTechnologyHspaPlus) { |
| 919 | drop_technology = kCellularDropTechnologyHspaPlus; |
| 920 | } else if (network_technology == flimflam::kNetworkTechnologyLte) { |
| 921 | drop_technology = kCellularDropTechnologyLte; |
| 922 | } else if (network_technology == flimflam::kNetworkTechnologyUmts) { |
| 923 | drop_technology = kCellularDropTechnologyUmts; |
| 924 | } |
| 925 | SendEnumToUMA(kMetricCellularDrop, |
| 926 | drop_technology, |
| 927 | kCellularDropTechnologyMax); |
| 928 | SendToUMA(kMetricCellularSignalStrengthBeforeDrop, |
| 929 | signal_strength, |
| 930 | kMetricCellularSignalStrengthBeforeDropMin, |
| 931 | kMetricCellularSignalStrengthBeforeDropMax, |
| 932 | kMetricCellularSignalStrengthBeforeDropNumBuckets); |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 933 | |
| 934 | DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index); |
| 935 | if (device_metrics == NULL) |
| 936 | return; |
| 937 | device_metrics->num_drops++; |
Thieu Le | 26fc01b | 2013-01-28 12:08:48 -0800 | [diff] [blame] | 938 | } |
| 939 | |
Thieu Le | b7aa5f7 | 2013-01-31 15:57:48 -0800 | [diff] [blame] | 940 | void Metrics::NotifyCellularDeviceFailure(const Error &error) { |
| 941 | library_->SendUserActionToUMA( |
| 942 | kMetricCellularFailureReason + error.message()); |
| 943 | } |
| 944 | |
Thieu Le | 91fccf6 | 2013-04-22 15:23:16 -0700 | [diff] [blame] | 945 | void Metrics::NotifyCellularOutOfCredits( |
| 946 | Metrics::CellularOutOfCreditsReason reason) { |
| 947 | SendEnumToUMA(kMetricCellularOutOfCreditsReason, |
| 948 | reason, |
| 949 | kCellularOutOfCreditsReasonMax); |
| 950 | } |
| 951 | |
Thieu Le | 5133b71 | 2013-02-19 14:47:21 -0800 | [diff] [blame] | 952 | void Metrics::NotifyCorruptedProfile() { |
| 953 | SendEnumToUMA(kMetricCorruptedProfile, |
| 954 | kCorruptedProfile, |
| 955 | kCorruptedProfileMax); |
| 956 | } |
| 957 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 958 | bool Metrics::SendEnumToUMA(const string &name, int sample, int max) { |
| 959 | return library_->SendEnumToUMA(name, sample, max); |
| 960 | } |
| 961 | |
Thieu Le | a20cbc2 | 2012-01-09 22:01:43 +0000 | [diff] [blame] | 962 | bool Metrics::SendToUMA(const string &name, int sample, int min, int max, |
| 963 | int num_buckets) { |
| 964 | return library_->SendToUMA(name, sample, min, max, num_buckets); |
| 965 | } |
| 966 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 967 | void Metrics::InitializeCommonServiceMetrics(const Service *service) { |
| 968 | Technology::Identifier technology = service->technology(); |
| 969 | string histogram = GetFullMetricName(kMetricTimeToConfigMilliseconds, |
| 970 | technology); |
| 971 | AddServiceStateTransitionTimer( |
| 972 | service, |
| 973 | histogram, |
| 974 | Service::kStateConfiguring, |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 975 | Service::kStateConnected); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 976 | histogram = GetFullMetricName(kMetricTimeToPortalMilliseconds, technology); |
| 977 | AddServiceStateTransitionTimer( |
| 978 | service, |
| 979 | histogram, |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 980 | Service::kStateConnected, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 981 | Service::kStatePortal); |
| 982 | histogram = GetFullMetricName(kMetricTimeToOnlineMilliseconds, technology); |
| 983 | AddServiceStateTransitionTimer( |
| 984 | service, |
| 985 | histogram, |
Paul Stewart | 20088d8 | 2012-02-16 06:58:55 -0800 | [diff] [blame] | 986 | Service::kStateConnected, |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 987 | Service::kStateOnline); |
| 988 | } |
| 989 | |
| 990 | void Metrics::UpdateServiceStateTransitionMetrics( |
| 991 | ServiceMetrics *service_metrics, |
| 992 | Service::ConnectState new_state) { |
| 993 | TimerReportersList::iterator it; |
| 994 | TimerReportersList &start_timers = service_metrics->start_on_state[new_state]; |
| 995 | for (it = start_timers.begin(); it != start_timers.end(); ++it) |
| 996 | (*it)->Start(); |
| 997 | |
| 998 | TimerReportersList &stop_timers = service_metrics->stop_on_state[new_state]; |
| 999 | for (it = stop_timers.begin(); it != stop_timers.end(); ++it) { |
Wade Guthrie | 091c41c | 2013-03-22 15:48:53 -0700 | [diff] [blame] | 1000 | if ((*it)->Stop()) |
| 1001 | (*it)->ReportMilliseconds(); |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 1002 | } |
| 1003 | } |
| 1004 | |
| 1005 | void Metrics::SendServiceFailure(const Service *service) { |
| 1006 | library_->SendEnumToUMA(kMetricNetworkServiceErrors, |
| 1007 | service->failure(), |
| 1008 | kMetricNetworkServiceErrorsMax); |
| 1009 | } |
| 1010 | |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 1011 | Metrics::DeviceMetrics *Metrics::GetDeviceMetrics(int interface_index) const { |
| 1012 | DeviceMetricsLookupMap::const_iterator it = |
| 1013 | devices_metrics_.find(interface_index); |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 1014 | if (it == devices_metrics_.end()) { |
Thieu Le | 9abd674 | 2013-01-23 23:35:37 -0800 | [diff] [blame] | 1015 | SLOG(Metrics, 2) << __func__ << ": device " << interface_index |
| 1016 | << " not found"; |
Thieu Le | ce4483e | 2013-01-23 15:12:03 -0800 | [diff] [blame] | 1017 | return NULL; |
| 1018 | } |
| 1019 | return it->second.get(); |
| 1020 | } |
| 1021 | |
Thieu Le | 7cf36b0 | 2013-01-30 17:15:56 -0800 | [diff] [blame] | 1022 | void Metrics::AutoConnectMetricsReset(DeviceMetrics *device_metrics) { |
| 1023 | device_metrics->auto_connect_tries = 0; |
| 1024 | device_metrics->auto_connect_timer->Reset(); |
| 1025 | } |
| 1026 | |
Thieu Le | 6c1e3bb | 2013-02-06 15:20:35 -0800 | [diff] [blame] | 1027 | void Metrics::HourlyTimeoutHandler() { |
| 1028 | SLOG(Metrics, 2) << __func__; |
| 1029 | DeviceMetricsLookupMap::iterator it; |
| 1030 | for (it = devices_metrics_.begin(); it != devices_metrics_.end(); ++it) { |
| 1031 | if (it->second->technology != Technology::kCellular || |
| 1032 | it->second->num_drops == 0) |
| 1033 | continue; |
| 1034 | SendToUMA(kMetricCellularDropsPerHour, |
| 1035 | it->second->num_drops, |
| 1036 | kMetricCellularDropsPerHourMin, |
| 1037 | kMetricCellularDropsPerHourMax, |
| 1038 | kMetricCellularDropsPerHourNumBuckets); |
| 1039 | it->second->num_drops = 0; |
| 1040 | } |
| 1041 | dispatcher_->PostDelayedTask(hourly_timeout_handler_.callback(), |
| 1042 | kHourlyTimeoutMilliseconds); |
| 1043 | } |
| 1044 | |
Thieu Le | 48e6d6d | 2011-12-06 00:40:27 +0000 | [diff] [blame] | 1045 | void Metrics::set_library(MetricsLibraryInterface *library) { |
| 1046 | chromeos_metrics::TimerReporter::set_metrics_lib(library); |
| 1047 | library_ = library; |
| 1048 | } |
| 1049 | |
| 1050 | } // namespace shill |