Bug 817381 - Add sThreadCount and sTelemetryMaxThreadCount to count the number of maximum concurrent threads in a download session and implemented Telemetry for the same. r=biesi

This commit is contained in:
Sunny 2013-03-04 22:40:11 -05:00
parent e805fec3d9
commit 7547ef4321
3 changed files with 45 additions and 0 deletions

View File

@ -16,6 +16,7 @@
#include "nsXPCOMStrings.h"
#include "BackgroundFileSaver.h"
#include "mozilla/Telemetry.h"
namespace mozilla {
namespace net {
@ -67,6 +68,9 @@ private:
////////////////////////////////////////////////////////////////////////////////
//// BackgroundFileSaver
uint32_t BackgroundFileSaver::sThreadCount = 0;
uint32_t BackgroundFileSaver::sTelemetryMaxThreadCount = 0;
BackgroundFileSaver::BackgroundFileSaver()
: mControlThread(nullptr)
, mWorkerThread(nullptr)
@ -117,6 +121,8 @@ BackgroundFileSaver::virtualDestroyNSSReference()
nsresult
BackgroundFileSaver::Init()
{
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
nsresult rv;
rv = NS_NewPipe2(getter_AddRefs(mPipeInputStream),
@ -130,6 +136,11 @@ BackgroundFileSaver::Init()
rv = NS_NewThread(getter_AddRefs(mWorkerThread));
NS_ENSURE_SUCCESS(rv, rv);
sThreadCount++;
if (sThreadCount > sTelemetryMaxThreadCount) {
sTelemetryMaxThreadCount = sThreadCount;
}
return NS_OK;
}
@ -600,6 +611,8 @@ BackgroundFileSaver::NotifyTargetChange(nsIFile *aTarget)
nsresult
BackgroundFileSaver::NotifySaveComplete()
{
MOZ_ASSERT(NS_IsMainThread(), "This should be called on the main thread");
nsresult status;
{
MutexAutoLock lock(mLock);
@ -619,6 +632,18 @@ BackgroundFileSaver::NotifySaveComplete()
// reference to it through the event object.
mWorkerThread->Shutdown();
sThreadCount--;
// When there are no more active downloads, we consider the download session
// finished. We record the maximum number of concurrent downloads reached
// during the session in a telemetry histogram, and we reset the maximum
// thread counter for the next download session
if (sThreadCount == 0) {
Telemetry::Accumulate(Telemetry::BACKGROUNDFILESAVER_THREAD_COUNT,
sTelemetryMaxThreadCount);
sTelemetryMaxThreadCount = 0;
}
return NS_OK;
}

View File

@ -53,6 +53,21 @@ public:
*/
void virtualDestroyNSSReference();
/**
* Number of worker threads that are currently running.
*/
static uint32_t sThreadCount;
/**
* Maximum number of worker threads reached during the current download session,
* used for telemetry.
*
* When there are no more worker threads running, we consider the download
* session finished, and this counter is reset.
*/
static uint32_t sTelemetryMaxThreadCount;
protected:
virtual ~BackgroundFileSaver();

View File

@ -23,6 +23,11 @@
"extended_statistics_ok": true,
"description": "time spent updating accessibility (ms)"
},
"BACKGROUNDFILESAVER_THREAD_COUNT": {
"kind": "enumerated",
"n_values": 21,
"description": "Maximum number of concurrent threads reached during a given download session"
},
"CYCLE_COLLECTOR": {
"kind": "exponential",
"high": "10000",