OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/http/http_basic_stream.h" | 5 #include "net/http/http_basic_stream.h" |
6 | 6 |
7 #include "base/metrics/histogram.h" | |
7 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
8 #include "net/base/io_buffer.h" | 9 #include "net/base/io_buffer.h" |
9 #include "net/base/net_errors.h" | 10 #include "net/base/net_errors.h" |
10 #include "net/http/http_request_headers.h" | 11 #include "net/http/http_request_headers.h" |
11 #include "net/http/http_request_info.h" | 12 #include "net/http/http_request_info.h" |
12 #include "net/http/http_stream_parser.h" | 13 #include "net/http/http_stream_parser.h" |
13 #include "net/http/http_util.h" | 14 #include "net/http/http_util.h" |
14 #include "net/socket/client_socket_handle.h" | 15 #include "net/socket/client_socket_handle.h" |
15 | 16 |
17 using base::Histogram; | |
willchan no longer on Chromium
2011/06/13 15:06:07
Chromium code does not often use using declaration
Gagan
2011/06/13 16:45:58
Done.
| |
18 | |
19 namespace { | |
20 int g_socket_reuse_policy = -1; | |
21 } | |
22 | |
16 namespace net { | 23 namespace net { |
17 | 24 |
18 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, | 25 HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, |
19 HttpStreamParser* parser, | 26 HttpStreamParser* parser, |
20 bool using_proxy) | 27 bool using_proxy) |
21 : read_buf_(new GrowableIOBuffer()), | 28 : read_buf_(new GrowableIOBuffer()), |
22 parser_(parser), | 29 parser_(parser), |
23 connection_(connection), | 30 connection_(connection), |
24 using_proxy_(using_proxy), | 31 using_proxy_(using_proxy), |
25 request_info_(NULL) { | 32 request_info_(NULL) { |
26 } | 33 } |
27 | 34 |
28 HttpBasicStream::~HttpBasicStream() {} | 35 HttpBasicStream::~HttpBasicStream() {} |
29 | 36 |
30 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, | 37 int HttpBasicStream::InitializeStream(const HttpRequestInfo* request_info, |
31 const BoundNetLog& net_log, | 38 const BoundNetLog& net_log, |
32 CompletionCallback* callback) { | 39 CompletionCallback* callback) { |
33 DCHECK(!parser_.get()); | 40 DCHECK(!parser_.get()); |
34 request_info_ = request_info; | 41 request_info_ = request_info; |
35 parser_.reset(new HttpStreamParser(connection_.get(), request_info, | 42 parser_.reset(new HttpStreamParser(connection_.get(), request_info, |
36 read_buf_, net_log)); | 43 read_buf_, net_log)); |
44 bytes_read_offset_ = connection_->socket()->NumBytesRead(); | |
37 return OK; | 45 return OK; |
38 } | 46 } |
39 | 47 |
40 | 48 |
41 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, | 49 int HttpBasicStream::SendRequest(const HttpRequestHeaders& headers, |
42 UploadDataStream* request_body, | 50 UploadDataStream* request_body, |
43 HttpResponseInfo* response, | 51 HttpResponseInfo* response, |
44 CompletionCallback* callback) { | 52 CompletionCallback* callback) { |
45 DCHECK(parser_.get()); | 53 DCHECK(parser_.get()); |
46 DCHECK(request_info_); | 54 DCHECK(request_info_); |
47 const std::string path = using_proxy_ ? | 55 const std::string path = using_proxy_ ? |
48 HttpUtil::SpecForRequest(request_info_->url) : | 56 HttpUtil::SpecForRequest(request_info_->url) : |
49 HttpUtil::PathForRequest(request_info_->url); | 57 HttpUtil::PathForRequest(request_info_->url); |
50 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", | 58 request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", |
51 request_info_->method.c_str(), | 59 request_info_->method.c_str(), |
52 path.c_str()); | 60 path.c_str()); |
61 response_ = response; | |
53 return parser_->SendRequest(request_line_, headers, request_body, response, | 62 return parser_->SendRequest(request_line_, headers, request_body, response, |
54 callback); | 63 callback); |
55 } | 64 } |
56 | 65 |
57 uint64 HttpBasicStream::GetUploadProgress() const { | 66 uint64 HttpBasicStream::GetUploadProgress() const { |
58 return parser_->GetUploadProgress(); | 67 return parser_->GetUploadProgress(); |
59 } | 68 } |
60 | 69 |
61 int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) { | 70 int HttpBasicStream::ReadResponseHeaders(CompletionCallback* callback) { |
62 return parser_->ReadResponseHeaders(callback); | 71 return parser_->ReadResponseHeaders(callback); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
112 | 121 |
113 void HttpBasicStream::GetSSLCertRequestInfo( | 122 void HttpBasicStream::GetSSLCertRequestInfo( |
114 SSLCertRequestInfo* cert_request_info) { | 123 SSLCertRequestInfo* cert_request_info) { |
115 parser_->GetSSLCertRequestInfo(cert_request_info); | 124 parser_->GetSSLCertRequestInfo(cert_request_info); |
116 } | 125 } |
117 | 126 |
118 bool HttpBasicStream::IsSpdyHttpStream() const { | 127 bool HttpBasicStream::IsSpdyHttpStream() const { |
119 return false; | 128 return false; |
120 } | 129 } |
121 | 130 |
131 void HttpBasicStream::LogNumRttVsBytesMetrics() const { | |
132 DCHECK_GE(g_socket_reuse_policy, 0); | |
133 DCHECK_LE(g_socket_reuse_policy, 3); | |
134 | |
135 int64 total_bytes_read = connection_->socket()->NumBytesRead(); | |
136 int64 bytes_received = total_bytes_read - bytes_read_offset_; | |
137 int64 num_kb = bytes_received / 1024; | |
138 double rtt = connection_->socket()->GetConnectTimeMicros(); | |
139 rtt /= 1000.0; | |
140 | |
141 if (num_kb < 1024 && rtt > 0) { // Ignore responses > 1MB | |
142 base::TimeDelta duration = base::Time::Now() - | |
143 response_->request_time; | |
144 double num_rtt = static_cast<double>(duration.InMilliseconds()) / rtt; | |
145 int64 num_rtt_scaled = (4 * num_rtt); | |
146 | |
147 const char* groups[] = { "last_accessed_socket", "warmest_socket", | |
willchan no longer on Chromium
2011/06/13 15:06:07
static const char* const kGroups[] = ...
Gagan
2011/06/13 16:45:58
Done.
| |
148 "warm_socket", "manual" }; | |
149 int bucket = (num_kb / 5) * 5; | |
150 const std::string histogram(StringPrintf("Net.Num_RTT_vs_KB_%s_%dKB", | |
151 groups[g_socket_reuse_policy], | |
152 bucket)); | |
153 Histogram* counter = Histogram::FactoryGet( | |
154 histogram, 0, 1000, 2, Histogram::kUmaTargetedHistogramFlag); | |
155 DCHECK_EQ(histogram, counter->histogram_name()); | |
156 counter->Add(num_rtt_scaled); | |
157 | |
158 LOG(ERROR) << request_line_ | |
willchan no longer on Chromium
2011/06/13 15:06:07
You're close to done now, please kill off all your
Gagan
2011/06/14 18:25:02
This log is very useful as it logs most of the int
| |
159 << "\nrtt = " << rtt << "\tnum_rtt = " << num_rtt | |
160 << "\tnum_kb = " << num_kb | |
161 << "\ttotal bytes = " << total_bytes_read | |
162 << "\thistogram = " << histogram; | |
163 } | |
164 } | |
165 | |
166 // static | |
167 // NOTE: 'policy' should be a valid ClientSocketReusePolicy enum value. | |
168 void HttpBasicStream::SetSocketReusePolicy(int policy) { | |
169 g_socket_reuse_policy = policy; | |
170 } | |
171 | |
122 } // namespace net | 172 } // namespace net |
OLD | NEW |