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