diff options
author | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-24 08:09:14 +0000 |
---|---|---|
committer | toyoshim@chromium.org <toyoshim@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-06-24 08:09:14 +0000 |
commit | 57f6e74d4cd92cc5ea83c0b6d76898328ea764f1 (patch) | |
tree | c8d48deb2452de791fb73bb40ed9f5288da85aa8 /net/socket_stream | |
parent | 85dd5dcae7e86f4c90f6d40fee497598761b891e (diff) | |
download | chromium_src-57f6e74d4cd92cc5ea83c0b6d76898328ea764f1.zip chromium_src-57f6e74d4cd92cc5ea83c0b6d76898328ea764f1.tar.gz chromium_src-57f6e74d4cd92cc5ea83c0b6d76898328ea764f1.tar.bz2 |
Update SocketStreamMetrics to support new metrics on protocol switch.
This change also include refactoring on SocketStreamMetrics.
BUG=42320
TEST=net_unittests --gtest_filter=SocketStream\*
Review URL: http://codereview.chromium.org/7191014
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90343 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/socket_stream')
-rw-r--r-- | net/socket_stream/socket_stream.cc | 21 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_metrics.cc | 38 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_metrics.h | 14 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_metrics_unittest.cc | 37 |
4 files changed, 67 insertions, 43 deletions
diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index 5915ba4..b49a6a1 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -546,13 +546,18 @@ int SocketStream::DoResolveHost() { int SocketStream::DoResolveHostComplete(int result) { if (result == OK && delegate_) { - next_state_ = STATE_TCP_CONNECT; result = delegate_->OnStartOpenConnection(this, &io_callback_); - if (result == ERR_IO_PENDING) - metrics_->OnWaitConnection(); - else if (result == ERR_PROTOCOL_SWITCHED) - // TODO(toyoshim): Add metrics events for protocol switch. + if (result == ERR_PROTOCOL_SWITCHED) { next_state_ = STATE_CLOSE; + metrics_->OnCountWireProtocolType( + SocketStreamMetrics::WIRE_PROTOCOL_SPDY); + } else { + next_state_ = STATE_TCP_CONNECT; + metrics_->OnCountWireProtocolType( + SocketStreamMetrics::WIRE_PROTOCOL_WEBSOCKET); + if (result == ERR_IO_PENDING) + metrics_->OnWaitConnection(); + } } else { next_state_ = STATE_CLOSE; } @@ -603,7 +608,7 @@ int SocketStream::DoWriteTunnelHeaders() { next_state_ = STATE_WRITE_TUNNEL_HEADERS_COMPLETE; if (!tunnel_request_headers_.get()) { - metrics_->OnTunnelProxy(); + metrics_->OnCountConnectionType(SocketStreamMetrics::TUNNEL_CONNECTION); tunnel_request_headers_ = new RequestHeaders(); tunnel_request_headers_bytes_sent_ = 0; } @@ -801,7 +806,7 @@ int SocketStream::DoSOCKSConnect() { else s = new SOCKSClientSocket(s, req_info, host_resolver_); socket_.reset(s); - metrics_->OnSOCKSProxy(); + metrics_->OnCountConnectionType(SocketStreamMetrics::SOCKS_CONNECTION); return socket_->Connect(&io_callback_); } @@ -828,7 +833,7 @@ int SocketStream::DoSSLConnect() { NULL /* ssl_host_info */, cert_verifier_)); next_state_ = STATE_SSL_CONNECT_COMPLETE; - metrics_->OnSSLConnection(); + metrics_->OnCountConnectionType(SocketStreamMetrics::SSL_CONNECTION); return socket_->Connect(&io_callback_); } diff --git a/net/socket_stream/socket_stream_metrics.cc b/net/socket_stream/socket_stream_metrics.cc index 108e829..7ef92bb 100644 --- a/net/socket_stream/socket_stream_metrics.cc +++ b/net/socket_stream/socket_stream_metrics.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -17,13 +17,14 @@ SocketStreamMetrics::SocketStreamMetrics(const GURL& url) received_counts_(0), sent_bytes_(0), sent_counts_(0) { - ProtocolType proto_type = PROTOCOL_UNKNOWN; + ProtocolType protocol_type = PROTOCOL_UNKNOWN; if (url.SchemeIs("ws")) - proto_type = PROTOCOL_WEBSOCKET; + protocol_type = PROTOCOL_WEBSOCKET; else if (url.SchemeIs("wss")) - proto_type = PROTOCOL_WEBSOCKET_SECURE; + protocol_type = PROTOCOL_WEBSOCKET_SECURE; - CountProtocolType(proto_type); + UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.ProtocolType", + protocol_type, NUM_PROTOCOL_TYPES); } SocketStreamMetrics::~SocketStreamMetrics() {} @@ -37,19 +38,7 @@ void SocketStreamMetrics::OnStartConnection() { if (!wait_start_time_.is_null()) UMA_HISTOGRAM_TIMES("Net.SocketStream.ConnectionLatency", connect_start_time_ - wait_start_time_); - CountConnectionType(ALL_CONNECTIONS); -} - -void SocketStreamMetrics::OnTunnelProxy() { - CountConnectionType(TUNNEL_CONNECTION); -} - -void SocketStreamMetrics::OnSOCKSProxy() { - CountConnectionType(SOCKS_CONNECTION); -} - -void SocketStreamMetrics::OnSSLConnection() { - CountConnectionType(SSL_CONNECTION); + OnCountConnectionType(ALL_CONNECTIONS); } void SocketStreamMetrics::OnConnected() { @@ -84,15 +73,14 @@ void SocketStreamMetrics::OnClose() { } } -void SocketStreamMetrics::CountProtocolType(ProtocolType protocol_type) { - UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.ProtocolType", - protocol_type, NUM_PROTOCOL_TYPES); +void SocketStreamMetrics::OnCountConnectionType(ConnectionType type) { + UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.ConnectionType", type, + NUM_CONNECTION_TYPES); } -void SocketStreamMetrics::CountConnectionType(ConnectionType connection_type) { - UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.ConnectionType", - connection_type, NUM_CONNECTION_TYPES); +void SocketStreamMetrics::OnCountWireProtocolType(WireProtocolType type) { + UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.WireProtocolType", type, + NUM_WIRE_PROTOCOL_TYPES); } - } // namespace net diff --git a/net/socket_stream/socket_stream_metrics.h b/net/socket_stream/socket_stream_metrics.h index 4bd93be6..83666fe 100644 --- a/net/socket_stream/socket_stream_metrics.h +++ b/net/socket_stream/socket_stream_metrics.h @@ -35,23 +35,25 @@ class NET_TEST SocketStreamMetrics { NUM_CONNECTION_TYPES, }; + enum WireProtocolType { + WIRE_PROTOCOL_WEBSOCKET, + WIRE_PROTOCOL_SPDY, + NUM_WIRE_PROTOCOL_TYPES, + }; + explicit SocketStreamMetrics(const GURL& url); ~SocketStreamMetrics(); void OnWaitConnection(); void OnStartConnection(); - void OnTunnelProxy(); - void OnSOCKSProxy(); - void OnSSLConnection(); void OnConnected(); void OnRead(int len); void OnWrite(int len); void OnClose(); + void OnCountConnectionType(ConnectionType type); + void OnCountWireProtocolType(WireProtocolType type); private: - void CountProtocolType(ProtocolType protocol_type); - void CountConnectionType(ConnectionType connection_type); - base::TimeTicks wait_start_time_; base::TimeTicks connect_start_time_; base::TimeTicks connect_establish_time_; diff --git a/net/socket_stream/socket_stream_metrics_unittest.cc b/net/socket_stream/socket_stream_metrics_unittest.cc index bd31bb7..cf4544c 100644 --- a/net/socket_stream/socket_stream_metrics_unittest.cc +++ b/net/socket_stream/socket_stream_metrics_unittest.cc @@ -51,7 +51,7 @@ TEST(SocketStreamMetricsTest, ProtocolType) { Histogram::SampleSet sample; histogram->SnapshotSample(&sample); original.Resize(*histogram); // Ensure |original| size is same as |sample|. - sample.Subtract(original); // Cancel the original values. + sample.Subtract(original); // Cancel the original values. EXPECT_EQ(1, sample.counts(SocketStreamMetrics::PROTOCOL_UNKNOWN)); EXPECT_EQ(2, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET)); EXPECT_EQ(3, sample.counts(SocketStreamMetrics::PROTOCOL_WEBSOCKET_SECURE)); @@ -71,11 +71,11 @@ TEST(SocketStreamMetricsTest, ConnectionType) { for (int i = 0; i < 1; ++i) metrics.OnStartConnection(); for (int i = 0; i < 2; ++i) - metrics.OnTunnelProxy(); + metrics.OnCountConnectionType(SocketStreamMetrics::TUNNEL_CONNECTION); for (int i = 0; i < 3; ++i) - metrics.OnSOCKSProxy(); + metrics.OnCountConnectionType(SocketStreamMetrics::SOCKS_CONNECTION); for (int i = 0; i < 4; ++i) - metrics.OnSSLConnection(); + metrics.OnCountConnectionType(SocketStreamMetrics::SSL_CONNECTION); ASSERT_TRUE(StatisticsRecorder::FindHistogram( "Net.SocketStream.ConnectionType", &histogram)); @@ -91,6 +91,35 @@ TEST(SocketStreamMetricsTest, ConnectionType) { EXPECT_EQ(4, sample.counts(SocketStreamMetrics::SSL_CONNECTION)); } +TEST(SocketStreamMetricsTest, WireProtocolType) { + Histogram* histogram; + + // First we'll preserve the original values. + Histogram::SampleSet original; + if (StatisticsRecorder::FindHistogram( + "Net.SocketStream.WireProtocolType", &histogram)) { + histogram->SnapshotSample(&original); + } + + SocketStreamMetrics metrics(GURL("ws://www.example.com/")); + for (int i = 0; i < 3; ++i) + metrics.OnCountWireProtocolType( + SocketStreamMetrics::WIRE_PROTOCOL_WEBSOCKET); + for (int i = 0; i < 7; ++i) + metrics.OnCountWireProtocolType(SocketStreamMetrics::WIRE_PROTOCOL_SPDY); + + ASSERT_TRUE(StatisticsRecorder::FindHistogram( + "Net.SocketStream.WireProtocolType", &histogram)); + EXPECT_EQ(Histogram::kUmaTargetedHistogramFlag, histogram->flags()); + + Histogram::SampleSet sample; + histogram->SnapshotSample(&sample); + original.Resize(*histogram); + sample.Subtract(original); + EXPECT_EQ(3, sample.counts(SocketStreamMetrics::WIRE_PROTOCOL_WEBSOCKET)); + EXPECT_EQ(7, sample.counts(SocketStreamMetrics::WIRE_PROTOCOL_SPDY)); +} + TEST(SocketStreamMetricsTest, OtherNumbers) { Histogram* histogram; |