From d72702ebefa7b79045788a72114e812183a72e86 Mon Sep 17 00:00:00 2001 From: Patrick McManus Date: Sat, 27 Oct 2012 15:24:19 -0400 Subject: [PATCH] bug 805457 telemetry for proxy and websocket connections r=jduell --- netwerk/protocol/http/nsHttpConnectionMgr.cpp | 15 ++++++ netwerk/protocol/http/nsHttpConnectionMgr.h | 1 + .../protocol/websocket/WebSocketChannel.cpp | 47 ++++++++++++++++--- netwerk/protocol/websocket/WebSocketChannel.h | 3 +- toolkit/components/telemetry/Histograms.json | 10 ++++ 5 files changed, 69 insertions(+), 7 deletions(-) diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.cpp b/netwerk/protocol/http/nsHttpConnectionMgr.cpp index 0209363df4a..bb13217a18c 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.cpp +++ b/netwerk/protocol/http/nsHttpConnectionMgr.cpp @@ -1670,6 +1670,19 @@ nsHttpConnectionMgr::BuildPipeline(nsConnectionEntry *ent, return NS_OK; } +void +nsHttpConnectionMgr::ReportProxyTelemetry(nsConnectionEntry *ent) +{ + enum { PROXY_NONE = 1, PROXY_HTTP = 2, PROXY_SOCKS = 3 }; + + if (!ent->mConnInfo->UsingProxy()) + Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_NONE); + else if (ent->mConnInfo->UsingHttpProxy()) + Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_HTTP); + else + Telemetry::Accumulate(Telemetry::HTTP_PROXY_TYPE, PROXY_SOCKS); +} + nsresult nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans) { @@ -1703,6 +1716,8 @@ nsHttpConnectionMgr::ProcessNewTransaction(nsHttpTransaction *trans) ent = preferredEntry; } + ReportProxyTelemetry(ent); + // If we are doing a force reload then close out any existing conns // to this host so that changes in DNS, LBs, etc.. are reflected if (trans->Caps() & NS_HTTP_CLEAR_KEEPALIVES) diff --git a/netwerk/protocol/http/nsHttpConnectionMgr.h b/netwerk/protocol/http/nsHttpConnectionMgr.h index 516b0640c98..3d1ad22c133 100644 --- a/netwerk/protocol/http/nsHttpConnectionMgr.h +++ b/netwerk/protocol/http/nsHttpConnectionMgr.h @@ -481,6 +481,7 @@ private: nsresult ProcessNewTransaction(nsHttpTransaction *); nsresult EnsureSocketThreadTarget(); void ClosePersistentConnections(nsConnectionEntry *ent); + void ReportProxyTelemetry(nsConnectionEntry *ent); nsresult CreateTransport(nsConnectionEntry *, nsAHttpTransaction *, uint8_t, bool); void AddActiveConn(nsHttpConnection *, nsConnectionEntry *); diff --git a/netwerk/protocol/websocket/WebSocketChannel.cpp b/netwerk/protocol/websocket/WebSocketChannel.cpp index 466d25deaa8..191d3e5216a 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.cpp +++ b/netwerk/protocol/websocket/WebSocketChannel.cpp @@ -20,6 +20,8 @@ #include "nsIStreamConverterService.h" #include "nsIIOService2.h" #include "nsIProtocolProxyService.h" +#include "nsIProxyInfo.h" +#include "nsIProxiedChannel.h" #include "nsAutoPtr.h" #include "nsStandardURL.h" @@ -35,6 +37,7 @@ #include "nsNetUtil.h" #include "mozilla/Attributes.h" #include "TimeStamp.h" +#include "mozilla/Telemetry.h" #include "plbase64.h" #include "prmem.h" @@ -917,7 +920,7 @@ WebSocketChannel::WebSocketChannel() : mPingTimeout(0), mPingResponseTimeout(10000), mMaxConcurrentConnections(200), - mRecvdHttpOnStartRequest(0), + mGotUpgradeOK(0), mRecvdHttpUpgradeTransport(0), mRequestedClose(0), mClientClosed(0), @@ -2187,6 +2190,36 @@ WebSocketChannel::StartWebsocketData() return mSocketIn->AsyncWait(this, 0, 0, mSocketThread); } +void +WebSocketChannel::ReportConnectionTelemetry() +{ + // 3 bits are used. high bit is for wss, middle bit for failed, + // and low bit for proxy.. + // 0 - 7 : ws-ok-plain, ws-ok-proxy, ws-failed-plain, ws-failed-proxy, + // wss-ok-plain, wss-ok-proxy, wss-failed-plain, wss-failed-proxy + + bool didProxy = false; + + nsCOMPtr pi; + nsCOMPtr pc = do_QueryInterface(mChannel); + if (pc) + pc->GetProxyInfo(getter_AddRefs(pi)); + if (pi) { + nsAutoCString proxyType; + pi->GetType(proxyType); + if (!proxyType.IsEmpty() && + !proxyType.Equals(NS_LITERAL_CSTRING("direct"))) + didProxy = true; + } + + uint8_t value = (mEncrypted ? (1 << 2) : 0) | + (!mGotUpgradeOK ? (1 << 1) : 0) | + (didProxy ? (1 << 0) : 0); + + LOG(("WebSocketChannel::ReportConnectionTelemetry() %p %d", this, value)); + Telemetry::Accumulate(Telemetry::WEBSOCKETS_HANDSHAKE_TYPE, value); +} + // nsIDNSListener NS_IMETHODIMP @@ -2380,7 +2413,7 @@ WebSocketChannel::Notify(nsITimer *timer) LOG(("WebSocketChannel:: Expecting Server Close - Timed Out\n")); AbortSession(NS_ERROR_NET_TIMEOUT); } else if (timer == mOpenTimer) { - NS_ABORT_IF_FALSE(!mRecvdHttpOnStartRequest, + NS_ABORT_IF_FALSE(!mGotUpgradeOK, "Open Timer after open complete"); NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread"); @@ -2717,7 +2750,7 @@ WebSocketChannel::OnTransportAvailable(nsISocketTransport *aTransport, } LOG(("WebSocketChannel::OnTransportAvailable %p [%p %p %p] rcvdonstart=%d\n", - this, aTransport, aSocketIn, aSocketOut, mRecvdHttpOnStartRequest)); + this, aTransport, aSocketIn, aSocketOut, mGotUpgradeOK)); NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread"); NS_ABORT_IF_FALSE(!mRecvdHttpUpgradeTransport, "OTA duplicated"); @@ -2734,7 +2767,7 @@ WebSocketChannel::OnTransportAvailable(nsISocketTransport *aTransport, if (NS_FAILED(rv)) return rv; mRecvdHttpUpgradeTransport = 1; - if (mRecvdHttpOnStartRequest) + if (mGotUpgradeOK) return StartWebsocketData(); return NS_OK; } @@ -2748,7 +2781,7 @@ WebSocketChannel::OnStartRequest(nsIRequest *aRequest, LOG(("WebSocketChannel::OnStartRequest(): %p [%p %p] recvdhttpupgrade=%d\n", this, aRequest, aContext, mRecvdHttpUpgradeTransport)); NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread"); - NS_ABORT_IF_FALSE(!mRecvdHttpOnStartRequest, "OTA duplicated"); + NS_ABORT_IF_FALSE(!mGotUpgradeOK, "OTA duplicated"); if (mOpenTimer) { mOpenTimer->Cancel(); @@ -2881,7 +2914,7 @@ WebSocketChannel::OnStartRequest(nsIRequest *aRequest, if (NS_FAILED(rv)) return rv; - mRecvdHttpOnStartRequest = 1; + mGotUpgradeOK = 1; if (mRecvdHttpUpgradeTransport) return StartWebsocketData(); @@ -2897,6 +2930,8 @@ WebSocketChannel::OnStopRequest(nsIRequest *aRequest, this, aRequest, aContext, aStatusCode)); NS_ABORT_IF_FALSE(NS_IsMainThread(), "not main thread"); + ReportConnectionTelemetry(); + // This is the end of the HTTP upgrade transaction, the // upgraded streams live on diff --git a/netwerk/protocol/websocket/WebSocketChannel.h b/netwerk/protocol/websocket/WebSocketChannel.h index a6602ceb1ac..d53cb5ac300 100644 --- a/netwerk/protocol/websocket/WebSocketChannel.h +++ b/netwerk/protocol/websocket/WebSocketChannel.h @@ -132,6 +132,7 @@ private: nsresult ApplyForAdmission(); nsresult StartWebsocketData(); uint16_t ResultToCloseCode(nsresult resultCode); + void ReportConnectionTelemetry(); void StopSession(nsresult reason); void AbortSession(nsresult reason); @@ -186,7 +187,7 @@ private: int32_t mMaxConcurrentConnections; - uint32_t mRecvdHttpOnStartRequest : 1; + uint32_t mGotUpgradeOK : 1; uint32_t mRecvdHttpUpgradeTransport : 1; uint32_t mRequestedClose : 1; uint32_t mClientClosed : 1; diff --git a/toolkit/components/telemetry/Histograms.json b/toolkit/components/telemetry/Histograms.json index 515f2f795e9..23d955519aa 100644 --- a/toolkit/components/telemetry/Histograms.json +++ b/toolkit/components/telemetry/Histograms.json @@ -701,6 +701,16 @@ "n_buckets": 50, "description": "HTTP subitem: Overall load time - network (ms)" }, + "HTTP_PROXY_TYPE": { + "kind": "enumerated", + "n_values": 8, + "description": "HTTP Proxy Type (none, http, socks)" + }, + "WEBSOCKETS_HANDSHAKE_TYPE": { + "kind": "enumerated", + "n_values": 16, + "description": "Websockets Handshake Results (ws-ok-plain, ws-ok-proxy, ws-failed-plain, ws-failed-proxy, wss-ok-plain, wss-ok-proxy, wss-failed-plain, wss-failed-proxy)" + }, "SPDY_VERSION2": { "kind": "enumerated", "n_values": 48,