1 // Copyright (c) 2009 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 11 #include <string> 12 13 #include "base/basictypes.h" 14 #include "base/time.h" 15 16 class GURL; 17 18 namespace net { 19 20 class SocketStreamMetrics { 21 public: 22 explicit SocketStreamMetrics(const GURL& url); 23 ~SocketStreamMetrics(); 24 25 void OnWaitConnection(); 26 void OnStartConnection(); 27 void OnTunnelProxy(); 28 void OnSOCKSProxy(); 29 void OnSSLConnection(); 30 void OnConnected(); 31 void OnRead(int len); 32 void OnWrite(int len); 33 void OnClose(); 34 35 enum ProtocolType { 36 PROTOCOL_UNKNOWN, 37 PROTOCOL_WEBSOCKET, 38 PROTOCOL_WEBSOCKET_SECURE, 39 NUM_PROTOCOL_TYPES, 40 }; 41 enum ConnectionType { 42 CONNECTION_NONE, 43 ALL_CONNECTIONS, 44 TUNNEL_CONNECTION, 45 SOCKS_CONNECTION, 46 SSL_CONNECTION, 47 NUM_CONNECTION_TYPES, 48 }; 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