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.
5 #include "net/socket_stream/socket_stream_metrics.h"
9 #include "base/metrics/histogram.h"
10 #include "base/time/time.h"
15 SocketStreamMetrics::SocketStreamMetrics(const GURL
& url
)
20 ProtocolType protocol_type
= PROTOCOL_UNKNOWN
;
21 if (url
.SchemeIs("ws"))
22 protocol_type
= PROTOCOL_WEBSOCKET
;
23 else if (url
.SchemeIs("wss"))
24 protocol_type
= PROTOCOL_WEBSOCKET_SECURE
;
26 UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.ProtocolType",
27 protocol_type
, NUM_PROTOCOL_TYPES
);
30 SocketStreamMetrics::~SocketStreamMetrics() {}
32 void SocketStreamMetrics::OnWaitConnection() {
33 wait_start_time_
= base::TimeTicks::Now();
36 void SocketStreamMetrics::OnStartConnection() {
37 connect_start_time_
= base::TimeTicks::Now();
38 if (!wait_start_time_
.is_null())
39 UMA_HISTOGRAM_TIMES("Net.SocketStream.ConnectionLatency",
40 connect_start_time_
- wait_start_time_
);
41 OnCountConnectionType(ALL_CONNECTIONS
);
44 void SocketStreamMetrics::OnConnected() {
45 connect_establish_time_
= base::TimeTicks::Now();
46 UMA_HISTOGRAM_TIMES("Net.SocketStream.ConnectionEstablish",
47 connect_establish_time_
- connect_start_time_
);
50 void SocketStreamMetrics::OnRead(int len
) {
51 received_bytes_
+= len
;
55 void SocketStreamMetrics::OnWrite(int len
) {
60 void SocketStreamMetrics::OnClose() {
61 base::TimeTicks closed_time
= base::TimeTicks::Now();
62 if (!connect_establish_time_
.is_null()) {
63 UMA_HISTOGRAM_LONG_TIMES("Net.SocketStream.Duration",
64 closed_time
- connect_establish_time_
);
65 UMA_HISTOGRAM_COUNTS("Net.SocketStream.ReceivedBytes",
67 UMA_HISTOGRAM_COUNTS("Net.SocketStream.ReceivedCounts",
69 UMA_HISTOGRAM_COUNTS("Net.SocketStream.SentBytes",
71 UMA_HISTOGRAM_COUNTS("Net.SocketStream.SentCounts",
76 void SocketStreamMetrics::OnCountConnectionType(ConnectionType type
) {
77 UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.ConnectionType", type
,
78 NUM_CONNECTION_TYPES
);
81 void SocketStreamMetrics::OnCountWireProtocolType(WireProtocolType type
) {
82 UMA_HISTOGRAM_ENUMERATION("Net.SocketStream.WireProtocolType", type
,
83 NUM_WIRE_PROTOCOL_TYPES
);