OLD | NEW |
---|---|
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/metrics/net/network_metrics_provider.h" | 5 #include "components/metrics/net/network_metrics_provider.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
11 | 11 |
12 #include "base/compiler_specific.h" | 12 #include "base/compiler_specific.h" |
13 #include "base/metrics/histogram_base.h" | |
14 #include "base/metrics/histogram_macros.h" | |
15 #include "base/metrics/sparse_histogram.h" | |
13 #include "base/strings/string_number_conversions.h" | 16 #include "base/strings/string_number_conversions.h" |
14 #include "base/strings/string_split.h" | 17 #include "base/strings/string_split.h" |
15 #include "base/strings/string_util.h" | 18 #include "base/strings/string_util.h" |
16 #include "base/task_runner_util.h" | 19 #include "base/task_runner_util.h" |
17 #include "build/build_config.h" | 20 #include "build/build_config.h" |
21 #include "net/base/net_errors.h" | |
18 | 22 |
19 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
20 #include "components/metrics/net/wifi_access_point_info_provider_chromeos.h" | 24 #include "components/metrics/net/wifi_access_point_info_provider_chromeos.h" |
21 #endif // OS_CHROMEOS | 25 #endif // OS_CHROMEOS |
22 | 26 |
23 namespace metrics { | 27 namespace metrics { |
24 | 28 |
25 NetworkMetricsProvider::NetworkMetricsProvider( | 29 NetworkMetricsProvider::NetworkMetricsProvider( |
26 base::TaskRunner* io_task_runner) | 30 base::TaskRunner* io_task_runner) |
27 : io_task_runner_(io_task_runner), | 31 : io_task_runner_(io_task_runner), |
28 connection_type_is_ambiguous_(false), | 32 connection_type_is_ambiguous_(false), |
29 wifi_phy_layer_protocol_is_ambiguous_(false), | 33 wifi_phy_layer_protocol_is_ambiguous_(false), |
30 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN), | 34 wifi_phy_layer_protocol_(net::WIFI_PHY_LAYER_PROTOCOL_UNKNOWN), |
31 weak_ptr_factory_(this) { | 35 weak_ptr_factory_(this) { |
32 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); | 36 net::NetworkChangeNotifier::AddConnectionTypeObserver(this); |
33 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); | 37 connection_type_ = net::NetworkChangeNotifier::GetConnectionType(); |
34 ProbeWifiPHYLayerProtocol(); | 38 ProbeWifiPHYLayerProtocol(); |
35 } | 39 } |
36 | 40 |
37 NetworkMetricsProvider::~NetworkMetricsProvider() { | 41 NetworkMetricsProvider::~NetworkMetricsProvider() { |
38 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); | 42 net::NetworkChangeNotifier::RemoveConnectionTypeObserver(this); |
39 } | 43 } |
40 | 44 |
41 void NetworkMetricsProvider::ProvideGeneralMetrics( | 45 void NetworkMetricsProvider::ProvideGeneralMetrics( |
42 ChromeUserMetricsExtension*) { | 46 ChromeUserMetricsExtension*) { |
43 // ProvideGeneralMetrics is called on the main thread, at the time a metrics | 47 // ProvideGeneralMetrics is called on the main thread, at the time a metrics |
44 // record is being finalized. | 48 // record is being finalized. |
45 net::NetworkChangeNotifier::FinalizingMetricsLogRecord(); | 49 net::NetworkChangeNotifier::FinalizingMetricsLogRecord(); |
50 LogAggregatedMetrics(); | |
46 } | 51 } |
47 | 52 |
48 void NetworkMetricsProvider::ProvideSystemProfileMetrics( | 53 void NetworkMetricsProvider::ProvideSystemProfileMetrics( |
49 SystemProfileProto* system_profile) { | 54 SystemProfileProto* system_profile) { |
50 SystemProfileProto::Network* network = system_profile->mutable_network(); | 55 SystemProfileProto::Network* network = system_profile->mutable_network(); |
51 network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_); | 56 network->set_connection_type_is_ambiguous(connection_type_is_ambiguous_); |
52 network->set_connection_type(GetConnectionType()); | 57 network->set_connection_type(GetConnectionType()); |
53 network->set_wifi_phy_layer_protocol_is_ambiguous( | 58 network->set_wifi_phy_layer_protocol_is_ambiguous( |
54 wifi_phy_layer_protocol_is_ambiguous_); | 59 wifi_phy_layer_protocol_is_ambiguous_); |
55 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); | 60 network->set_wifi_phy_layer_protocol(GetWifiPHYLayerProtocol()); |
(...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
233 for (const base::StringPiece& oui_str : base::SplitStringPiece( | 238 for (const base::StringPiece& oui_str : base::SplitStringPiece( |
234 info.oui_list, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { | 239 info.oui_list, " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL)) { |
235 uint32_t oui; | 240 uint32_t oui; |
236 if (base::HexStringToUInt(oui_str, &oui)) | 241 if (base::HexStringToUInt(oui_str, &oui)) |
237 vendor->add_element_identifier(oui); | 242 vendor->add_element_identifier(oui); |
238 else | 243 else |
239 NOTREACHED(); | 244 NOTREACHED(); |
240 } | 245 } |
241 } | 246 } |
242 | 247 |
248 void NetworkMetricsProvider::LogAggregatedMetrics() { | |
249 base::HistogramBase* error_codes = base::SparseHistogram::FactoryGet( | |
250 "Net.ErrorCodesForMainFrame3", | |
251 base::HistogramBase::kUmaTargetedHistogramFlag); | |
252 scoped_ptr<base::HistogramSamples> samples = error_codes->SnapshotSamples(); | |
Ilya Sherman
2016/03/16 22:33:41
Hmm, I think this will give you the total number o
Charlie Harrison
2016/03/17 14:03:20
Ah I misunderstood and thought that SnapshotSample
| |
253 base::HistogramBase::Count aborts = samples->GetCount(-net::ERR_ABORTED); | |
254 base::HistogramBase::Count total_codes = samples->TotalCount(); | |
255 if (total_codes > 0) { | |
256 UMA_HISTOGRAM_COUNTS("Net.ErrAborted.CountPerUpload", aborts); | |
257 UMA_HISTOGRAM_PERCENTAGE("Net.ErrAborted.ProportionPerUpload", | |
258 (100.0 * aborts) / total_codes); | |
Ilya Sherman
2016/03/16 22:33:41
Hmm, this looks like an implicit conversion from f
Charlie Harrison
2016/03/17 14:03:20
Changed to a multiplication by 100.
| |
259 } | |
260 } | |
261 | |
243 } // namespace metrics | 262 } // namespace metrics |
OLD | NEW |