Index: net/http/http_basic_stream.cc |
=================================================================== |
--- net/http/http_basic_stream.cc (revision 88789) |
+++ net/http/http_basic_stream.cc (working copy) |
@@ -4,6 +4,7 @@ |
#include "net/http/http_basic_stream.h" |
+#include "base/metrics/histogram.h" |
#include "base/stringprintf.h" |
#include "net/base/io_buffer.h" |
#include "net/base/net_errors.h" |
@@ -13,6 +14,12 @@ |
#include "net/http/http_util.h" |
#include "net/socket/client_socket_handle.h" |
+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.
|
+ |
+namespace { |
+int g_socket_reuse_policy = -1; |
+} |
+ |
namespace net { |
HttpBasicStream::HttpBasicStream(ClientSocketHandle* connection, |
@@ -34,6 +41,7 @@ |
request_info_ = request_info; |
parser_.reset(new HttpStreamParser(connection_.get(), request_info, |
read_buf_, net_log)); |
+ bytes_read_offset_ = connection_->socket()->NumBytesRead(); |
return OK; |
} |
@@ -50,6 +58,7 @@ |
request_line_ = base::StringPrintf("%s %s HTTP/1.1\r\n", |
request_info_->method.c_str(), |
path.c_str()); |
+ response_ = response; |
return parser_->SendRequest(request_line_, headers, request_body, response, |
callback); |
} |
@@ -119,4 +128,45 @@ |
return false; |
} |
+void HttpBasicStream::LogNumRttVsBytesMetrics() const { |
+ DCHECK_GE(g_socket_reuse_policy, 0); |
+ DCHECK_LE(g_socket_reuse_policy, 3); |
+ |
+ int64 total_bytes_read = connection_->socket()->NumBytesRead(); |
+ int64 bytes_received = total_bytes_read - bytes_read_offset_; |
+ int64 num_kb = bytes_received / 1024; |
+ double rtt = connection_->socket()->GetConnectTimeMicros(); |
+ rtt /= 1000.0; |
+ |
+ if (num_kb < 1024 && rtt > 0) { // Ignore responses > 1MB |
+ base::TimeDelta duration = base::Time::Now() - |
+ response_->request_time; |
+ double num_rtt = static_cast<double>(duration.InMilliseconds()) / rtt; |
+ int64 num_rtt_scaled = (4 * num_rtt); |
+ |
+ 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.
|
+ "warm_socket", "manual" }; |
+ int bucket = (num_kb / 5) * 5; |
+ const std::string histogram(StringPrintf("Net.Num_RTT_vs_KB_%s_%dKB", |
+ groups[g_socket_reuse_policy], |
+ bucket)); |
+ Histogram* counter = Histogram::FactoryGet( |
+ histogram, 0, 1000, 2, Histogram::kUmaTargetedHistogramFlag); |
+ DCHECK_EQ(histogram, counter->histogram_name()); |
+ counter->Add(num_rtt_scaled); |
+ |
+ 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
|
+ << "\nrtt = " << rtt << "\tnum_rtt = " << num_rtt |
+ << "\tnum_kb = " << num_kb |
+ << "\ttotal bytes = " << total_bytes_read |
+ << "\thistogram = " << histogram; |
+ } |
+} |
+ |
+// static |
+// NOTE: 'policy' should be a valid ClientSocketReusePolicy enum value. |
+void HttpBasicStream::SetSocketReusePolicy(int policy) { |
+ g_socket_reuse_policy = policy; |
+} |
+ |
} // namespace net |