blob: 58a7eaf83002258f302387e72b64cdb5ca5fbca0 [file] [log] [blame]
Thieu Le3426c8f2012-01-11 17:35:11 -08001// Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
Thieu Le48e6d6d2011-12-06 00:40:27 +00002// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Wade Guthrie60a37062013-04-02 11:39:09 -07005#ifndef SHILL_METRICS_H_
6#define SHILL_METRICS_H_
Thieu Le48e6d6d2011-12-06 00:40:27 +00007
8#include <list>
9
Thieu Le48e6d6d2011-12-06 00:40:27 +000010#include <base/memory/scoped_vector.h>
11#include <metrics/metrics_library.h>
12#include <metrics/timer.h>
13
Thieu Le6c1e3bb2013-02-06 15:20:35 -080014#include "shill/event_dispatcher.h"
Wade Guthried4977f22012-08-22 12:37:54 -070015#include "shill/ieee80211.h"
Thieu Le85e050b2012-03-13 15:04:38 -070016#include "shill/portal_detector.h"
Thieu Leb84ba342012-03-02 15:15:19 -080017#include "shill/power_manager.h"
Thieu Le48e6d6d2011-12-06 00:40:27 +000018#include "shill/refptr_types.h"
19#include "shill/service.h"
20
21namespace shill {
22
Gaurav Shah6d2c72d2012-10-16 16:30:44 -070023class WiFiMainTest;
Thieu Le48e6d6d2011-12-06 00:40:27 +000024class WiFiService;
25
26class Metrics {
27 public:
28 enum WiFiChannel {
29 kWiFiChannelUndef = 0,
30 kWiFiChannel2412 = 1,
31 kWiFiChannel2417 = 2,
32 kWiFiChannel2422 = 3,
33 kWiFiChannel2427 = 4,
34 kWiFiChannel2432 = 5,
35 kWiFiChannel2437 = 6,
36 kWiFiChannel2442 = 7,
37 kWiFiChannel2447 = 8,
38 kWiFiChannel2452 = 9,
39 kWiFiChannel2457 = 10,
40 kWiFiChannel2462 = 11,
41 kWiFiChannel2467 = 12,
42 kWiFiChannel2472 = 13,
43 kWiFiChannel2484 = 14,
44
45 kWiFiChannel5180 = 15,
46 kWiFiChannel5200 = 16,
47 kWiFiChannel5220 = 17,
48 kWiFiChannel5240 = 18,
49 kWiFiChannel5260 = 19,
50 kWiFiChannel5280 = 20,
51 kWiFiChannel5300 = 21,
52 kWiFiChannel5320 = 22,
53
54 kWiFiChannel5500 = 23,
55 kWiFiChannel5520 = 24,
56 kWiFiChannel5540 = 25,
57 kWiFiChannel5560 = 26,
58 kWiFiChannel5580 = 27,
59 kWiFiChannel5600 = 28,
60 kWiFiChannel5620 = 29,
61 kWiFiChannel5640 = 30,
62 kWiFiChannel5660 = 31,
63 kWiFiChannel5680 = 32,
64 kWiFiChannel5700 = 33,
65
66 kWiFiChannel5745 = 34,
67 kWiFiChannel5765 = 35,
68 kWiFiChannel5785 = 36,
69 kWiFiChannel5805 = 37,
70 kWiFiChannel5825 = 38,
71
72 kWiFiChannel5170 = 39,
73 kWiFiChannel5190 = 40,
74 kWiFiChannel5210 = 41,
75 kWiFiChannel5230 = 42,
76
77 /* NB: ignore old 11b bands 2312..2372 and 2512..2532 */
78 /* NB: ignore regulated bands 4920..4980 and 5020..5160 */
79 kWiFiChannelMax
80 };
81
Thieu Lead1ec2c2012-01-05 23:39:48 +000082 enum WiFiNetworkPhyMode {
83 kWiFiNetworkPhyModeUndef = 0, // Unknown/undefined
84 kWiFiNetworkPhyMode11a = 1, // 802.11a
85 kWiFiNetworkPhyMode11b = 2, // 802.11b
86 kWiFiNetworkPhyMode11g = 3, // 802.11g
87 kWiFiNetworkPhyMode11n = 4, // 802.11n
88 kWiFiNetworkPhyModeHalf = 5, // PSB Half-width
89 kWiFiNetworkPhyModeQuarter = 6, // PSB Quarter-width
90 kWiFiNetworkPhyModeTurbo = 7, // Atheros Turbo mode
91
92 kWiFiNetworkPhyModeMax
93 };
94
Paul Stewart21f40962013-03-01 14:27:28 -080095 enum EapOuterProtocol {
96 kEapOuterProtocolUnknown = 0,
97 kEapOuterProtocolLeap = 1,
98 kEapOuterProtocolPeap = 2,
99 kEapOuterProtocolTls = 3,
100 kEapOuterProtocolTtls = 4,
101
102 kEapOuterProtocolMax
103 };
104
105 enum EapInnerProtocol {
106 kEapInnerProtocolUnknown = 0,
107 kEapInnerProtocolNone = 1,
108 kEapInnerProtocolPeapMd5 = 2,
109 kEapInnerProtocolPeapMschapv2 = 3,
110 kEapInnerProtocolTtlsEapMd5 = 4,
111 kEapInnerProtocolTtlsEapMschapv2 = 5,
112 kEapInnerProtocolTtlsMschapv2 = 6,
113 kEapInnerProtocolTtlsMschap = 7,
114 kEapInnerProtocolTtlsPap = 8,
115 kEapInnerProtocolTtlsChap = 9,
116
117 kEapInnerProtocolMax
118 };
119
Thieu Lead1ec2c2012-01-05 23:39:48 +0000120 enum WiFiSecurity {
121 kWiFiSecurityUnknown = 0,
122 kWiFiSecurityNone = 1,
123 kWiFiSecurityWep = 2,
124 kWiFiSecurityWpa = 3,
125 kWiFiSecurityRsn = 4,
126 kWiFiSecurity8021x = 5,
127 kWiFiSecurityPsk = 6,
128
129 kWiFiSecurityMax
130 };
131
Thieu Le85e050b2012-03-13 15:04:38 -0700132 enum PortalResult {
133 kPortalResultSuccess = 0,
134 kPortalResultDNSFailure = 1,
135 kPortalResultDNSTimeout = 2,
136 kPortalResultConnectionFailure = 3,
137 kPortalResultConnectionTimeout = 4,
138 kPortalResultHTTPFailure = 5,
139 kPortalResultHTTPTimeout = 6,
140 kPortalResultContentFailure = 7,
141 kPortalResultContentTimeout = 8,
142 kPortalResultUnknown = 9,
143
144 kPortalResultMax
145 };
146
Paul Stewartff845fc2012-08-07 07:28:44 -0700147 enum LinkMonitorFailure {
148 kLinkMonitorMacAddressNotFound = 0,
149 kLinkMonitorClientStartFailure = 1,
150 kLinkMonitorTransmitFailure = 2,
151 kLinkMonitorFailureThresholdReached = 3,
152
153 kLinkMonitorFailureMax
154 };
155
Wade Guthried4977f22012-08-22 12:37:54 -0700156 enum WiFiStatusType {
157 kStatusCodeTypeByAp,
158 kStatusCodeTypeByClient,
159 kStatusCodeTypeByUser,
160 kStatusCodeTypeConsideredDead,
161 kStatusCodeTypeMax
162 };
163
164 enum WiFiDisconnectByWhom {
165 kDisconnectedByAp,
166 kDisconnectedNotByAp
167 };
168
Wade Guthrieb9e0ee72013-05-31 09:23:30 -0700169 enum WiFiScanResult {
170 kScanResultProgressiveConnected,
171 kScanResultProgressiveErrorAndFullFoundNothing,
172 kScanResultProgressiveErrorButFullConnected,
173 kScanResultProgressiveAndFullFoundNothing,
174 kScanResultProgressiveAndFullConnected,
175 kScanResultFullScanFoundNothing,
176 kScanResultFullScanConnected,
177 kScanResultInternalError,
178 kScanResultMax
179 };
180
Paul Stewart85aea152013-01-22 09:31:56 -0800181 enum ServiceFixupProfileType {
182 kMetricServiceFixupDefaultProfile,
183 kMetricServiceFixupUserProfile,
184 kMetricServiceFixupMax
185 };
186
Arman Uguray6d528f12012-09-13 13:44:55 -0700187 enum TerminationActionResult {
Arman Ugurayab22c162012-10-08 19:08:38 -0700188 kTerminationActionResultSuccess,
189 kTerminationActionResultFailure,
Arman Uguray6d528f12012-09-13 13:44:55 -0700190 kTerminationActionResultMax
191 };
192
Arman Ugurayab22c162012-10-08 19:08:38 -0700193 enum TerminationActionReason {
194 kTerminationActionReasonSuspend,
195 kTerminationActionReasonTerminate
196 };
197
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -0700198 enum Cellular3GPPRegistrationDelayedDrop {
199 kCellular3GPPRegistrationDelayedDropPosted = 0,
200 kCellular3GPPRegistrationDelayedDropCanceled = 1,
201 kCellular3GPPRegistrationDelayedDropMax
202 };
203
Thieu Le26fc01b2013-01-28 12:08:48 -0800204 enum CellularDropTechnology {
205 kCellularDropTechnology1Xrtt = 0,
206 kCellularDropTechnologyEdge = 1,
207 kCellularDropTechnologyEvdo = 2,
208 kCellularDropTechnologyGprs = 3,
209 kCellularDropTechnologyGsm = 4,
210 kCellularDropTechnologyHspa = 5,
211 kCellularDropTechnologyHspaPlus = 6,
212 kCellularDropTechnologyLte = 7,
213 kCellularDropTechnologyUmts = 8,
214 kCellularDropTechnologyUnknown = 9,
215 kCellularDropTechnologyMax
216 };
217
Thieu Le91fccf62013-04-22 15:23:16 -0700218 enum CellularOutOfCreditsReason {
219 kCellularOutOfCreditsReasonConnectDisconnectLoop = 0,
220 kCellularOutOfCreditsReasonTxCongested = 1,
221 kCellularOutOfCreditsReasonElongatedTimeWait = 2,
222 kCellularOutOfCreditsReasonMax
223 };
224
Thieu Le5133b712013-02-19 14:47:21 -0800225 enum CorruptedProfile {
226 kCorruptedProfile = 1,
227 kCorruptedProfileMax
228 };
229
Paul Stewart91a43cb2013-03-02 21:34:15 -0800230 enum VpnDriver {
231 kVpnDriverOpenVpn = 0,
232 kVpnDriverL2tpIpsec = 1,
233 kVpnDriverMax
234 };
235
236 enum VpnRemoteAuthenticationType {
237 kVpnRemoteAuthenticationTypeOpenVpnDefault = 0,
238 kVpnRemoteAuthenticationTypeOpenVpnCertificate = 1,
239 kVpnRemoteAuthenticationTypeL2tpIpsecDefault = 2,
240 kVpnRemoteAuthenticationTypeL2tpIpsecCertificate = 3,
241 kVpnRemoteAuthenticationTypeL2tpIpsecPsk = 4,
242 kVpnRemoteAuthenticationTypeMax
243 };
244
245 enum VpnUserAuthenticationType {
246 kVpnUserAuthenticationTypeOpenVpnNone = 0,
247 kVpnUserAuthenticationTypeOpenVpnCertificate = 1,
248 kVpnUserAuthenticationTypeOpenVpnUsernamePassword = 2,
249 kVpnUserAuthenticationTypeOpenVpnUsernamePasswordOtp = 3,
250 kVpnUserAuthenticationTypeL2tpIpsecNone = 4,
251 kVpnUserAuthenticationTypeL2tpIpsecCertificate = 5,
252 kVpnUserAuthenticationTypeL2tpIpsecUsernamePassword = 6,
253 kVpnUserAuthenticationTypeMax
254 };
255
Thieu Le67370f62012-02-14 23:01:42 +0000256 static const char kMetricDisconnect[];
257 static const int kMetricDisconnectMax;
258 static const int kMetricDisconnectMin;
259 static const int kMetricDisconnectNumBuckets;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000260 static const char kMetricNetworkChannel[];
261 static const int kMetricNetworkChannelMax;
Paul Stewart21f40962013-03-01 14:27:28 -0800262 static const char kMetricNetworkEapInnerProtocol[];
263 static const int kMetricNetworkEapInnerProtocolMax;
264 static const char kMetricNetworkEapOuterProtocol[];
265 static const int kMetricNetworkEapOuterProtocolMax;
Thieu Lead1ec2c2012-01-05 23:39:48 +0000266 static const char kMetricNetworkPhyMode[];
267 static const int kMetricNetworkPhyModeMax;
268 static const char kMetricNetworkSecurity[];
269 static const int kMetricNetworkSecurityMax;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000270 static const char kMetricNetworkServiceErrors[];
271 static const int kMetricNetworkServiceErrorsMax;
Paul Stewart23b393a2012-09-25 21:21:06 -0700272 static const char kMetricNetworkSignalStrength[];
273 static const int kMetricNetworkSignalStrengthMin;
274 static const int kMetricNetworkSignalStrengthMax;
275 static const int kMetricNetworkSignalStrengthNumBuckets;
Thieu Lea20cbc22012-01-09 22:01:43 +0000276 static const char kMetricTimeOnlineSeconds[];
277 static const int kMetricTimeOnlineSecondsMax;
278 static const int kMetricTimeOnlineSecondsMin;
279 static const int kMetricTimeOnlineSecondsNumBuckets;
Thieu Leb84ba342012-03-02 15:15:19 -0800280 static const char kMetricTimeResumeToReadyMilliseconds[];
Thieu Le48e6d6d2011-12-06 00:40:27 +0000281 static const char kMetricTimeToConfigMilliseconds[];
Thieu Lecdb5a212013-01-25 11:17:18 -0800282 static const char kMetricTimeToConnectMilliseconds[];
283 static const int kMetricTimeToConnectMillisecondsMax;
284 static const int kMetricTimeToConnectMillisecondsMin;
285 static const int kMetricTimeToConnectMillisecondsNumBuckets;
Wade Guthrie44f290d2013-05-28 10:16:25 -0700286 static const char kMetricTimeToScanAndConnectMilliseconds[];
Thieu Lea20cbc22012-01-09 22:01:43 +0000287 static const char kMetricTimeToDropSeconds[];
288 static const int kMetricTimeToDropSecondsMax;
289 static const int kMetricTimeToDropSecondsMin;
Thieu Lea2519bf2013-01-23 16:51:54 -0800290 static const char kMetricTimeToDisableMilliseconds[];
291 static const int kMetricTimeToDisableMillisecondsMax;
292 static const int kMetricTimeToDisableMillisecondsMin;
293 static const int kMetricTimeToDisableMillisecondsNumBuckets;
Thieu Lece4483e2013-01-23 15:12:03 -0800294 static const char kMetricTimeToEnableMilliseconds[];
295 static const int kMetricTimeToEnableMillisecondsMax;
296 static const int kMetricTimeToEnableMillisecondsMin;
297 static const int kMetricTimeToEnableMillisecondsNumBuckets;
Thieu Lec8078a62013-01-22 18:01:12 -0800298 static const char kMetricTimeToInitializeMilliseconds[];
Thieu Lec8078a62013-01-22 18:01:12 -0800299 static const int kMetricTimeToInitializeMillisecondsMax;
Thieu Lece4483e2013-01-23 15:12:03 -0800300 static const int kMetricTimeToInitializeMillisecondsMin;
Thieu Lec8078a62013-01-22 18:01:12 -0800301 static const int kMetricTimeToInitializeMillisecondsNumBuckets;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000302 static const char kMetricTimeToJoinMilliseconds[];
303 static const char kMetricTimeToOnlineMilliseconds[];
304 static const char kMetricTimeToPortalMilliseconds[];
Thieu Le18c11072013-01-28 17:21:37 -0800305 static const char kMetricTimeToScanMilliseconds[];
306 static const int kMetricTimeToScanMillisecondsMax;
307 static const int kMetricTimeToScanMillisecondsMin;
308 static const int kMetricTimeToScanMillisecondsNumBuckets;
Thieu Lea20cbc22012-01-09 22:01:43 +0000309 static const int kTimerHistogramMillisecondsMax;
310 static const int kTimerHistogramMillisecondsMin;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000311 static const int kTimerHistogramNumBuckets;
312
Thieu Le85e050b2012-03-13 15:04:38 -0700313 // The number of portal detections attempted for each pass.
314 // This includes both failure/timeout attempts and successful attempt
315 // (if any).
316 static const char kMetricPortalAttempts[];
317 static const int kMetricPortalAttemptsMax;
318 static const int kMetricPortalAttemptsMin;
319 static const int kMetricPortalAttemptsNumBuckets;
320
321 // The total number of portal detections attempted between the Connected
322 // state and the Online state. This includes both failure/timeout attempts
323 // and the final successful attempt.
324 static const char kMetricPortalAttemptsToOnline[];
325 static const int kMetricPortalAttemptsToOnlineMax;
326 static const int kMetricPortalAttemptsToOnlineMin;
327 static const int kMetricPortalAttemptsToOnlineNumBuckets;
328
329 // The result of the portal detection.
330 static const char kMetricPortalResult[];
331
Wade Guthrie60a37062013-04-02 11:39:09 -0700332 // Wifi connection frequencies.
333 static const char kMetricFrequenciesConnectedEver[];
334 static const int kMetricFrequenciesConnectedMax;
335 static const int kMetricFrequenciesConnectedMin;
336 static const int kMetricFrequenciesConnectedNumBuckets;
337
Wade Guthrieb9e0ee72013-05-31 09:23:30 -0700338 static const char kMetricScanResult[];
Wade Guthrief22681f2013-05-31 11:46:31 -0700339 static const char kMetricWiFiScanTimeInEbusyMilliseconds[];
340
Thieu Leb84ba342012-03-02 15:15:19 -0800341 static const char kMetricPowerManagerKey[];
342
Paul Stewartff845fc2012-08-07 07:28:44 -0700343 // LinkMonitor statistics.
344 static const char kMetricLinkMonitorFailure[];
345 static const char kMetricLinkMonitorResponseTimeSample[];
Paul Stewartf1961f82012-09-11 20:45:39 -0700346 static const int kMetricLinkMonitorResponseTimeSampleMin;
347 static const int kMetricLinkMonitorResponseTimeSampleMax;
Paul Stewartff845fc2012-08-07 07:28:44 -0700348 static const int kMetricLinkMonitorResponseTimeSampleNumBuckets;
Paul Stewart0443aa52012-08-09 10:43:50 -0700349 static const char kMetricLinkMonitorSecondsToFailure[];
Paul Stewartf1961f82012-09-11 20:45:39 -0700350 static const int kMetricLinkMonitorSecondsToFailureMin;
351 static const int kMetricLinkMonitorSecondsToFailureMax;
Paul Stewart0443aa52012-08-09 10:43:50 -0700352 static const int kMetricLinkMonitorSecondsToFailureNumBuckets;
353 static const char kMetricLinkMonitorBroadcastErrorsAtFailure[];
354 static const char kMetricLinkMonitorUnicastErrorsAtFailure[];
Paul Stewartf1961f82012-09-11 20:45:39 -0700355 static const int kMetricLinkMonitorErrorCountMin;
356 static const int kMetricLinkMonitorErrorCountMax;
Paul Stewart0443aa52012-08-09 10:43:50 -0700357 static const int kMetricLinkMonitorErrorCountNumBuckets;
Paul Stewartff845fc2012-08-07 07:28:44 -0700358
Wade Guthried4977f22012-08-22 12:37:54 -0700359 static const char kMetricLinkClientDisconnectReason[];
360 static const char kMetricLinkApDisconnectReason[];
361 static const char kMetricLinkClientDisconnectType[];
362 static const char kMetricLinkApDisconnectType[];
363
Arman Uguray6d528f12012-09-13 13:44:55 -0700364 // Shill termination action statistics.
Arman Ugurayab22c162012-10-08 19:08:38 -0700365 static const char kMetricTerminationActionTimeOnTerminate[];
366 static const char kMetricTerminationActionResultOnTerminate[];
367 static const char kMetricTerminationActionTimeOnSuspend[];
368 static const char kMetricTerminationActionResultOnSuspend[];
369 static const int kMetricTerminationActionTimeMillisecondsMax;
370 static const int kMetricTerminationActionTimeMillisecondsMin;
Arman Uguray6d528f12012-09-13 13:44:55 -0700371
Paul Stewart85aea152013-01-22 09:31:56 -0800372 // WiFiService Entry Fixup.
373 static const char kMetricServiceFixupEntries[];
374
Thieu Le26fc01b2013-01-28 12:08:48 -0800375 // Cellular specific statistics.
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -0700376 static const char kMetricCellular3GPPRegistrationDelayedDrop[];
Thieu Le7cf36b02013-01-30 17:15:56 -0800377 static const char kMetricCellularAutoConnectTries[];
378 static const int kMetricCellularAutoConnectTriesMax;
379 static const int kMetricCellularAutoConnectTriesMin;
380 static const int kMetricCellularAutoConnectTriesNumBuckets;
381 static const char kMetricCellularAutoConnectTotalTime[];
382 static const int kMetricCellularAutoConnectTotalTimeMax;
383 static const int kMetricCellularAutoConnectTotalTimeMin;
384 static const int kMetricCellularAutoConnectTotalTimeNumBuckets;
Thieu Le91fccf62013-04-22 15:23:16 -0700385 static const char kMetricCellularDrop[];
386 static const char kMetricCellularDropsPerHour[];
387 static const int kMetricCellularDropsPerHourMax;
388 static const int kMetricCellularDropsPerHourMin;
389 static const int kMetricCellularDropsPerHourNumBuckets;
390 static const char kMetricCellularFailureReason[];
391 static const char kMetricCellularOutOfCreditsReason[];
392 static const char kMetricCellularSignalStrengthBeforeDrop[];
393 static const int kMetricCellularSignalStrengthBeforeDropMax;
394 static const int kMetricCellularSignalStrengthBeforeDropMin;
395 static const int kMetricCellularSignalStrengthBeforeDropNumBuckets;
Thieu Le26fc01b2013-01-28 12:08:48 -0800396
Thieu Le5133b712013-02-19 14:47:21 -0800397 // Profile statistics.
398 static const char kMetricCorruptedProfile[];
399
Paul Stewart91a43cb2013-03-02 21:34:15 -0800400 // VPN connection statistics.
401 static const char kMetricVpnDriver[];
402 static const int kMetricVpnDriverMax;
403 static const char kMetricVpnRemoteAuthenticationType[];
404 static const int kMetricVpnRemoteAuthenticationTypeMax;
405 static const char kMetricVpnUserAuthenticationType[];
406 static const int kMetricVpnUserAuthenticationTypeMax;
407
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800408 explicit Metrics(EventDispatcher *dispatcher);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000409 virtual ~Metrics();
410
Thieu Le48e6d6d2011-12-06 00:40:27 +0000411 // Converts the WiFi frequency into the associated UMA channel enumerator.
412 static WiFiChannel WiFiFrequencyToChannel(uint16 frequency);
413
Thieu Lead1ec2c2012-01-05 23:39:48 +0000414 // Converts a flimflam security string into its UMA security enumerator.
415 static WiFiSecurity WiFiSecurityStringToEnum(const std::string &security);
416
Paul Stewart21f40962013-03-01 14:27:28 -0800417 // Converts a flimflam EAP outer protocol string into its UMA enumerator.
418 static EapOuterProtocol EapOuterProtocolStringToEnum(
419 const std::string &outer);
420
421 // Converts a flimflam EAP inner protocol string into its UMA enumerator.
422 static EapInnerProtocol EapInnerProtocolStringToEnum(
423 const std::string &inner);
424
Thieu Le85e050b2012-03-13 15:04:38 -0700425 // Converts portal detection result to UMA portal result enumerator.
426 static PortalResult PortalDetectionResultToEnum(
427 const PortalDetector::Result &result);
428
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800429 // Starts this object. Call this during initialization.
430 virtual void Start();
431
432 // Stops this object. Call this during cleanup.
433 virtual void Stop();
434
Thieu Le48e6d6d2011-12-06 00:40:27 +0000435 // Registers a service with this object so it can use the timers to track
436 // state transition metrics.
437 void RegisterService(const Service *service);
438
439 // Deregisters the service from this class. All state transition timers
440 // will be removed.
441 void DeregisterService(const Service *service);
442
443 // Tracks the time it takes |service| to go from |start_state| to
444 // |stop_state|. When |stop_state| is reached, the time is sent to UMA.
445 void AddServiceStateTransitionTimer(const Service *service,
446 const std::string &histogram_name,
447 Service::ConnectState start_state,
448 Service::ConnectState stop_state);
449
450 // Specializes |metric_name| for the specified |technology_id|.
451 std::string GetFullMetricName(const char *metric_name,
452 Technology::Identifier technology_id);
453
454 // Notifies this object that the default service has changed.
455 // |service| is the new default service.
Thieu Lea20cbc22012-01-09 22:01:43 +0000456 virtual void NotifyDefaultServiceChanged(const Service *service);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000457
458 // Notifies this object that |service| state has changed.
459 virtual void NotifyServiceStateChanged(const Service *service,
460 Service::ConnectState new_state);
461
Thieu Le67370f62012-02-14 23:01:42 +0000462 // Notifies this object that |service| has been disconnected.
463 void NotifyServiceDisconnect(const Service *service);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000464
Thieu Leb84ba342012-03-02 15:15:19 -0800465 // Notifies this object of a power management state change.
466 void NotifyPowerStateChange(PowerManager::SuspendState new_state);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000467
Arman Ugurayab22c162012-10-08 19:08:38 -0700468 // Notifies this object that termination actions started executing.
469 void NotifyTerminationActionsStarted(TerminationActionReason reason);
470
471 // Notifies this object that termination actions have been completed.
472 // |success| is true, if the termination actions completed successfully.
473 void NotifyTerminationActionsCompleted(
474 TerminationActionReason reason, bool success);
475
Paul Stewartff845fc2012-08-07 07:28:44 -0700476 // Notifies this object of a failure in LinkMonitor.
477 void NotifyLinkMonitorFailure(
Paul Stewart0443aa52012-08-09 10:43:50 -0700478 Technology::Identifier technology,
479 LinkMonitorFailure failure,
Paul Stewartf1961f82012-09-11 20:45:39 -0700480 int seconds_to_failure,
481 int broadcast_error_count,
482 int unicast_error_count);
Paul Stewartff845fc2012-08-07 07:28:44 -0700483
484 // Notifies this object that LinkMonitor has added a response time sample
485 // for |connection| with a value of |response_time_milliseconds|.
486 void NotifyLinkMonitorResponseTimeSampleAdded(
487 Technology::Identifier technology,
Paul Stewartf1961f82012-09-11 20:45:39 -0700488 int response_time_milliseconds);
Paul Stewartff845fc2012-08-07 07:28:44 -0700489
Wade Guthried4977f22012-08-22 12:37:54 -0700490 // Notifies this object of WiFi disconnect.
491 void Notify80211Disconnect(WiFiDisconnectByWhom by_whom,
492 IEEE_80211::WiFiReasonCode reason);
493
Thieu Lec8078a62013-01-22 18:01:12 -0800494 // Registers a device with this object so the device can use the timers to
495 // track state transition metrics.
496 void RegisterDevice(int interface_index,
497 Technology::Identifier technology);
498
Thieu Le9abd6742013-01-23 23:35:37 -0800499 // Checks to see if the device has already been registered.
500 bool IsDeviceRegistered(int interface_index,
501 Technology::Identifier technology);
502
Thieu Lec8078a62013-01-22 18:01:12 -0800503 // Deregisters the device from this class. All state transition timers
504 // will be removed.
505 void DeregisterDevice(int interface_index);
506
507 // Notifies this object that a device has been initialized.
508 void NotifyDeviceInitialized(int interface_index);
509
Thieu Lece4483e2013-01-23 15:12:03 -0800510 // Notifies this object that a device has started the enable process.
511 void NotifyDeviceEnableStarted(int interface_index);
512
513 // Notifies this object that a device has completed the enable process.
514 void NotifyDeviceEnableFinished(int interface_index);
515
Thieu Lea2519bf2013-01-23 16:51:54 -0800516 // Notifies this object that a device has started the disable process.
517 void NotifyDeviceDisableStarted(int interface_index);
518
519 // Notifies this object that a device has completed the disable process.
520 void NotifyDeviceDisableFinished(int interface_index);
521
Thieu Le18c11072013-01-28 17:21:37 -0800522 // Notifies this object that a device has started the scanning process.
Wade Guthrie44f290d2013-05-28 10:16:25 -0700523 virtual void NotifyDeviceScanStarted(int interface_index);
Thieu Le18c11072013-01-28 17:21:37 -0800524
525 // Notifies this object that a device has completed the scanning process.
Wade Guthrie5a4e2ef2013-04-30 12:51:39 -0700526 virtual void NotifyDeviceScanFinished(int interface_index);
Thieu Le18c11072013-01-28 17:21:37 -0800527
Wade Guthrie44f290d2013-05-28 10:16:25 -0700528 // Terminates an underay scan (does nothing if a scan wasn't underay).
529 void ResetScanTimer(int interface_index);
530
Thieu Lecdb5a212013-01-25 11:17:18 -0800531 // Notifies this object that a device has started the connect process.
Wade Guthrie44f290d2013-05-28 10:16:25 -0700532 virtual void NotifyDeviceConnectStarted(int interface_index,
533 bool is_auto_connecting);
Thieu Lecdb5a212013-01-25 11:17:18 -0800534
535 // Notifies this object that a device has completed the connect process.
Wade Guthrie44f290d2013-05-28 10:16:25 -0700536 virtual void NotifyDeviceConnectFinished(int interface_index);
537
538 // Resets both the connect_timer and the scan_connect_timer the timer (the
539 // latter so that a future connect will not erroneously be associated with
540 // the previous scan).
541 virtual void ResetConnectTimer(int interface_index);
Thieu Lecdb5a212013-01-25 11:17:18 -0800542
Thieu Le26fc01b2013-01-28 12:08:48 -0800543 // Notifies this object that a cellular device has been dropped by the
544 // network.
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800545 void NotifyCellularDeviceDrop(int interface_index,
546 const std::string &network_technology,
Thieu Le26fc01b2013-01-28 12:08:48 -0800547 uint16 signal_strength);
548
Prathmesh Prabhu08757aa2013-05-15 17:17:33 -0700549 // Notifies this object about 3GPP registration drop events.
550 virtual void Notify3GPPRegistrationDelayedDropPosted();
551 virtual void Notify3GPPRegistrationDelayedDropCanceled();
552
Thieu Leb7aa5f72013-01-31 15:57:48 -0800553 // Notifies this object about a cellular device failure code.
554 void NotifyCellularDeviceFailure(const Error &error);
555
Thieu Le91fccf62013-04-22 15:23:16 -0700556 // Notifies this object that a cellular service has been marked as
557 // out-of-credits.
558 void NotifyCellularOutOfCredits(Metrics::CellularOutOfCreditsReason reason);
559
Thieu Le5133b712013-02-19 14:47:21 -0800560 // Notifies this object about a corrupted profile.
561 virtual void NotifyCorruptedProfile();
562
Thieu Le48e6d6d2011-12-06 00:40:27 +0000563 // Sends linear histogram data to UMA.
Thieu Le85e050b2012-03-13 15:04:38 -0700564 virtual bool SendEnumToUMA(const std::string &name, int sample, int max);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000565
Thieu Lea20cbc22012-01-09 22:01:43 +0000566 // Send histogram data to UMA.
Thieu Le85e050b2012-03-13 15:04:38 -0700567 virtual bool SendToUMA(const std::string &name, int sample, int min,
568 int max, int num_buckets);
Thieu Lea20cbc22012-01-09 22:01:43 +0000569
Thieu Le48e6d6d2011-12-06 00:40:27 +0000570 private:
Thieu Le48e6d6d2011-12-06 00:40:27 +0000571 friend class MetricsTest;
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800572 FRIEND_TEST(MetricsTest, CellularDropsPerHour);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000573 FRIEND_TEST(MetricsTest, FrequencyToChannel);
Wade Guthrie44f290d2013-05-28 10:16:25 -0700574 FRIEND_TEST(MetricsTest, ResetConnectTimer);
Thieu Leb84ba342012-03-02 15:15:19 -0800575 FRIEND_TEST(MetricsTest, ServiceFailure);
Thieu Lea20cbc22012-01-09 22:01:43 +0000576 FRIEND_TEST(MetricsTest, TimeOnlineTimeToDrop);
Thieu Leb84ba342012-03-02 15:15:19 -0800577 FRIEND_TEST(MetricsTest, TimeToConfig);
578 FRIEND_TEST(MetricsTest, TimeToOnline);
579 FRIEND_TEST(MetricsTest, TimeToPortal);
Thieu Le18c11072013-01-28 17:21:37 -0800580 FRIEND_TEST(MetricsTest, TimeToScanIgnore);
Thieu Leb84ba342012-03-02 15:15:19 -0800581 FRIEND_TEST(MetricsTest, WiFiServiceChannel);
582 FRIEND_TEST(MetricsTest, WiFiServicePostReady);
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700583 FRIEND_TEST(WiFiMainTest, GetGeolocationObjects);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000584
585 typedef ScopedVector<chromeos_metrics::TimerReporter> TimerReporters;
586 typedef std::list<chromeos_metrics::TimerReporter *> TimerReportersList;
587 typedef std::map<Service::ConnectState, TimerReportersList>
588 TimerReportersByState;
589 struct ServiceMetrics {
590 ServiceMetrics() : service(NULL) {}
591 // The service is registered/deregistered in the Service
592 // constructor/destructor, therefore there is no need to keep a ref count.
593 const Service *service;
594 // All TimerReporter objects are stored in |timers| which owns the objects.
595 // |start_on_state| and |stop_on_state| contain pointers to the
596 // TimerReporter objects and control when to start and stop the timers.
597 TimerReporters timers;
598 TimerReportersByState start_on_state;
599 TimerReportersByState stop_on_state;
600 };
601 typedef std::map<const Service *, std::tr1::shared_ptr<ServiceMetrics> >
602 ServiceMetricsLookupMap;
603
Thieu Lec8078a62013-01-22 18:01:12 -0800604 struct DeviceMetrics {
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800605 DeviceMetrics() : auto_connect_tries(0), num_drops(0) {}
Thieu Le9abd6742013-01-23 23:35:37 -0800606 Technology::Identifier technology;
Thieu Lec8078a62013-01-22 18:01:12 -0800607 scoped_ptr<chromeos_metrics::TimerReporter> initialization_timer;
Thieu Lece4483e2013-01-23 15:12:03 -0800608 scoped_ptr<chromeos_metrics::TimerReporter> enable_timer;
Thieu Lea2519bf2013-01-23 16:51:54 -0800609 scoped_ptr<chromeos_metrics::TimerReporter> disable_timer;
Thieu Le18c11072013-01-28 17:21:37 -0800610 scoped_ptr<chromeos_metrics::TimerReporter> scan_timer;
Thieu Lecdb5a212013-01-25 11:17:18 -0800611 scoped_ptr<chromeos_metrics::TimerReporter> connect_timer;
Wade Guthrie44f290d2013-05-28 10:16:25 -0700612 scoped_ptr<chromeos_metrics::TimerReporter> scan_connect_timer;
Thieu Le7cf36b02013-01-30 17:15:56 -0800613 scoped_ptr<chromeos_metrics::TimerReporter> auto_connect_timer;
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800614 int auto_connect_tries;
615 int num_drops;
Thieu Lec8078a62013-01-22 18:01:12 -0800616 };
617 typedef std::map<const int, std::tr1::shared_ptr<DeviceMetrics> >
618 DeviceMetricsLookupMap;
619
Thieu Le48e6d6d2011-12-06 00:40:27 +0000620 static const uint16 kWiFiBandwidth5MHz;
621 static const uint16 kWiFiBandwidth20MHz;
622 static const uint16 kWiFiFrequency2412;
623 static const uint16 kWiFiFrequency2472;
624 static const uint16 kWiFiFrequency2484;
625 static const uint16 kWiFiFrequency5170;
626 static const uint16 kWiFiFrequency5180;
627 static const uint16 kWiFiFrequency5230;
628 static const uint16 kWiFiFrequency5240;
629 static const uint16 kWiFiFrequency5320;
630 static const uint16 kWiFiFrequency5500;
631 static const uint16 kWiFiFrequency5700;
632 static const uint16 kWiFiFrequency5745;
633 static const uint16 kWiFiFrequency5825;
634
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800635 static const int kHourlyTimeoutMilliseconds;
636
Thieu Le48e6d6d2011-12-06 00:40:27 +0000637 void InitializeCommonServiceMetrics(const Service *service);
638 void UpdateServiceStateTransitionMetrics(ServiceMetrics *service_metrics,
639 Service::ConnectState new_state);
640 void SendServiceFailure(const Service *service);
641
Wade Guthrie60a37062013-04-02 11:39:09 -0700642 DeviceMetrics *GetDeviceMetrics(int interface_index) const;
Thieu Le7cf36b02013-01-30 17:15:56 -0800643 void AutoConnectMetricsReset(DeviceMetrics *device_metrics);
Thieu Lece4483e2013-01-23 15:12:03 -0800644
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800645 void HourlyTimeoutHandler();
646
Thieu Le48e6d6d2011-12-06 00:40:27 +0000647 // For unit test purposes.
648 void set_library(MetricsLibraryInterface *library);
Thieu Lea20cbc22012-01-09 22:01:43 +0000649 void set_time_online_timer(chromeos_metrics::Timer *timer) {
650 time_online_timer_.reset(timer); // Passes ownership
651 }
652 void set_time_to_drop_timer(chromeos_metrics::Timer *timer) {
653 time_to_drop_timer_.reset(timer); // Passes ownership
654 }
Thieu Leb84ba342012-03-02 15:15:19 -0800655 void set_time_resume_to_ready_timer(chromeos_metrics::Timer *timer) {
656 time_resume_to_ready_timer_.reset(timer); // Passes ownership
657 }
Arman Ugurayab22c162012-10-08 19:08:38 -0700658 void set_time_termination_actions_timer(
659 chromeos_metrics::Timer *timer) {
660 time_termination_actions_timer.reset(timer); // Passes ownership
661 }
Thieu Le18c11072013-01-28 17:21:37 -0800662 void set_time_to_scan_timer(int interface_index,
663 chromeos_metrics::TimerReporter *timer) {
664 DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index);
665 device_metrics->scan_timer.reset(timer); // Passes ownership
666 }
Wade Guthrie44f290d2013-05-28 10:16:25 -0700667 void set_time_to_connect_timer(int interface_index,
668 chromeos_metrics::TimerReporter *timer) {
669 DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index);
670 device_metrics->connect_timer.reset(timer); // Passes ownership
671 }
672 void set_time_to_scan_connect_timer(int interface_index,
673 chromeos_metrics::TimerReporter *timer) {
674 DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index);
675 device_metrics->scan_connect_timer.reset(timer); // Passes ownership
676 }
Thieu Le48e6d6d2011-12-06 00:40:27 +0000677
678 // |library_| points to |metrics_library_| when shill runs normally.
679 // However, in order to allow for unit testing, we point |library_| to a
680 // MetricsLibraryMock object instead.
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800681 EventDispatcher *dispatcher_;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000682 MetricsLibrary metrics_library_;
683 MetricsLibraryInterface *library_;
684 ServiceMetricsLookupMap services_metrics_;
Thieu Lea20cbc22012-01-09 22:01:43 +0000685 Technology::Identifier last_default_technology_;
686 bool was_online_;
687 scoped_ptr<chromeos_metrics::Timer> time_online_timer_;
688 scoped_ptr<chromeos_metrics::Timer> time_to_drop_timer_;
Thieu Leb84ba342012-03-02 15:15:19 -0800689 scoped_ptr<chromeos_metrics::Timer> time_resume_to_ready_timer_;
Arman Ugurayab22c162012-10-08 19:08:38 -0700690 scoped_ptr<chromeos_metrics::Timer> time_termination_actions_timer;
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200691 bool collect_bootstats_;
Thieu Lec8078a62013-01-22 18:01:12 -0800692 DeviceMetricsLookupMap devices_metrics_;
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800693 base::CancelableClosure hourly_timeout_handler_;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000694
695 DISALLOW_COPY_AND_ASSIGN(Metrics);
696};
697
698} // namespace shill
699
Wade Guthrie60a37062013-04-02 11:39:09 -0700700#endif // SHILL_METRICS_H_