Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / net / socket_stream / socket_stream_metrics.cc
blobe026887753315e8a792befbb782ac2178da5524e
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"
7 #include <string.h>
9 #include "base/metrics/histogram.h"
10 #include "base/time/time.h"
11 #include "url/gurl.h"
13 namespace net {
15 SocketStreamMetrics::SocketStreamMetrics(const GURL& url)
16 : received_bytes_(0),
17 received_counts_(0),
18 sent_bytes_(0),
19 sent_counts_(0) {
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;
52 ++received_counts_;
55 void SocketStreamMetrics::OnWrite(int len) {
56 sent_bytes_ += len;
57 ++sent_counts_;
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",
66 received_bytes_);
67 UMA_HISTOGRAM_COUNTS("Net.SocketStream.ReceivedCounts",
68 received_counts_);
69 UMA_HISTOGRAM_COUNTS("Net.SocketStream.SentBytes",
70 sent_bytes_);
71 UMA_HISTOGRAM_COUNTS("Net.SocketStream.SentCounts",
72 sent_counts_);
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);
86 } // namespace net