Skip to content

Commit

Permalink
Add a new Net.AlternateProtocolUsage for tracking usage of Alternate-…
Browse files Browse the repository at this point in the history
…Protocol.

BUG=

Review URL: https://codereview.chromium.org/232193002

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@263298 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
rch@chromium.org committed Apr 11, 2014
1 parent 5ff0f8c commit db9bfea
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 5 deletions.
6 changes: 6 additions & 0 deletions net/http/http_server_properties.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "net/http/http_server_properties.h"

#include "base/logging.h"
#include "base/metrics/histogram.h"
#include "base/strings/stringprintf.h"

namespace net {
Expand All @@ -31,6 +32,11 @@ COMPILE_ASSERT(

} // namespace

void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage) {
UMA_HISTOGRAM_ENUMERATION("Net.AlternateProtocolUsage", usage,
ALTERNATE_PROTOCOL_USAGE_MAX);
}

bool IsAlternateProtocolValid(AlternateProtocol protocol) {
return protocol >= ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION &&
protocol <= ALTERNATE_PROTOCOL_MAXIMUM_VALID_VERSION;
Expand Down
20 changes: 20 additions & 0 deletions net/http/http_server_properties.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,26 @@

namespace net {

enum AlternateProtocolUsage {
// Alternate Protocol was used without racing a normal connection.
ALTERNATE_PROTOCOL_USAGE_NO_RACE = 0,
// Alternate Protocol was used by winning a race with a normal connection.
ALTERNATE_PROTOCOL_USAGE_WON_RACE = 1,
// Alternate Protocol was not used by losing a race with a normal connection.
ALTERNATE_PROTOCOL_USAGE_LOST_RACE = 2,
// Alternate Protocol was not used because no Alternate-Protocol information
// was available when the request was issued, but an Alternate-Protocol header
// was present in the response.
ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING = 3,
// Alternate Protocol was not used because it was marked broken.
ALTERNATE_PROTOCOL_USAGE_BROKEN = 4,
// Maximum value for the enum.
ALTERNATE_PROTOCOL_USAGE_MAX,
};

// Log a histogram to reflect |usage|.
NET_EXPORT void HistogramAlternateProtocolUsage(AlternateProtocolUsage usage);

enum AlternateProtocol {
DEPRECATED_NPN_SPDY_2 = 0,
ALTERNATE_PROTOCOL_MINIMUM_VALID_VERSION = DEPRECATED_NPN_SPDY_2,
Expand Down
5 changes: 5 additions & 0 deletions net/http/http_server_properties_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ void HttpServerPropertiesImpl::SetAlternateProtocol(
<< ", Protocol: " << alternate_protocol
<< "].";
}
} else {
// TODO(rch): Consider the case where multiple requests are started
// before the first completes. In this case, only one of the jobs
// would reach this code, whereas all of them should should have.
HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING);
}

alternate_protocol_map_.Put(server, alternate);
Expand Down
4 changes: 3 additions & 1 deletion net/http/http_stream_factory_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,10 @@ PortAlternateProtocolPair HttpStreamFactoryImpl::GetAlternateProtocolRequestFor(

PortAlternateProtocolPair alternate =
http_server_properties.GetAlternateProtocol(origin);
if (alternate.protocol == ALTERNATE_PROTOCOL_BROKEN)
if (alternate.protocol == ALTERNATE_PROTOCOL_BROKEN) {
HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_BROKEN);
return kNoAlternateProtocol;
}

if (!IsAlternateProtocolValid(alternate.protocol)) {
NOTREACHED();
Expand Down
20 changes: 19 additions & 1 deletion net/http/http_stream_factory_impl_job.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ HttpStreamFactoryImpl::Job::Job(HttpStreamFactoryImpl* stream_factory,
using_spdy_(false),
using_quic_(false),
quic_request_(session_->quic_stream_factory()),
using_existing_quic_session_(false),
force_spdy_always_(HttpStreamFactory::force_spdy_always()),
force_spdy_over_ssl_(HttpStreamFactory::force_spdy_over_ssl()),
spdy_certificate_error_(OK),
Expand Down Expand Up @@ -750,7 +751,9 @@ int HttpStreamFactoryImpl::Job::DoInitConnection() {
int rv = quic_request_.Request(
destination, secure_quic, request_info_.privacy_mode,
request_info_.method, net_log_, io_callback_);
if (rv != OK) {
if (rv == OK) {
using_existing_quic_session_ = true;
} else {
// OK, there's no available QUIC session. Let |waiting_job_| resume
// if it's paused.
if (waiting_job_) {
Expand Down Expand Up @@ -1447,6 +1450,21 @@ bool HttpStreamFactoryImpl::Job::IsOrphaned() const {
return !IsPreconnecting() && !request_;
}

void HttpStreamFactoryImpl::Job::ReportJobSuccededForRequest() {
if (using_existing_quic_session_) {
// If an existing session was used, then no TCP connection was
// started.
HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_NO_RACE);
} else if (original_url_) {
// This job was the alternate protocol job, and hence won the race.
HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_WON_RACE);
} else {
// This job was the normal job, and hence the alternate protocol job lost
// the race.
HistogramAlternateProtocolUsage(ALTERNATE_PROTOCOL_USAGE_LOST_RACE);
}
}

bool HttpStreamFactoryImpl::Job::IsRequestEligibleForPipelining() {
if (IsPreconnecting() || !request_) {
return false;
Expand Down
7 changes: 7 additions & 0 deletions net/http/http_stream_factory_impl_job.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ class HttpStreamFactoryImpl::Job {
// Indicates whether or not this Job has been orphaned by a Request.
bool IsOrphaned() const;

// Called to indicate that this job succeeded, and some other jobs
// will be orphaned.
void ReportJobSuccededForRequest();

private:
enum State {
STATE_START,
Expand Down Expand Up @@ -277,6 +281,9 @@ class HttpStreamFactoryImpl::Job {
bool using_quic_;
QuicStreamRequest quic_request_;

// True if this job used an existing QUIC session.
bool using_existing_quic_session_;

// Force spdy for all connections.
bool force_spdy_always_;

Expand Down
10 changes: 7 additions & 3 deletions net/http/http_stream_factory_impl_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -380,13 +380,17 @@ void HttpStreamFactoryImpl::Request::OnJobSucceeded(Job* job) {
// they complete? Or do we want to prevent connecting a new SpdySession if
// we've already got one available for a different hostname where the ip
// address matches up?
} else if (!bound_job_.get()) {
return;
}
if (!bound_job_.get()) {
if (jobs_.size() > 1)
job->ReportJobSuccededForRequest();
// We may have other jobs in |jobs_|. For example, if we start multiple jobs
// for Alternate-Protocol.
OrphanJobsExcept(job);
} else {
DCHECK(jobs_.empty());
return;
}
DCHECK(jobs_.empty());
}

} // namespace net
16 changes: 16 additions & 0 deletions tools/metrics/histograms/histograms.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10466,6 +10466,14 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<summary>The scheme of the URL for each main-frame navigation.</summary>
</histogram>

<histogram name="Net.AlternateProtocolUsage" enum="AlternateProtocolUsage">
<owner>rch@chromium.org</owner>
<summary>
Breakdown of how requests which could potentially make use of an alternate
protocol use or don't use the protocol.
</summary>
</histogram>

<histogram name="Net.AsyncResourceHandler_PendingDataCount">
<owner>Please list the metric's owners. Add more owner tags as needed.</owner>
<summary>
Expand Down Expand Up @@ -30097,6 +30105,14 @@ Therefore, the affected-histogram name has to have at least one dot in it.
<int value="4" label="Snapped"/>
</enum>

<enum name="AlternateProtocolUsage" type="int">
<int value="0" label="ALTERNATE_PROTOCOL_USAGE_NO_RACE"/>
<int value="1" label="ALTERNATE_PROTOCOL_USAGE_WON_RACE"/>
<int value="2" label="ALTERNATE_PROTOCOL_USAGE_LOST_RACE"/>
<int value="3" label="ALTERNATE_PROTOCOL_USAGE_MAPPING_MISSING"/>
<int value="4" label="ALTERNATE_PROTOCOL_USAGE_BROKEN"/>
</enum>

<enum name="AndroidActivityId" type="int">
<int value="1" label="Unknown"/>
<int value="2" label="Main"/>
Expand Down

0 comments on commit db9bfea

Please sign in to comment.