Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1629)

Unified Diff: net/http/bidirectional_stream.cc

Issue 2222113003: Add UMA to net::BidirectionalStream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: address comments Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: net/http/bidirectional_stream.cc
diff --git a/net/http/bidirectional_stream.cc b/net/http/bidirectional_stream.cc
index a3f74d2bf1118f8bfbe65bd04efa01e8ab4ed0a7..1319af9a96edaaa7e9590ac8f76c36a3f53a170a 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);
@@ -145,6 +150,7 @@ int BidirectionalStream::ReadData(IOBuffer* buf, int buf_len) {
int rv = stream_impl_->ReadData(buf, buf_len);
if (rv > 0) {
+ read_end_time_ = tick_clock_->NowTicks();
mef 2016/08/10 01:05:20 Can we use TimeTicks::Now() here and elsewhere? Th
xunjieli 2016/08/11 12:50:40 Done.
net_log_.AddByteTransferEvent(
NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, rv, buf->data());
} else if (rv == ERR_IO_PENDING) {
@@ -229,6 +235,8 @@ void BidirectionalStream::OnStreamReady(bool request_headers_sent) {
NetLog::TYPE_BIDIRECTIONAL_STREAM_READY,
NetLog::BoolCallback("request_headers_sent", request_headers_sent));
}
+ send_start_time_ = tick_clock_->NowTicks();
+ send_end_time_ = send_start_time_;
delegate_->OnStreamReady(request_headers_sent);
}
@@ -244,6 +252,8 @@ void BidirectionalStream::OnHeadersReceived(
net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_HEADERS,
base::Bind(&NetLogHeadersCallback, &response_headers));
}
+ read_start_time_ = tick_clock_->NowTicks();
+ read_end_time_ = read_start_time_;
session_->http_stream_factory()->ProcessAlternativeServices(
session_, response_info.headers.get(),
url::SchemeHostPort(request_info_->url));
@@ -258,6 +268,7 @@ void BidirectionalStream::OnDataRead(int bytes_read) {
NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_RECEIVED, bytes_read,
read_buffer_->data());
}
+ read_end_time_ = tick_clock_->NowTicks();
read_buffer_ = nullptr;
delegate_->OnDataRead(bytes_read);
}
@@ -282,6 +293,7 @@ void BidirectionalStream::OnDataSent() {
net_log_.EndEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_BYTES_SENT_COALESCED);
}
}
+ send_end_time_ = tick_clock_->NowTicks();
write_buffer_list_.clear();
write_buffer_len_list_.clear();
delegate_->OnDataSent();
@@ -292,6 +304,7 @@ void BidirectionalStream::OnTrailersReceived(const SpdyHeaderBlock& trailers) {
net_log_.AddEvent(NetLog::TYPE_BIDIRECTIONAL_STREAM_RECV_TRAILERS,
base::Bind(&NetLogHeadersCallback, &trailers));
}
+ read_end_time_ = tick_clock_->NowTicks();
delegate_->OnTrailersReceived(trailers);
}
@@ -315,6 +328,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 +395,41 @@ 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() || read_start_time_.is_null() ||
+ read_end_time_.is_null() || send_start_time_.is_null() ||
+ send_end_time_.is_null()) {
+ return;
+ }
+ if (GetProtocol() == kProtoHTTP2) {
+ UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.HTTP2.TimeToReadStart",
mef 2016/08/10 01:05:20 Should these names match those in histograms.xml?
xunjieli 2016/08/11 12:50:40 I don't understand. They do match right? I added t
mef 2016/08/11 15:42:19 I would've thought that suffix goes at the end of
Ilya Sherman 2016/08/11 18:48:46 ordering=prefix should indeed put the "suffix" in
xunjieli 2016/08/11 19:37:09 I talked to csharrison@ who added a similar histog
+ read_start_time_ - start_time_);
+ UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.HTTP2.TimeToReadEnd",
+ read_end_time_ - start_time_);
+ UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.HTTP2.TimeToSendStart",
+ send_start_time_ - start_time_);
+ UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.HTTP2.TimeToSendEnd",
+ send_end_time_ - start_time_);
+ UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.HTTP2.ReceivedBytes",
+ stream_impl_->GetTotalReceivedBytes());
+ UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.HTTP2.SentBytes",
+ stream_impl_->GetTotalSentBytes());
+ } else if (GetProtocol() == kProtoQUIC1SPDY3) {
+ UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.QUIC.TimeToReadStart",
+ read_start_time_ - start_time_);
+ UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.QUIC.TimeToReadEnd",
+ read_end_time_ - start_time_);
+ UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.QUIC.TimeToSendStart",
+ send_start_time_ - start_time_);
+ UMA_HISTOGRAM_TIMES("Net.BidirectionalStream.QUIC.TimeToSendEnd",
+ send_end_time_ - start_time_);
+ UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.QUIC.ReceivedBytes",
+ stream_impl_->GetTotalReceivedBytes());
+ UMA_HISTOGRAM_COUNTS("Net.BidirectionalStream.QUIC.SentBytes",
+ stream_impl_->GetTotalSentBytes());
+ }
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698