Add UMA reporting to CdmPromise.
[chromium-blink-merge.git] / net / socket / client_socket_pool_histograms.cc
blob9af8649c48b1ac87de1deab24a05c1ada281cd78
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/socket/client_socket_pool_histograms.h"
7 #include <string>
9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h"
11 #include "net/base/net_errors.h"
12 #include "net/socket/client_socket_handle.h"
14 namespace net {
16 using base::Histogram;
17 using base::HistogramBase;
18 using base::LinearHistogram;
19 using base::CustomHistogram;
21 ClientSocketPoolHistograms::ClientSocketPoolHistograms(
22 const std::string& pool_name)
23 : is_http_proxy_connection_(false),
24 is_socks_connection_(false) {
25 // UMA_HISTOGRAM_ENUMERATION
26 socket_type_ = LinearHistogram::FactoryGet("Net.SocketType_" + pool_name, 1,
27 ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1,
28 HistogramBase::kUmaTargetedHistogramFlag);
29 // UMA_HISTOGRAM_CUSTOM_TIMES
30 request_time_ = Histogram::FactoryTimeGet(
31 "Net.SocketRequestTime_" + pool_name,
32 base::TimeDelta::FromMilliseconds(1),
33 base::TimeDelta::FromMinutes(10),
34 100, HistogramBase::kUmaTargetedHistogramFlag);
35 // UMA_HISTOGRAM_CUSTOM_TIMES
36 unused_idle_time_ = Histogram::FactoryTimeGet(
37 "Net.SocketIdleTimeBeforeNextUse_UnusedSocket_" + pool_name,
38 base::TimeDelta::FromMilliseconds(1),
39 base::TimeDelta::FromMinutes(6),
40 100, HistogramBase::kUmaTargetedHistogramFlag);
41 // UMA_HISTOGRAM_CUSTOM_TIMES
42 reused_idle_time_ = Histogram::FactoryTimeGet(
43 "Net.SocketIdleTimeBeforeNextUse_ReusedSocket_" + pool_name,
44 base::TimeDelta::FromMilliseconds(1),
45 base::TimeDelta::FromMinutes(6),
46 100, HistogramBase::kUmaTargetedHistogramFlag);
47 // UMA_HISTOGRAM_CUSTOM_ENUMERATION
48 error_code_ = CustomHistogram::FactoryGet(
49 "Net.SocketInitErrorCodes_" + pool_name,
50 GetAllErrorCodesForUma(),
51 HistogramBase::kUmaTargetedHistogramFlag);
53 if (pool_name == "HTTPProxy")
54 is_http_proxy_connection_ = true;
55 else if (pool_name == "SOCK")
56 is_socks_connection_ = true;
59 ClientSocketPoolHistograms::~ClientSocketPoolHistograms() {
62 void ClientSocketPoolHistograms::AddSocketType(int type) const {
63 socket_type_->Add(type);
66 void ClientSocketPoolHistograms::AddRequestTime(base::TimeDelta time) const {
67 request_time_->AddTime(time);
70 void ClientSocketPoolHistograms::AddUnusedIdleTime(base::TimeDelta time) const {
71 unused_idle_time_->AddTime(time);
74 void ClientSocketPoolHistograms::AddReusedIdleTime(base::TimeDelta time) const {
75 reused_idle_time_->AddTime(time);
78 void ClientSocketPoolHistograms::AddErrorCode(int error_code) const {
79 // Error codes are positive (since histograms expect positive sample values).
80 error_code_->Add(-error_code);
83 } // namespace net