diff --git a/dom/base/nsGlobalWindow.cpp b/dom/base/nsGlobalWindow.cpp index 33b959db714..b91d304c264 100644 --- a/dom/base/nsGlobalWindow.cpp +++ b/dom/base/nsGlobalWindow.cpp @@ -283,6 +283,9 @@ static bool gDragServiceDisabled = false; static FILE *gDumpFile = nsnull; static PRUint64 gNextWindowID = 0; static PRUint32 gSerialCounter = 0; +static PRUint32 gTimeoutsRecentlySet = 0; +static TimeStamp gLastRecordedRecentTimeouts; +#define STATISTICS_INTERVAL (30 * PR_MSEC_PER_SEC) #ifdef DEBUG_jst PRInt32 gTimeoutCnt = 0; @@ -9054,6 +9057,7 @@ nsGlobalWindow::SetTimeoutOrInterval(nsIScriptTimeoutHandler *aHandler, timeout->mPrincipal = ourPrincipal; } + ++gTimeoutsRecentlySet; TimeDuration delta = TimeDuration::FromMilliseconds(realInterval); if (!IsFrozen() && !mTimeoutsSuspendDepth) { @@ -9228,6 +9232,16 @@ nsGlobalWindow::RunTimeout(nsTimeout *aTimeout) return; } + // Record telemetry information about timers set recently. + TimeDuration recordingInterval = TimeDuration::FromMilliseconds(STATISTICS_INTERVAL); + if (gLastRecordedRecentTimeouts.IsNull() || + now - gLastRecordedRecentTimeouts > recordingInterval) { + PRUint32 count = gTimeoutsRecentlySet; + gTimeoutsRecentlySet = 0; + Telemetry::Accumulate(Telemetry::DOM_TIMERS_RECENTLY_SET, count); + gLastRecordedRecentTimeouts = now; + } + // Insert a dummy timeout into the list of timeouts between the // portion of the list that we are about to process now and those // timeouts that will be processed in a future call to diff --git a/toolkit/components/telemetry/TelemetryHistograms.h b/toolkit/components/telemetry/TelemetryHistograms.h index 3e7f7701c48..be77bc7b6d9 100644 --- a/toolkit/components/telemetry/TelemetryHistograms.h +++ b/toolkit/components/telemetry/TelemetryHistograms.h @@ -324,6 +324,7 @@ HISTOGRAM_BOOLEAN(XMLHTTPREQUEST_ASYNC_OR_SYNC, "Type of XMLHttpRequest, async o * DOM telemetry. */ HISTOGRAM(DOM_TIMERS_FIRED_PER_NATIVE_TIMEOUT, 1, 3000, 10, EXPONENTIAL, "DOM: Timer handlers called per native timer expiration") +HISTOGRAM(DOM_TIMERS_RECENTLY_SET, 1, 3000, 10, EXPONENTIAL, "DOM: setTimeout/setInterval calls recently (last 30s or more)") /** * DOM Storage telemetry.