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 // Collect metrics of SocketStream usage. 6 // TODO(ukai): collect WebSocket specific metrics (e.g. handshake time, etc). 7 8 #ifndef NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ 9 #define NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ 10 #pragma once 11 12 #include "base/basictypes.h" 13 #include "base/time.h" 14 15 class GURL; 16 17 namespace net { 18 19 class SocketStreamMetrics { 20 public: 21 enum ProtocolType { 22 PROTOCOL_UNKNOWN, 23 PROTOCOL_WEBSOCKET, 24 PROTOCOL_WEBSOCKET_SECURE, 25 NUM_PROTOCOL_TYPES, 26 }; 27 28 enum ConnectionType { 29 CONNECTION_NONE, 30 ALL_CONNECTIONS, 31 TUNNEL_CONNECTION, 32 SOCKS_CONNECTION, 33 SSL_CONNECTION, 34 NUM_CONNECTION_TYPES, 35 }; 36 37 explicit SocketStreamMetrics(const GURL& url); 38 ~SocketStreamMetrics(); 39 40 void OnWaitConnection(); 41 void OnStartConnection(); 42 void OnTunnelProxy(); 43 void OnSOCKSProxy(); 44 void OnSSLConnection(); 45 void OnConnected(); 46 void OnRead(int len); 47 void OnWrite(int len); 48 void OnClose(); 49 50 private: 51 void CountProtocolType(ProtocolType protocol_type); 52 void CountConnectionType(ConnectionType connection_type); 53 54 base::TimeTicks wait_start_time_; 55 base::TimeTicks connect_start_time_; 56 base::TimeTicks connect_establish_time_; 57 int received_bytes_; 58 int received_counts_; 59 int sent_bytes_; 60 int sent_counts_; 61 62 DISALLOW_COPY_AND_ASSIGN(SocketStreamMetrics); 63 }; 64 65 } // namespace net 66 67 #endif // NET_SOCKET_STREAM_SOCKET_STREAM_METRICS_H_ 68