Chromium Code Reviews| Index: net/http/bidirectional_stream.cc |
| diff --git a/net/http/bidirectional_stream.cc b/net/http/bidirectional_stream.cc |
| index a3f74d2bf1118f8bfbe65bd04efa01e8ab4ed0a7..3393ff32997ce7e949608e2580ac9f5c0390f2a5 100644 |
| --- a/net/http/bidirectional_stream.cc |
| +++ b/net/http/bidirectional_stream.cc |
| @@ -11,7 +11,10 @@ |
| #include "base/location.h" |
| #include "base/logging.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/metrics/histogram_macros.h" |
| #include "base/threading/thread_task_runner_handle.h" |
| +#include "base/time/default_tick_clock.h" |
| +#include "base/time/tick_clock.h" |
| #include "base/time/time.h" |
| #include "base/timer/timer.h" |
| #include "base/values.h" |
| @@ -86,6 +89,7 @@ BidirectionalStream::BidirectionalStream( |
| request_headers_sent_(false), |
| delegate_(delegate), |
| timer_(std::move(timer)), |
| + tick_clock_(new base::DefaultTickClock()), |
| weak_factory_(this) { |
| DCHECK(delegate_); |
| DCHECK(request_info_); |
| @@ -126,6 +130,7 @@ BidirectionalStream::BidirectionalStream( |
| } |
| BidirectionalStream::~BidirectionalStream() { |
| + UpdateHistograms(); |
| Cancel(); |
| if (net_log_.IsCapturing()) { |
| net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_ALIVE); |
| @@ -244,6 +249,8 @@ void BidirectionalStream::OnHeadersReceived( |
| net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_HEADERS, |
| base::Bind(&NetLogHeadersCallback, &response_headers)); |
| } |
| + recv_first_byte_time_ = tick_clock_->NowTicks(); |
| + recv_last_byte_time_ = recv_first_byte_time_; |
| session_->http_stream_factory()->ProcessAlternativeServices( |
| session_, response_info.headers.get(), |
| url::SchemeHostPort(request_info_->url)); |
| @@ -258,6 +265,7 @@ void BidirectionalStream::OnDataRead(int bytes_read) { |
| NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, bytes_read, |
| read_buffer_->data()); |
| } |
| + recv_last_byte_time_ = tick_clock_->NowTicks(); |
| read_buffer_ = nullptr; |
| delegate_->OnDataRead(bytes_read); |
| } |
| @@ -292,6 +300,7 @@ void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) { |
| net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_TRAILERS, |
| base::Bind(&NetLogHeadersCallback, &trailers)); |
| } |
| + recv_last_byte_time_ = tick_clock_->NowTicks(); |
| delegate_->OnTrailersReceived(trailers); |
| } |
| @@ -315,6 +324,7 @@ void BidirectionalStream::OnBidirectionalStreamImplReady( |
| BidirectionalStreamImpl* stream) { |
| DCHECK(!stream_impl_); |
| + start_time_ = tick_clock_->NowTicks(); |
| stream_request_.reset(); |
| stream_impl_.reset(stream); |
| stream_impl_->Start(request_info_.get(), net_log_, |
| @@ -381,4 +391,32 @@ void BidirectionalStream::NotifyFailed(int error) { |
| delegate_->OnFailed(error); |
| } |
| +void BidirectionalStream::UpdateHistograms() { |
| + // If the request failed before response is started, treat the metrics as |
| + // bogus and skip logging. |
| + if (start_time_.is_null() || recv_first_byte_time_.is_null() || |
| + recv_last_byte_time_.is_null()) { |
| + return; |
| + } |
| + if (GetProtocol() == kProtoHTTP2) { |
| + UMA_HISTOGRAM_TIMES("BidirectionalStream.HTTP2.TimeToResponseStart", |
|
Ilya Sherman
2016/08/08 22:26:37
Would it be appropriate to prefix these histogram
xunjieli
2016/08/09 20:31:28
Done.
|
| + recv_first_byte_time_ - start_time_); |
| + UMA_HISTOGRAM_TIMES("BidirectionalStream.HTTP2.TimeToResponseEnd", |
| + recv_last_byte_time_ - start_time_); |
| + UMA_HISTOGRAM_COUNTS("BidirectionalStream.HTTP2.ReceivedBytes", |
|
Ilya Sherman
2016/08/08 22:26:37
Are the boundaries set by UMA_HISTOGRAM_COUNTS rea
xunjieli
2016/08/09 20:31:28
Yes, elsewhere in net/, the UMA for bytes is logge
|
| + stream_impl_->GetTotalReceivedBytes()); |
| + UMA_HISTOGRAM_COUNTS("BidirectionalStream.HTTP2.SentBytes", |
| + stream_impl_->GetTotalSentBytes()); |
| + } else if (GetProtocol() == kProtoQUIC1SPDY3) { |
| + UMA_HISTOGRAM_TIMES("BidirectionalStream.QUIC.TimeToResponseStart", |
| + recv_first_byte_time_ - start_time_); |
| + UMA_HISTOGRAM_TIMES("BidirectionalStream.QUIC.TimeToResponseEnd", |
| + recv_last_byte_time_ - start_time_); |
| + UMA_HISTOGRAM_COUNTS("BidirectionalStream.QUIC.ReceivedBytes", |
| + stream_impl_->GetTotalReceivedBytes()); |
| + UMA_HISTOGRAM_COUNTS("BidirectionalStream.QUIC.SentBytes", |
| + stream_impl_->GetTotalSentBytes()); |
| + } |
| +} |
| + |
| } // namespace net |