Bug 1648284 - Record the number of pending critical input events r=smaug

Record the number of pending critical input events that are in
the IPC Channel when we about to run the timeout handler.

This telemetry is mainly used for bug 1644284. We'd like to tell
how often do we run timeout handlers when there are a lot of
pending input events.

Once we know the data, we can use it to do further setTimeout
improvements.

Differential Revision: https://phabricator.services.mozilla.com/D81340
This commit is contained in:
sefeng 2020-06-26 19:08:53 +00:00
Родитель 6a9d502918
Коммит ce403463bf
5 изменённых файлов: 59 добавлений и 0 удалений

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

@ -16,6 +16,7 @@
#include "nsINamed.h"
#include "mozilla/dom/DocGroup.h"
#include "mozilla/dom/PopupBlocker.h"
#include "mozilla/dom/ContentChild.h"
#include "mozilla/dom/TimeoutHandler.h"
#include "TimeoutExecutor.h"
#include "TimeoutBudgetManager.h"
@ -395,6 +396,27 @@ void TimeoutManager::UpdateBudget(const TimeStamp& aNow,
mLastBudgetUpdate = aNow;
}
size_t TimeoutManager::GetNumPendingInputs() {
ContentChild* contentChild = ContentChild::GetSingleton();
mozilla::ipc::MessageChannel* channel =
contentChild ? contentChild->GetIPCChannel() : nullptr;
if (channel) {
size_t count = 0;
channel->PeekMessages([&count](const IPC::Message& aMsg) -> bool {
if (nsContentUtils::IsMessageCriticalInputEvent(aMsg)) {
// The max number we can record in the telemetry is 80,
// so we don't need to continue the counting.
if (++count > 80) {
return false;
}
}
return true;
});
return count;
}
return 0;
}
// The longest interval (as PRIntervalTime) we permit, or that our
// timer code can handle, really. See DELAY_INTERVAL_LIMIT in
// nsTimerImpl.h for details.
@ -885,6 +907,8 @@ void TimeoutManager::RunTimeout(const TimeStamp& aNow,
mLastFiringIndex = timeout->mFiringIndex;
#endif
// This timeout is good to run.
Telemetry::Accumulate(Telemetry::PENDING_CRITICAL_INPUT_WHEN_TIMEOUT,
GetNumPendingInputs());
bool timeout_was_cleared = window->RunTimeoutHandler(timeout, scx);
#if MOZ_GECKO_PROFILER
if (profiler_can_accept_markers()) {

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

@ -103,6 +103,8 @@ class TimeoutManager final {
void SetLoading(bool value);
size_t GetNumPendingInputs();
private:
void MaybeStartThrottleTimeout();

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

@ -9778,6 +9778,21 @@ bool nsContentUtils::IsMessageInputEvent(const IPC::Message& aMsg) {
return false;
}
/* static */
bool nsContentUtils::IsMessageCriticalInputEvent(const IPC::Message& aMsg) {
if ((aMsg.type() & mozilla::dom::PBrowser::PBrowserStart) ==
mozilla::dom::PBrowser::PBrowserStart) {
switch (aMsg.type()) {
case mozilla::dom::PBrowser::Msg_RealMouseButtonEvent__ID:
case mozilla::dom::PBrowser::Msg_RealKeyEvent__ID:
case mozilla::dom::PBrowser::Msg_RealTouchEvent__ID:
case mozilla::dom::PBrowser::Msg_RealDragEvent__ID:
return true;
}
}
return false;
}
static const char* kUserInteractionInactive = "user-interaction-inactive";
static const char* kUserInteractionActive = "user-interaction-active";

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

@ -3201,6 +3201,13 @@ class nsContentUtils {
*/
static bool IsMessageInputEvent(const IPC::Message& aMsg);
/**
* Returns true if the passed-in message is a critical InputEvent.
*
* @param aMsg The message to check
*/
static bool IsMessageCriticalInputEvent(const IPC::Message& aMsg);
static void AsyncPrecreateStringBundles();
static bool ContentIsLink(nsIContent* aContent);

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

@ -1753,6 +1753,17 @@
"description": "Time between receiving a scroll event on the event loop and compositing its result onto the screen (ms)",
"bug_numbers": [1500465, 1604818]
},
"PENDING_CRITICAL_INPUT_WHEN_TIMEOUT": {
"record_in_processes": ["content"],
"products": ["firefox"],
"alert_emails": ["perfteam@mozilla.com", "seanfeng@mozilla.com"],
"expires_in_version": "84",
"kind": "enumerated",
"n_values": 80,
"releaseChannelCollection": "opt-out",
"description": "Measures the number of pending critical input events in the IPC channel when the timeout handler is about to run",
"bug_numbers": [1648284]
},
"CANVAS_2D_USED": {
"record_in_processes": ["main", "content"],
"products": ["firefox", "fennec"],