Bug 1363700 - Add RCWN stats to about:networking r=bz,michal

MozReview-Commit-ID: GVt1omCfL6t

--HG--
extra : rebase_source : fdb321360f21f0f54692bc6b715abb4c155171b7
This commit is contained in:
Valentin Gosu 2017-05-10 19:23:54 +02:00
Родитель 752bb6183f
Коммит 4ccb51bae2
10 изменённых файлов: 137 добавлений и 2 удалений

Просмотреть файл

@ -75,3 +75,9 @@ dictionary DNSLookupDict {
dictionary ConnStatusDict {
DOMString status = "";
};
dictionary RcwnStatus {
unsigned long totalNetworkRequests = 0;
unsigned long rcwnCacheWonCount = 0;
unsigned long rcwnNetWonCount = 0;
};

Просмотреть файл

@ -19,6 +19,7 @@
#include "nsThreadUtils.h"
#include "nsURLHelper.h"
#include "mozilla/Logging.h"
#include "nsIOService.h"
using mozilla::AutoSafeJSContext;
using mozilla::dom::Sequence;
@ -167,6 +168,28 @@ public:
NS_IMPL_ISUPPORTS(ConnectionData, nsITransportEventSink, nsITimerCallback)
class RcwnData
: public nsISupports
{
virtual ~RcwnData()
{
}
public:
NS_DECL_THREADSAFE_ISUPPORTS
RcwnData()
{
mThread = nullptr;
}
nsMainThreadPtrHandle<NetDashboardCallback> mCallback;
nsIThread *mThread;
};
NS_IMPL_ISUPPORTS0(RcwnData)
NS_IMETHODIMP
ConnectionData::OnTransportStatus(nsITransport *aTransport, nsresult aStatus,
int64_t aProgress, int64_t aProgressMax)
@ -755,6 +778,39 @@ Dashboard::RequestDNSLookup(const nsACString &aHost,
return rv;
}
NS_IMETHODIMP
Dashboard::RequestRcwnStats(NetDashboardCallback *aCallback)
{
RefPtr<RcwnData> rcwnData = new RcwnData();
rcwnData->mThread = NS_GetCurrentThread();
rcwnData->mCallback =
new nsMainThreadPtrHolder<NetDashboardCallback>(aCallback, true);
return rcwnData->mThread->Dispatch(
NewRunnableMethod<RefPtr<RcwnData>>(this, &Dashboard::GetRcwnData, rcwnData),
NS_DISPATCH_NORMAL);
}
nsresult
Dashboard::GetRcwnData(RcwnData *aData)
{
AutoSafeJSContext cx;
mozilla::dom::RcwnStatus dict;
dict.mTotalNetworkRequests = gIOService->GetTotalRequestNumber();
dict.mRcwnCacheWonCount = gIOService->GetCacheWonRequestNumber();
dict.mRcwnNetWonCount = gIOService->GetNetWonRequestNumber();
JS::RootedValue val(cx);
if (!ToJSValue(cx, dict, &val)) {
return NS_ERROR_FAILURE;
}
aData->mCallback->OnDashboardDataAvailable(val);
return NS_OK;
}
void
HttpConnInfo::SetHTTP1ProtocolVersion(uint8_t pv)
{

Просмотреть файл

@ -24,6 +24,7 @@ class HttpData;
class DnsData;
class WebSocketRequest;
class ConnectionData;
class RcwnData;
class Dashboard final
: public nsIDashboard
@ -95,6 +96,7 @@ private:
nsresult GetHttpConnections(HttpData *);
nsresult GetDNSCacheEntries(DnsData *);
nsresult GetWebSocketConnections(WebSocketRequest *);
nsresult GetRcwnData(RcwnData *);
nsCOMPtr<nsIDNSService> mDnsService;
};

Просмотреть файл

@ -50,5 +50,10 @@ interface nsIDashboard : nsISupports
* aHost: host name */
void requestDNSLookup(in ACString aHost, in NetDashboardCallback cb);
/**
* Asyncly returns stats regarding the "Race Cache With Network" feature.
*/
void requestRcwnStats(in NetDashboardCallback cb);
AUTF8String getLogPath();
};

Просмотреть файл

@ -188,6 +188,9 @@ nsIOService::nsIOService()
, mNetworkLinkServiceInitialized(false)
, mChannelEventSinks(NS_CHANNEL_EVENT_SINK_CATEGORY)
, mNetworkNotifyChanged(true)
, mTotalRequests(0)
, mCacheWon(0)
, mNetWon(0)
, mLastOfflineStateChange(PR_IntervalNow())
, mLastConnectivityChange(PR_IntervalNow())
, mLastNetworkLinkChange(PR_IntervalNow())

Просмотреть файл

@ -97,6 +97,15 @@ public:
static bool IsInheritSecurityContextForDataURIEnabled();
// Used to count the total number of HTTP requests made
void IncrementRequestNumber() { mTotalRequests++; }
uint32_t GetTotalRequestNumber() { return mTotalRequests; }
// Used to keep "race cache with network" stats
void IncrementCacheWonRequestNumber() { mCacheWon++; }
uint32_t GetCacheWonRequestNumber() { return mCacheWon; }
void IncrementNetWonRequestNumber() { mNetWon++; }
uint32_t GetNetWonRequestNumber() { return mNetWon; }
// Used to trigger a recheck of the captive portal status
nsresult RecheckCaptivePortal();
private:
@ -178,6 +187,10 @@ private:
static bool sDataURIInheritSecurityContext;
uint32_t mTotalRequests;
uint32_t mCacheWon;
uint32_t mNetWon;
// These timestamps are needed for collecting telemetry on PR_Connect,
// PR_ConnectContinue and PR_Close blocking time. If we spend very long
// time in any of these functions we want to know if and what network

Просмотреть файл

@ -7249,6 +7249,13 @@ nsHttpChannel::OnStopRequest(nsIRequest *request, nsISupports *ctxt, nsresult st
}
}
gIOService->IncrementRequestNumber();
if (rcwnStatus == kRaceUsedCache) {
gIOService->IncrementCacheWonRequestNumber();
} else if (rcwnStatus == kRaceUsedNetwork) {
gIOService->IncrementNetWonRequestNumber();
}
// Register entry to the Performance resource timing
mozilla::dom::Performance* documentPerformance = GetPerformance();
if (documentPerformance) {

Просмотреть файл

@ -21,13 +21,15 @@ const gRequestNetworkingData = {
"http": gDashboard.requestHttpConnections,
"sockets": gDashboard.requestSockets,
"dns": gDashboard.requestDNSInfo,
"websockets": gDashboard.requestWebsocketConnections
"websockets": gDashboard.requestWebsocketConnections,
"rcwn": gDashboard.requestRcwnStats,
};
const gDashboardCallbacks = {
"http": displayHttp,
"sockets": displaySockets,
"dns": displayDns,
"websockets": displayWebsockets
"websockets": displayWebsockets,
"rcwn": displayRcwnStats,
};
const REFRESH_INTERVAL_MS = 3000;
@ -124,6 +126,18 @@ function displayWebsockets(data) {
parent.replaceChild(new_cont, cont);
}
function displayRcwnStats(data) {
let status = Services.prefs.getBoolPref("network.http.rcwn.enabled");
let cacheWon = data.rcwnCacheWonCount;
let netWon = data.rcwnNetWonCount;
let total = data.totalNetworkRequests;
document.getElementById("rcwn_status").innerText = status;
document.getElementById("total_req_count").innerText = total;
document.getElementById("rcwn_cache_won_count").innerText = cacheWon;
document.getElementById("rcwn_cache_net_count").innerText = netWon;
}
function requestAllNetworkingData() {
for (let id in gRequestNetworkingData)
requestNetworkingDataForTab(id);

Просмотреть файл

@ -50,6 +50,9 @@
<div class="category" value="logging">
<span class="category-name">&aboutNetworking.logging;</span>
</div>
<div class="category" value="rcwn">
<span class="category-name">&aboutNetworking.rcwn;</span>
</div>
</div>
<div class="main-content">
<div class="header">
@ -139,6 +142,27 @@
</table>
</div>
<div id="rcwn" class="tab" hidden="true">
<table>
<thead>
<tr>
<th>&aboutNetworking.rcwnStatus;</th>
<th>&aboutNetworking.totalNetworkRequests;</th>
<th>&aboutNetworking.rcwnCacheWonCount;</th>
<th>&aboutNetworking.rcwnNetWonCount;</th>
</tr>
</thead>
<tbody id="rcwn_content">
<tr>
<td id="rcwn_status"> </td>
<td id="total_req_count"> </td>
<td id="rcwn_cache_won_count"> </td>
<td id="rcwn_cache_net_count"> </td>
</tr>
</tbody>
</table>
</div>
<div id="logging" class="tab" hidden="true">
<div>
&aboutNetworking.logTutorial;

Просмотреть файл

@ -41,3 +41,8 @@
<!ENTITY aboutNetworking.dnsLookupButton "Resolve">
<!ENTITY aboutNetworking.dnsDomain "Domain">
<!ENTITY aboutNetworking.dnsLookupTableColumn "IPs">
<!ENTITY aboutNetworking.rcwn "RCWN Stats">
<!ENTITY aboutNetworking.rcwnStatus "RCWN Status">
<!ENTITY aboutNetworking.rcwnCacheWonCount "Cache won count">
<!ENTITY aboutNetworking.rcwnNetWonCount "Net won count">
<!ENTITY aboutNetworking.totalNetworkRequests "Total network request count">