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. 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/base/net_errors.h" 12#include "net/socket/client_socket_handle.h" 13 14namespace net { 15 16using base::Histogram; 17using base::HistogramBase; 18using base::LinearHistogram; 19using base::CustomHistogram; 20 21ClientSocketPoolHistograms::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); 52 53 if (pool_name == "HTTPProxy") 54 is_http_proxy_connection_ = true; 55 else if (pool_name == "SOCK") 56 is_socks_connection_ = true; 57} 58 59ClientSocketPoolHistograms::~ClientSocketPoolHistograms() { 60} 61 62void ClientSocketPoolHistograms::AddSocketType(int type) const { 63 socket_type_->Add(type); 64} 65 66void ClientSocketPoolHistograms::AddRequestTime(base::TimeDelta time) const { 67 request_time_->AddTime(time); 68} 69 70void ClientSocketPoolHistograms::AddUnusedIdleTime(base::TimeDelta time) const { 71 unused_idle_time_->AddTime(time); 72} 73 74void ClientSocketPoolHistograms::AddReusedIdleTime(base::TimeDelta time) const { 75 reused_idle_time_->AddTime(time); 76} 77 78void ClientSocketPoolHistograms::AddErrorCode(int error_code) const { 79 // Error codes are positive (since histograms expect positive sample values). 80 error_code_->Add(-error_code); 81} 82 83} // namespace net 84