blob: d95101aea72659009fea1ea7bec247a6e3da03cb [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
Paul Stewart85aea152013-01-22 09:31:56 -0800169 enum ServiceFixupProfileType {
170 kMetricServiceFixupDefaultProfile,
171 kMetricServiceFixupUserProfile,
172 kMetricServiceFixupMax
173 };
174
Arman Uguray6d528f12012-09-13 13:44:55 -0700175 enum TerminationActionResult {
Arman Ugurayab22c162012-10-08 19:08:38 -0700176 kTerminationActionResultSuccess,
177 kTerminationActionResultFailure,
Arman Uguray6d528f12012-09-13 13:44:55 -0700178 kTerminationActionResultMax
179 };
180
Arman Ugurayab22c162012-10-08 19:08:38 -0700181 enum TerminationActionReason {
182 kTerminationActionReasonSuspend,
183 kTerminationActionReasonTerminate
184 };
185
Thieu Le26fc01b2013-01-28 12:08:48 -0800186 enum CellularDropTechnology {
187 kCellularDropTechnology1Xrtt = 0,
188 kCellularDropTechnologyEdge = 1,
189 kCellularDropTechnologyEvdo = 2,
190 kCellularDropTechnologyGprs = 3,
191 kCellularDropTechnologyGsm = 4,
192 kCellularDropTechnologyHspa = 5,
193 kCellularDropTechnologyHspaPlus = 6,
194 kCellularDropTechnologyLte = 7,
195 kCellularDropTechnologyUmts = 8,
196 kCellularDropTechnologyUnknown = 9,
197 kCellularDropTechnologyMax
198 };
199
Thieu Le91fccf62013-04-22 15:23:16 -0700200 enum CellularOutOfCreditsReason {
201 kCellularOutOfCreditsReasonConnectDisconnectLoop = 0,
202 kCellularOutOfCreditsReasonTxCongested = 1,
203 kCellularOutOfCreditsReasonElongatedTimeWait = 2,
204 kCellularOutOfCreditsReasonMax
205 };
206
Thieu Le5133b712013-02-19 14:47:21 -0800207 enum CorruptedProfile {
208 kCorruptedProfile = 1,
209 kCorruptedProfileMax
210 };
211
Paul Stewart91a43cb2013-03-02 21:34:15 -0800212 enum VpnDriver {
213 kVpnDriverOpenVpn = 0,
214 kVpnDriverL2tpIpsec = 1,
215 kVpnDriverMax
216 };
217
218 enum VpnRemoteAuthenticationType {
219 kVpnRemoteAuthenticationTypeOpenVpnDefault = 0,
220 kVpnRemoteAuthenticationTypeOpenVpnCertificate = 1,
221 kVpnRemoteAuthenticationTypeL2tpIpsecDefault = 2,
222 kVpnRemoteAuthenticationTypeL2tpIpsecCertificate = 3,
223 kVpnRemoteAuthenticationTypeL2tpIpsecPsk = 4,
224 kVpnRemoteAuthenticationTypeMax
225 };
226
227 enum VpnUserAuthenticationType {
228 kVpnUserAuthenticationTypeOpenVpnNone = 0,
229 kVpnUserAuthenticationTypeOpenVpnCertificate = 1,
230 kVpnUserAuthenticationTypeOpenVpnUsernamePassword = 2,
231 kVpnUserAuthenticationTypeOpenVpnUsernamePasswordOtp = 3,
232 kVpnUserAuthenticationTypeL2tpIpsecNone = 4,
233 kVpnUserAuthenticationTypeL2tpIpsecCertificate = 5,
234 kVpnUserAuthenticationTypeL2tpIpsecUsernamePassword = 6,
235 kVpnUserAuthenticationTypeMax
236 };
237
Thieu Le67370f62012-02-14 23:01:42 +0000238 static const char kMetricDisconnect[];
239 static const int kMetricDisconnectMax;
240 static const int kMetricDisconnectMin;
241 static const int kMetricDisconnectNumBuckets;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000242 static const char kMetricNetworkChannel[];
243 static const int kMetricNetworkChannelMax;
Paul Stewart21f40962013-03-01 14:27:28 -0800244 static const char kMetricNetworkEapInnerProtocol[];
245 static const int kMetricNetworkEapInnerProtocolMax;
246 static const char kMetricNetworkEapOuterProtocol[];
247 static const int kMetricNetworkEapOuterProtocolMax;
Thieu Lead1ec2c2012-01-05 23:39:48 +0000248 static const char kMetricNetworkPhyMode[];
249 static const int kMetricNetworkPhyModeMax;
250 static const char kMetricNetworkSecurity[];
251 static const int kMetricNetworkSecurityMax;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000252 static const char kMetricNetworkServiceErrors[];
253 static const int kMetricNetworkServiceErrorsMax;
Paul Stewart23b393a2012-09-25 21:21:06 -0700254 static const char kMetricNetworkSignalStrength[];
255 static const int kMetricNetworkSignalStrengthMin;
256 static const int kMetricNetworkSignalStrengthMax;
257 static const int kMetricNetworkSignalStrengthNumBuckets;
Thieu Lea20cbc22012-01-09 22:01:43 +0000258 static const char kMetricTimeOnlineSeconds[];
259 static const int kMetricTimeOnlineSecondsMax;
260 static const int kMetricTimeOnlineSecondsMin;
261 static const int kMetricTimeOnlineSecondsNumBuckets;
Thieu Leb84ba342012-03-02 15:15:19 -0800262 static const char kMetricTimeResumeToReadyMilliseconds[];
Thieu Le48e6d6d2011-12-06 00:40:27 +0000263 static const char kMetricTimeToConfigMilliseconds[];
Thieu Lecdb5a212013-01-25 11:17:18 -0800264 static const char kMetricTimeToConnectMilliseconds[];
265 static const int kMetricTimeToConnectMillisecondsMax;
266 static const int kMetricTimeToConnectMillisecondsMin;
267 static const int kMetricTimeToConnectMillisecondsNumBuckets;
Thieu Lea20cbc22012-01-09 22:01:43 +0000268 static const char kMetricTimeToDropSeconds[];
269 static const int kMetricTimeToDropSecondsMax;
270 static const int kMetricTimeToDropSecondsMin;
Thieu Lea2519bf2013-01-23 16:51:54 -0800271 static const char kMetricTimeToDisableMilliseconds[];
272 static const int kMetricTimeToDisableMillisecondsMax;
273 static const int kMetricTimeToDisableMillisecondsMin;
274 static const int kMetricTimeToDisableMillisecondsNumBuckets;
Thieu Lece4483e2013-01-23 15:12:03 -0800275 static const char kMetricTimeToEnableMilliseconds[];
276 static const int kMetricTimeToEnableMillisecondsMax;
277 static const int kMetricTimeToEnableMillisecondsMin;
278 static const int kMetricTimeToEnableMillisecondsNumBuckets;
Thieu Lec8078a62013-01-22 18:01:12 -0800279 static const char kMetricTimeToInitializeMilliseconds[];
Thieu Lec8078a62013-01-22 18:01:12 -0800280 static const int kMetricTimeToInitializeMillisecondsMax;
Thieu Lece4483e2013-01-23 15:12:03 -0800281 static const int kMetricTimeToInitializeMillisecondsMin;
Thieu Lec8078a62013-01-22 18:01:12 -0800282 static const int kMetricTimeToInitializeMillisecondsNumBuckets;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000283 static const char kMetricTimeToJoinMilliseconds[];
284 static const char kMetricTimeToOnlineMilliseconds[];
285 static const char kMetricTimeToPortalMilliseconds[];
Thieu Le18c11072013-01-28 17:21:37 -0800286 static const char kMetricTimeToScanMilliseconds[];
287 static const int kMetricTimeToScanMillisecondsMax;
288 static const int kMetricTimeToScanMillisecondsMin;
289 static const int kMetricTimeToScanMillisecondsNumBuckets;
Thieu Lea20cbc22012-01-09 22:01:43 +0000290 static const int kTimerHistogramMillisecondsMax;
291 static const int kTimerHistogramMillisecondsMin;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000292 static const int kTimerHistogramNumBuckets;
293
Thieu Le85e050b2012-03-13 15:04:38 -0700294 // The number of portal detections attempted for each pass.
295 // This includes both failure/timeout attempts and successful attempt
296 // (if any).
297 static const char kMetricPortalAttempts[];
298 static const int kMetricPortalAttemptsMax;
299 static const int kMetricPortalAttemptsMin;
300 static const int kMetricPortalAttemptsNumBuckets;
301
302 // The total number of portal detections attempted between the Connected
303 // state and the Online state. This includes both failure/timeout attempts
304 // and the final successful attempt.
305 static const char kMetricPortalAttemptsToOnline[];
306 static const int kMetricPortalAttemptsToOnlineMax;
307 static const int kMetricPortalAttemptsToOnlineMin;
308 static const int kMetricPortalAttemptsToOnlineNumBuckets;
309
310 // The result of the portal detection.
311 static const char kMetricPortalResult[];
312
Wade Guthrie60a37062013-04-02 11:39:09 -0700313 // Wifi connection frequencies.
314 static const char kMetricFrequenciesConnectedEver[];
315 static const int kMetricFrequenciesConnectedMax;
316 static const int kMetricFrequenciesConnectedMin;
317 static const int kMetricFrequenciesConnectedNumBuckets;
318
Wade Guthrief22681f2013-05-31 11:46:31 -0700319 static const char kMetricWiFiScanTimeInEbusyMilliseconds[];
320
Thieu Leb84ba342012-03-02 15:15:19 -0800321 static const char kMetricPowerManagerKey[];
322
Paul Stewartff845fc2012-08-07 07:28:44 -0700323 // LinkMonitor statistics.
324 static const char kMetricLinkMonitorFailure[];
325 static const char kMetricLinkMonitorResponseTimeSample[];
Paul Stewartf1961f82012-09-11 20:45:39 -0700326 static const int kMetricLinkMonitorResponseTimeSampleMin;
327 static const int kMetricLinkMonitorResponseTimeSampleMax;
Paul Stewartff845fc2012-08-07 07:28:44 -0700328 static const int kMetricLinkMonitorResponseTimeSampleNumBuckets;
Paul Stewart0443aa52012-08-09 10:43:50 -0700329 static const char kMetricLinkMonitorSecondsToFailure[];
Paul Stewartf1961f82012-09-11 20:45:39 -0700330 static const int kMetricLinkMonitorSecondsToFailureMin;
331 static const int kMetricLinkMonitorSecondsToFailureMax;
Paul Stewart0443aa52012-08-09 10:43:50 -0700332 static const int kMetricLinkMonitorSecondsToFailureNumBuckets;
333 static const char kMetricLinkMonitorBroadcastErrorsAtFailure[];
334 static const char kMetricLinkMonitorUnicastErrorsAtFailure[];
Paul Stewartf1961f82012-09-11 20:45:39 -0700335 static const int kMetricLinkMonitorErrorCountMin;
336 static const int kMetricLinkMonitorErrorCountMax;
Paul Stewart0443aa52012-08-09 10:43:50 -0700337 static const int kMetricLinkMonitorErrorCountNumBuckets;
Paul Stewartff845fc2012-08-07 07:28:44 -0700338
Wade Guthried4977f22012-08-22 12:37:54 -0700339 static const char kMetricLinkClientDisconnectReason[];
340 static const char kMetricLinkApDisconnectReason[];
341 static const char kMetricLinkClientDisconnectType[];
342 static const char kMetricLinkApDisconnectType[];
343
Arman Uguray6d528f12012-09-13 13:44:55 -0700344 // Shill termination action statistics.
Arman Ugurayab22c162012-10-08 19:08:38 -0700345 static const char kMetricTerminationActionTimeOnTerminate[];
346 static const char kMetricTerminationActionResultOnTerminate[];
347 static const char kMetricTerminationActionTimeOnSuspend[];
348 static const char kMetricTerminationActionResultOnSuspend[];
349 static const int kMetricTerminationActionTimeMillisecondsMax;
350 static const int kMetricTerminationActionTimeMillisecondsMin;
Arman Uguray6d528f12012-09-13 13:44:55 -0700351
Paul Stewart85aea152013-01-22 09:31:56 -0800352 // WiFiService Entry Fixup.
353 static const char kMetricServiceFixupEntries[];
354
Thieu Le26fc01b2013-01-28 12:08:48 -0800355 // Cellular specific statistics.
Thieu Le7cf36b02013-01-30 17:15:56 -0800356 static const char kMetricCellularAutoConnectTries[];
357 static const int kMetricCellularAutoConnectTriesMax;
358 static const int kMetricCellularAutoConnectTriesMin;
359 static const int kMetricCellularAutoConnectTriesNumBuckets;
360 static const char kMetricCellularAutoConnectTotalTime[];
361 static const int kMetricCellularAutoConnectTotalTimeMax;
362 static const int kMetricCellularAutoConnectTotalTimeMin;
363 static const int kMetricCellularAutoConnectTotalTimeNumBuckets;
Thieu Le91fccf62013-04-22 15:23:16 -0700364 static const char kMetricCellularDrop[];
365 static const char kMetricCellularDropsPerHour[];
366 static const int kMetricCellularDropsPerHourMax;
367 static const int kMetricCellularDropsPerHourMin;
368 static const int kMetricCellularDropsPerHourNumBuckets;
369 static const char kMetricCellularFailureReason[];
370 static const char kMetricCellularOutOfCreditsReason[];
371 static const char kMetricCellularSignalStrengthBeforeDrop[];
372 static const int kMetricCellularSignalStrengthBeforeDropMax;
373 static const int kMetricCellularSignalStrengthBeforeDropMin;
374 static const int kMetricCellularSignalStrengthBeforeDropNumBuckets;
Thieu Le26fc01b2013-01-28 12:08:48 -0800375
Thieu Le5133b712013-02-19 14:47:21 -0800376 // Profile statistics.
377 static const char kMetricCorruptedProfile[];
378
Paul Stewart91a43cb2013-03-02 21:34:15 -0800379 // VPN connection statistics.
380 static const char kMetricVpnDriver[];
381 static const int kMetricVpnDriverMax;
382 static const char kMetricVpnRemoteAuthenticationType[];
383 static const int kMetricVpnRemoteAuthenticationTypeMax;
384 static const char kMetricVpnUserAuthenticationType[];
385 static const int kMetricVpnUserAuthenticationTypeMax;
386
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800387 explicit Metrics(EventDispatcher *dispatcher);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000388 virtual ~Metrics();
389
Thieu Le48e6d6d2011-12-06 00:40:27 +0000390 // Converts the WiFi frequency into the associated UMA channel enumerator.
391 static WiFiChannel WiFiFrequencyToChannel(uint16 frequency);
392
Thieu Lead1ec2c2012-01-05 23:39:48 +0000393 // Converts a flimflam security string into its UMA security enumerator.
394 static WiFiSecurity WiFiSecurityStringToEnum(const std::string &security);
395
Paul Stewart21f40962013-03-01 14:27:28 -0800396 // Converts a flimflam EAP outer protocol string into its UMA enumerator.
397 static EapOuterProtocol EapOuterProtocolStringToEnum(
398 const std::string &outer);
399
400 // Converts a flimflam EAP inner protocol string into its UMA enumerator.
401 static EapInnerProtocol EapInnerProtocolStringToEnum(
402 const std::string &inner);
403
Thieu Le85e050b2012-03-13 15:04:38 -0700404 // Converts portal detection result to UMA portal result enumerator.
405 static PortalResult PortalDetectionResultToEnum(
406 const PortalDetector::Result &result);
407
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800408 // Starts this object. Call this during initialization.
409 virtual void Start();
410
411 // Stops this object. Call this during cleanup.
412 virtual void Stop();
413
Thieu Le48e6d6d2011-12-06 00:40:27 +0000414 // Registers a service with this object so it can use the timers to track
415 // state transition metrics.
416 void RegisterService(const Service *service);
417
418 // Deregisters the service from this class. All state transition timers
419 // will be removed.
420 void DeregisterService(const Service *service);
421
422 // Tracks the time it takes |service| to go from |start_state| to
423 // |stop_state|. When |stop_state| is reached, the time is sent to UMA.
424 void AddServiceStateTransitionTimer(const Service *service,
425 const std::string &histogram_name,
426 Service::ConnectState start_state,
427 Service::ConnectState stop_state);
428
429 // Specializes |metric_name| for the specified |technology_id|.
430 std::string GetFullMetricName(const char *metric_name,
431 Technology::Identifier technology_id);
432
433 // Notifies this object that the default service has changed.
434 // |service| is the new default service.
Thieu Lea20cbc22012-01-09 22:01:43 +0000435 virtual void NotifyDefaultServiceChanged(const Service *service);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000436
437 // Notifies this object that |service| state has changed.
438 virtual void NotifyServiceStateChanged(const Service *service,
439 Service::ConnectState new_state);
440
Thieu Le67370f62012-02-14 23:01:42 +0000441 // Notifies this object that |service| has been disconnected.
442 void NotifyServiceDisconnect(const Service *service);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000443
Thieu Leb84ba342012-03-02 15:15:19 -0800444 // Notifies this object of a power management state change.
445 void NotifyPowerStateChange(PowerManager::SuspendState new_state);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000446
Arman Ugurayab22c162012-10-08 19:08:38 -0700447 // Notifies this object that termination actions started executing.
448 void NotifyTerminationActionsStarted(TerminationActionReason reason);
449
450 // Notifies this object that termination actions have been completed.
451 // |success| is true, if the termination actions completed successfully.
452 void NotifyTerminationActionsCompleted(
453 TerminationActionReason reason, bool success);
454
Paul Stewartff845fc2012-08-07 07:28:44 -0700455 // Notifies this object of a failure in LinkMonitor.
456 void NotifyLinkMonitorFailure(
Paul Stewart0443aa52012-08-09 10:43:50 -0700457 Technology::Identifier technology,
458 LinkMonitorFailure failure,
Paul Stewartf1961f82012-09-11 20:45:39 -0700459 int seconds_to_failure,
460 int broadcast_error_count,
461 int unicast_error_count);
Paul Stewartff845fc2012-08-07 07:28:44 -0700462
463 // Notifies this object that LinkMonitor has added a response time sample
464 // for |connection| with a value of |response_time_milliseconds|.
465 void NotifyLinkMonitorResponseTimeSampleAdded(
466 Technology::Identifier technology,
Paul Stewartf1961f82012-09-11 20:45:39 -0700467 int response_time_milliseconds);
Paul Stewartff845fc2012-08-07 07:28:44 -0700468
Wade Guthried4977f22012-08-22 12:37:54 -0700469 // Notifies this object of WiFi disconnect.
470 void Notify80211Disconnect(WiFiDisconnectByWhom by_whom,
471 IEEE_80211::WiFiReasonCode reason);
472
Thieu Lec8078a62013-01-22 18:01:12 -0800473 // Registers a device with this object so the device can use the timers to
474 // track state transition metrics.
475 void RegisterDevice(int interface_index,
476 Technology::Identifier technology);
477
Thieu Le9abd6742013-01-23 23:35:37 -0800478 // Checks to see if the device has already been registered.
479 bool IsDeviceRegistered(int interface_index,
480 Technology::Identifier technology);
481
Thieu Lec8078a62013-01-22 18:01:12 -0800482 // Deregisters the device from this class. All state transition timers
483 // will be removed.
484 void DeregisterDevice(int interface_index);
485
486 // Notifies this object that a device has been initialized.
487 void NotifyDeviceInitialized(int interface_index);
488
Thieu Lece4483e2013-01-23 15:12:03 -0800489 // Notifies this object that a device has started the enable process.
490 void NotifyDeviceEnableStarted(int interface_index);
491
492 // Notifies this object that a device has completed the enable process.
493 void NotifyDeviceEnableFinished(int interface_index);
494
Thieu Lea2519bf2013-01-23 16:51:54 -0800495 // Notifies this object that a device has started the disable process.
496 void NotifyDeviceDisableStarted(int interface_index);
497
498 // Notifies this object that a device has completed the disable process.
499 void NotifyDeviceDisableFinished(int interface_index);
500
Thieu Le18c11072013-01-28 17:21:37 -0800501 // Notifies this object that a device has started the scanning process.
502 void NotifyDeviceScanStarted(int interface_index);
503
504 // Notifies this object that a device has completed the scanning process.
Wade Guthrie5a4e2ef2013-04-30 12:51:39 -0700505 virtual void NotifyDeviceScanFinished(int interface_index);
Thieu Le18c11072013-01-28 17:21:37 -0800506
Thieu Lecdb5a212013-01-25 11:17:18 -0800507 // Notifies this object that a device has started the connect process.
Thieu Le7cf36b02013-01-30 17:15:56 -0800508 void NotifyDeviceConnectStarted(int interface_index,
509 bool is_auto_connecting);
Thieu Lecdb5a212013-01-25 11:17:18 -0800510
511 // Notifies this object that a device has completed the connect process.
512 void NotifyDeviceConnectFinished(int interface_index);
513
Thieu Le26fc01b2013-01-28 12:08:48 -0800514 // Notifies this object that a cellular device has been dropped by the
515 // network.
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800516 void NotifyCellularDeviceDrop(int interface_index,
517 const std::string &network_technology,
Thieu Le26fc01b2013-01-28 12:08:48 -0800518 uint16 signal_strength);
519
Thieu Leb7aa5f72013-01-31 15:57:48 -0800520 // Notifies this object about a cellular device failure code.
521 void NotifyCellularDeviceFailure(const Error &error);
522
Thieu Le91fccf62013-04-22 15:23:16 -0700523 // Notifies this object that a cellular service has been marked as
524 // out-of-credits.
525 void NotifyCellularOutOfCredits(Metrics::CellularOutOfCreditsReason reason);
526
Thieu Le5133b712013-02-19 14:47:21 -0800527 // Notifies this object about a corrupted profile.
528 virtual void NotifyCorruptedProfile();
529
Thieu Le48e6d6d2011-12-06 00:40:27 +0000530 // Sends linear histogram data to UMA.
Thieu Le85e050b2012-03-13 15:04:38 -0700531 virtual bool SendEnumToUMA(const std::string &name, int sample, int max);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000532
Thieu Lea20cbc22012-01-09 22:01:43 +0000533 // Send histogram data to UMA.
Thieu Le85e050b2012-03-13 15:04:38 -0700534 virtual bool SendToUMA(const std::string &name, int sample, int min,
535 int max, int num_buckets);
Thieu Lea20cbc22012-01-09 22:01:43 +0000536
Thieu Le48e6d6d2011-12-06 00:40:27 +0000537 private:
Thieu Le48e6d6d2011-12-06 00:40:27 +0000538 friend class MetricsTest;
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800539 FRIEND_TEST(MetricsTest, CellularDropsPerHour);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000540 FRIEND_TEST(MetricsTest, FrequencyToChannel);
Thieu Leb84ba342012-03-02 15:15:19 -0800541 FRIEND_TEST(MetricsTest, ServiceFailure);
Thieu Lea20cbc22012-01-09 22:01:43 +0000542 FRIEND_TEST(MetricsTest, TimeOnlineTimeToDrop);
Thieu Leb84ba342012-03-02 15:15:19 -0800543 FRIEND_TEST(MetricsTest, TimeToConfig);
544 FRIEND_TEST(MetricsTest, TimeToOnline);
545 FRIEND_TEST(MetricsTest, TimeToPortal);
Thieu Le18c11072013-01-28 17:21:37 -0800546 FRIEND_TEST(MetricsTest, TimeToScanIgnore);
Thieu Leb84ba342012-03-02 15:15:19 -0800547 FRIEND_TEST(MetricsTest, WiFiServiceChannel);
548 FRIEND_TEST(MetricsTest, WiFiServicePostReady);
Gaurav Shah6d2c72d2012-10-16 16:30:44 -0700549 FRIEND_TEST(WiFiMainTest, GetGeolocationObjects);
Thieu Le48e6d6d2011-12-06 00:40:27 +0000550
551 typedef ScopedVector<chromeos_metrics::TimerReporter> TimerReporters;
552 typedef std::list<chromeos_metrics::TimerReporter *> TimerReportersList;
553 typedef std::map<Service::ConnectState, TimerReportersList>
554 TimerReportersByState;
555 struct ServiceMetrics {
556 ServiceMetrics() : service(NULL) {}
557 // The service is registered/deregistered in the Service
558 // constructor/destructor, therefore there is no need to keep a ref count.
559 const Service *service;
560 // All TimerReporter objects are stored in |timers| which owns the objects.
561 // |start_on_state| and |stop_on_state| contain pointers to the
562 // TimerReporter objects and control when to start and stop the timers.
563 TimerReporters timers;
564 TimerReportersByState start_on_state;
565 TimerReportersByState stop_on_state;
566 };
567 typedef std::map<const Service *, std::tr1::shared_ptr<ServiceMetrics> >
568 ServiceMetricsLookupMap;
569
Thieu Lec8078a62013-01-22 18:01:12 -0800570 struct DeviceMetrics {
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800571 DeviceMetrics() : auto_connect_tries(0), num_drops(0) {}
Thieu Le9abd6742013-01-23 23:35:37 -0800572 Technology::Identifier technology;
Thieu Lec8078a62013-01-22 18:01:12 -0800573 scoped_ptr<chromeos_metrics::TimerReporter> initialization_timer;
Thieu Lece4483e2013-01-23 15:12:03 -0800574 scoped_ptr<chromeos_metrics::TimerReporter> enable_timer;
Thieu Lea2519bf2013-01-23 16:51:54 -0800575 scoped_ptr<chromeos_metrics::TimerReporter> disable_timer;
Thieu Le18c11072013-01-28 17:21:37 -0800576 scoped_ptr<chromeos_metrics::TimerReporter> scan_timer;
Thieu Lecdb5a212013-01-25 11:17:18 -0800577 scoped_ptr<chromeos_metrics::TimerReporter> connect_timer;
Thieu Le7cf36b02013-01-30 17:15:56 -0800578 scoped_ptr<chromeos_metrics::TimerReporter> auto_connect_timer;
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800579 int auto_connect_tries;
580 int num_drops;
Thieu Lec8078a62013-01-22 18:01:12 -0800581 };
582 typedef std::map<const int, std::tr1::shared_ptr<DeviceMetrics> >
583 DeviceMetricsLookupMap;
584
Thieu Le48e6d6d2011-12-06 00:40:27 +0000585 static const uint16 kWiFiBandwidth5MHz;
586 static const uint16 kWiFiBandwidth20MHz;
587 static const uint16 kWiFiFrequency2412;
588 static const uint16 kWiFiFrequency2472;
589 static const uint16 kWiFiFrequency2484;
590 static const uint16 kWiFiFrequency5170;
591 static const uint16 kWiFiFrequency5180;
592 static const uint16 kWiFiFrequency5230;
593 static const uint16 kWiFiFrequency5240;
594 static const uint16 kWiFiFrequency5320;
595 static const uint16 kWiFiFrequency5500;
596 static const uint16 kWiFiFrequency5700;
597 static const uint16 kWiFiFrequency5745;
598 static const uint16 kWiFiFrequency5825;
599
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800600 static const int kHourlyTimeoutMilliseconds;
601
Thieu Le48e6d6d2011-12-06 00:40:27 +0000602 void InitializeCommonServiceMetrics(const Service *service);
603 void UpdateServiceStateTransitionMetrics(ServiceMetrics *service_metrics,
604 Service::ConnectState new_state);
605 void SendServiceFailure(const Service *service);
606
Wade Guthrie60a37062013-04-02 11:39:09 -0700607 DeviceMetrics *GetDeviceMetrics(int interface_index) const;
Thieu Le7cf36b02013-01-30 17:15:56 -0800608 void AutoConnectMetricsReset(DeviceMetrics *device_metrics);
Thieu Lece4483e2013-01-23 15:12:03 -0800609
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800610 void HourlyTimeoutHandler();
611
Thieu Le48e6d6d2011-12-06 00:40:27 +0000612 // For unit test purposes.
613 void set_library(MetricsLibraryInterface *library);
Thieu Lea20cbc22012-01-09 22:01:43 +0000614 void set_time_online_timer(chromeos_metrics::Timer *timer) {
615 time_online_timer_.reset(timer); // Passes ownership
616 }
617 void set_time_to_drop_timer(chromeos_metrics::Timer *timer) {
618 time_to_drop_timer_.reset(timer); // Passes ownership
619 }
Thieu Leb84ba342012-03-02 15:15:19 -0800620 void set_time_resume_to_ready_timer(chromeos_metrics::Timer *timer) {
621 time_resume_to_ready_timer_.reset(timer); // Passes ownership
622 }
Arman Ugurayab22c162012-10-08 19:08:38 -0700623 void set_time_termination_actions_timer(
624 chromeos_metrics::Timer *timer) {
625 time_termination_actions_timer.reset(timer); // Passes ownership
626 }
Thieu Le18c11072013-01-28 17:21:37 -0800627 void set_time_to_scan_timer(int interface_index,
628 chromeos_metrics::TimerReporter *timer) {
629 DeviceMetrics *device_metrics = GetDeviceMetrics(interface_index);
630 device_metrics->scan_timer.reset(timer); // Passes ownership
631 }
Thieu Le48e6d6d2011-12-06 00:40:27 +0000632
633 // |library_| points to |metrics_library_| when shill runs normally.
634 // However, in order to allow for unit testing, we point |library_| to a
635 // MetricsLibraryMock object instead.
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800636 EventDispatcher *dispatcher_;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000637 MetricsLibrary metrics_library_;
638 MetricsLibraryInterface *library_;
639 ServiceMetricsLookupMap services_metrics_;
Thieu Lea20cbc22012-01-09 22:01:43 +0000640 Technology::Identifier last_default_technology_;
641 bool was_online_;
642 scoped_ptr<chromeos_metrics::Timer> time_online_timer_;
643 scoped_ptr<chromeos_metrics::Timer> time_to_drop_timer_;
Thieu Leb84ba342012-03-02 15:15:19 -0800644 scoped_ptr<chromeos_metrics::Timer> time_resume_to_ready_timer_;
Arman Ugurayab22c162012-10-08 19:08:38 -0700645 scoped_ptr<chromeos_metrics::Timer> time_termination_actions_timer;
Darin Petkov58f0b6d2012-06-12 12:52:30 +0200646 bool collect_bootstats_;
Thieu Lec8078a62013-01-22 18:01:12 -0800647 DeviceMetricsLookupMap devices_metrics_;
Thieu Le6c1e3bb2013-02-06 15:20:35 -0800648 base::CancelableClosure hourly_timeout_handler_;
Thieu Le48e6d6d2011-12-06 00:40:27 +0000649
650 DISALLOW_COPY_AND_ASSIGN(Metrics);
651};
652
653} // namespace shill
654
Wade Guthrie60a37062013-04-02 11:39:09 -0700655#endif // SHILL_METRICS_H_