diff options
author | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-11 05:53:12 +0000 |
---|---|---|
committer | ukai@chromium.org <ukai@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-11-11 05:53:12 +0000 |
commit | c7f689be146dd9f7ff0c271f4fc736ea6adeaaa6 (patch) | |
tree | 48b59b1d951006663d744ae1300d12821beb5c73 /net | |
parent | 38531587b801093b08a5d76664413bdf2b660467 (diff) | |
download | chromium_src-c7f689be146dd9f7ff0c271f4fc736ea6adeaaa6.zip chromium_src-c7f689be146dd9f7ff0c271f4fc736ea6adeaaa6.tar.gz chromium_src-c7f689be146dd9f7ff0c271f4fc736ea6adeaaa6.tar.bz2 |
Metrics of SocketStream
BUG=none
TEST=none
Review URL: http://codereview.chromium.org/380004
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@31650 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/net.gyp | 2 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.cc | 14 | ||||
-rw-r--r-- | net/socket_stream/socket_stream.h | 3 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_metrics.cc | 102 | ||||
-rw-r--r-- | net/socket_stream/socket_stream_metrics.h | 66 |
5 files changed, 186 insertions, 1 deletions
diff --git a/net/net.gyp b/net/net.gyp index b80b2a9..fc0b5b1 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -431,6 +431,8 @@ 'socket/tcp_pinger.h', 'socket_stream/socket_stream.cc', 'socket_stream/socket_stream.h', + 'socket_stream/socket_stream_metrics.cc', + 'socket_stream/socket_stream_metrics.h', 'socket_stream/socket_stream_throttle.cc', 'socket_stream/socket_stream_throttle.h', 'third_party/parseftp/ParseFTPList.cpp', diff --git a/net/socket_stream/socket_stream.cc b/net/socket_stream/socket_stream.cc index fc8e77a..8ca8489 100644 --- a/net/socket_stream/socket_stream.cc +++ b/net/socket_stream/socket_stream.cc @@ -25,6 +25,7 @@ #include "net/socket/socks5_client_socket.h" #include "net/socket/socks_client_socket.h" #include "net/socket/tcp_client_socket.h" +#include "net/socket_stream/socket_stream_metrics.h" #include "net/socket_stream/socket_stream_throttle.h" #include "net/url_request/url_request.h" @@ -58,7 +59,8 @@ SocketStream::SocketStream(const GURL& url, Delegate* delegate) write_buf_size_(0), throttle_( SocketStreamThrottle::GetSocketStreamThrottleForScheme( - url.scheme())) { + url.scheme())), + metrics_(new SocketStreamMetrics(url)) { DCHECK(MessageLoop::current()) << "The current MessageLoop must exist"; DCHECK_EQ(MessageLoop::TYPE_IO, MessageLoop::current()->type()) << @@ -199,6 +201,7 @@ void SocketStream::Finish(int result) { if (delegate_) delegate_->OnError(this, result); + metrics_->OnClose(); Delegate* delegate = delegate_; delegate_ = NULL; if (delegate) { @@ -229,6 +232,7 @@ int SocketStream::DidEstablishConnection() { return ERR_CONNECTION_FAILED; } next_state_ = STATE_READ_WRITE; + metrics_->OnConnected(); if (delegate_) delegate_->OnConnected(this, max_pending_send_allowed_); @@ -240,6 +244,7 @@ int SocketStream::DidReceiveData(int result) { DCHECK(read_buf_); DCHECK_GT(result, 0); int len = result; + metrics_->OnRead(len); result = throttle_->OnRead(this, read_buf_->data(), len, &io_callback_); if (delegate_) { // Notify recevied data to delegate. @@ -252,6 +257,7 @@ int SocketStream::DidReceiveData(int result) { int SocketStream::DidSendData(int result) { DCHECK_GT(result, 0); int len = result; + metrics_->OnWrite(len); result = throttle_->OnWrite(this, current_write_buf_->data(), len, &io_callback_); current_write_buf_ = NULL; @@ -425,6 +431,8 @@ int SocketStream::DoResolveHostComplete(int result) { if (result == OK) { next_state_ = STATE_TCP_CONNECT; result = throttle_->OnStartOpenConnection(this, &io_callback_); + if (result == net::ERR_IO_PENDING) + metrics_->OnWaitConnection(); } else { next_state_ = STATE_CLOSE; } @@ -437,6 +445,7 @@ int SocketStream::DoTcpConnect() { DCHECK(factory_); socket_.reset(factory_->CreateTCPClientSocket(addresses_)); // TODO(willchan): Plumb LoadLog into SocketStream. + metrics_->OnStartConnection(); return socket_->Connect(&io_callback_, NULL); } @@ -465,6 +474,7 @@ int SocketStream::DoWriteTunnelHeaders() { next_state_ = STATE_WRITE_TUNNEL_HEADERS_COMPLETE; if (!tunnel_request_headers_.get()) { + metrics_->OnTunnelProxy(); tunnel_request_headers_ = new RequestHeaders(); tunnel_request_headers_bytes_sent_ = 0; } @@ -645,6 +655,7 @@ int SocketStream::DoSOCKSConnect() { s = new SOCKSClientSocket(s, req_info, host_resolver_.get()); socket_.reset(s); // TODO(willchan): Plumb LoadLog into SocketStream. + metrics_->OnSOCKSProxy(); return socket_->Connect(&io_callback_, NULL); } @@ -666,6 +677,7 @@ int SocketStream::DoSSLConnect() { socket_.release(), url_.HostNoBrackets(), ssl_config_)); next_state_ = STATE_SSL_CONNECT_COMPLETE; // TODO(willchan): Plumb LoadLog into SocketStream. + metrics_->OnSSLConnection(); return socket_->Connect(&io_callback_, NULL); } diff --git a/net/socket_stream/socket_stream.h b/net/socket_stream/socket_stream.h index 84fa2bb..ad06be0 100644 --- a/net/socket_stream/socket_stream.h +++ b/net/socket_stream/socket_stream.h @@ -31,6 +31,7 @@ class ClientSocketFactory; class HostResolver; class SSLConfigService; class SingleRequestHostResolver; +class SocketStreamMetrics; class SocketStreamThrottle; // SocketStream is used to implement Web Sockets. @@ -303,6 +304,8 @@ class SocketStream : public base::RefCountedThreadSafe<SocketStream> { SocketStreamThrottle* throttle_; + scoped_ptr<SocketStreamMetrics> metrics_; + DISALLOW_COPY_AND_ASSIGN(SocketStream); }; diff --git a/net/socket_stream/socket_stream_metrics.cc b/net/socket_stream/socket_stream_metrics.cc new file mode 100644 index 0000000..f7a55a4 --- /dev/null +++ b/net/socket_stream/socket_stream_metrics.cc @@ -0,0 +1,102 @@ +// Copyright (c) 2009 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. + +#include "net/socket_stream/socket_stream_metrics.h" + +#include <string.h> + +#include "base/histogram.h" +#include "base/time.h" +#include "googleurl/src/gurl.h" + +namespace net { + +SocketStreamMetrics::SocketStreamMetrics(const GURL& url) + : received_bytes_(0), + received_counts_(0), + sent_bytes_(0), + sent_counts_(0) { + ProtocolType proto_type = PROTOCOL_UNKNOWN; + if (url.SchemeIs("ws")) + proto_type = PROTOCOL_WEBSOCKET; + else if (url.SchemeIs("wss")) + proto_type = PROTOCOL_WEBSOCKET_SECURE; + + CountProtocolType(proto_type); +} + +SocketStreamMetrics::~SocketStreamMetrics() {} + +void SocketStreamMetrics::OnWaitConnection() { + wait_start_time_ = base::TimeTicks::Now(); +} + +void SocketStreamMetrics::OnStartConnection() { + connect_start_time_ = base::TimeTicks::Now(); + 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); +} + +void SocketStreamMetrics::OnConnected() { + connect_establish_time_ = base::TimeTicks::Now(); + UMA_HISTOGRAM_TIMES("Net.SocketStream.ConnectionEstablish", + connect_establish_time_ - connect_start_time_); +} + +void SocketStreamMetrics::OnRead(int len) { + received_bytes_ += len; + ++received_counts_; +} + +void SocketStreamMetrics::OnWrite(int len) { + sent_bytes_ += len; + ++sent_counts_; +} + +void SocketStreamMetrics::OnClose() { + base::TimeTicks closed_time = base::TimeTicks::Now(); + UMA_HISTOGRAM_LONG_TIMES("Net.SocketStream.Duration", + closed_time - connect_establish_time_); + UMA_HISTOGRAM_COUNTS("Net.SocketStream.ReceivedBytes", + received_bytes_); + UMA_HISTOGRAM_COUNTS("Net.SocketStream.ReceivedCounts", + received_counts_); + UMA_HISTOGRAM_COUNTS("Net.SocketStream.SentBytes", + sent_bytes_); + UMA_HISTOGRAM_COUNTS("Net.SocketStream.SentCounts", + sent_counts_); +} + +void SocketStreamMetrics::CountProtocolType(ProtocolType protocol_type) { + static LinearHistogram counter("Net.SocketStream.ProtocolType", + 0, NUM_PROTOCOL_TYPES, + NUM_PROTOCOL_TYPES + 1); + counter.SetFlags(kUmaTargetedHistogramFlag); + counter.Add(protocol_type); +} + +void SocketStreamMetrics::CountConnectionType(ConnectionType connection_type) { + static LinearHistogram counter("Net.SocketStream.ConnectionType", + 1, NUM_CONNECTION_TYPES, + NUM_CONNECTION_TYPES + 1); + counter.SetFlags(kUmaTargetedHistogramFlag); + counter.Add(connection_type); +} + + +} // namespace net diff --git a/net/socket_stream/socket_stream_metrics.h b/net/socket_stream/socket_stream_metrics.h new file mode 100644 index 0000000..67b1e33a0 --- /dev/null +++ b/net/socket_stream/socket_stream_metrics.h @@ -0,0 +1,66 @@ +// Copyright (c) 2009 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. +// +// Collect metrics of SocketStream usage. +// TODO(ukai): collect WebSocket specific metrics (e.g. handshake time, etc). + +#ifndef NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ +#define NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ + +#include <string> + +#include "base/basictypes.h" +#include "base/time.h" + +class GURL; + +namespace net { + +class SocketStreamMetrics { + public: + 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(); + + private: + enum ProtocolType { + PROTOCOL_UNKNOWN, + PROTOCOL_WEBSOCKET, + PROTOCOL_WEBSOCKET_SECURE, + NUM_PROTOCOL_TYPES, + }; + enum ConnectionType { + CONNECTION_NONE, + ALL_CONNECTIONS, + TUNNEL_CONNECTION, + SOCKS_CONNECTION, + SSL_CONNECTION, + NUM_CONNECTION_TYPES, + }; + 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_; + int received_bytes_; + int received_counts_; + int sent_bytes_; + int sent_counts_; + + DISALLOW_COPY_AND_ASSIGN(SocketStreamMetrics); +}; + +} // namespace net + +#endif // NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ |