• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright (c) 2010 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.
4 
5 #include "net/socket/client_socket_pool_histograms.h"
6 
7 #include <string>
8 
9 #include "base/metrics/field_trial.h"
10 #include "base/metrics/histogram.h"
11 #include "net/socket/client_socket_handle.h"
12 
13 namespace net {
14 
15 using base::Histogram;
16 using base::LinearHistogram;
17 
ClientSocketPoolHistograms(const std::string & pool_name)18 ClientSocketPoolHistograms::ClientSocketPoolHistograms(
19     const std::string& pool_name)
20     : is_http_proxy_connection_(false),
21       is_socks_connection_(false) {
22   // UMA_HISTOGRAM_ENUMERATION
23   socket_type_ = LinearHistogram::FactoryGet("Net.SocketType_" + pool_name, 1,
24       ClientSocketHandle::NUM_TYPES, ClientSocketHandle::NUM_TYPES + 1,
25       Histogram::kUmaTargetedHistogramFlag);
26   // UMA_HISTOGRAM_CUSTOM_TIMES
27   request_time_ = Histogram::FactoryTimeGet(
28       "Net.SocketRequestTime_" + pool_name,
29       base::TimeDelta::FromMilliseconds(1),
30       base::TimeDelta::FromMinutes(10),
31       100, Histogram::kUmaTargetedHistogramFlag);
32   // UMA_HISTOGRAM_CUSTOM_TIMES
33   unused_idle_time_ = Histogram::FactoryTimeGet(
34       "Net.SocketIdleTimeBeforeNextUse_UnusedSocket_" + pool_name,
35       base::TimeDelta::FromMilliseconds(1),
36       base::TimeDelta::FromMinutes(6),
37       100, Histogram::kUmaTargetedHistogramFlag);
38   // UMA_HISTOGRAM_CUSTOM_TIMES
39   reused_idle_time_ = Histogram::FactoryTimeGet(
40       "Net.SocketIdleTimeBeforeNextUse_ReusedSocket_" + pool_name,
41       base::TimeDelta::FromMilliseconds(1),
42       base::TimeDelta::FromMinutes(6),
43       100, Histogram::kUmaTargetedHistogramFlag);
44 
45   if (pool_name == "HTTPProxy")
46     is_http_proxy_connection_ = true;
47   else if (pool_name == "SOCK")
48     is_socks_connection_ = true;
49 }
50 
~ClientSocketPoolHistograms()51 ClientSocketPoolHistograms::~ClientSocketPoolHistograms() {
52 }
53 
AddSocketType(int type) const54 void ClientSocketPoolHistograms::AddSocketType(int type) const {
55   socket_type_->Add(type);
56 }
57 
AddRequestTime(base::TimeDelta time) const58 void ClientSocketPoolHistograms::AddRequestTime(base::TimeDelta time) const {
59   request_time_->AddTime(time);
60 
61   static bool proxy_connection_impact_trial_exists(
62       base::FieldTrialList::Find("ProxyConnectionImpact") &&
63       !base::FieldTrialList::Find("ProxyConnectionImpact")->
64           group_name().empty());
65   if (proxy_connection_impact_trial_exists && is_http_proxy_connection_) {
66     UMA_HISTOGRAM_CUSTOM_TIMES(
67         base::FieldTrial::MakeName("Net.HttpProxySocketRequestTime",
68                              "ProxyConnectionImpact"),
69         time,
70         base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10),
71         100);
72   }
73   if (proxy_connection_impact_trial_exists && is_socks_connection_) {
74     UMA_HISTOGRAM_CUSTOM_TIMES(
75         base::FieldTrial::MakeName("Net.SocksSocketRequestTime",
76                              "ProxyConnectionImpact"),
77         time,
78         base::TimeDelta::FromMilliseconds(1), base::TimeDelta::FromMinutes(10),
79         100);
80   }
81 }
82 
AddUnusedIdleTime(base::TimeDelta time) const83 void ClientSocketPoolHistograms::AddUnusedIdleTime(base::TimeDelta time) const {
84   unused_idle_time_->AddTime(time);
85 }
86 
AddReusedIdleTime(base::TimeDelta time) const87 void ClientSocketPoolHistograms::AddReusedIdleTime(base::TimeDelta time) const {
88   reused_idle_time_->AddTime(time);
89 }
90 
91 }  // namespace net
92