Bug 1747138 - Breakdown CPU and GPU time by process type, r=chutten,gsvelto

Differential Revision: https://phabricator.services.mozilla.com/D134441
This commit is contained in:
Florian Quèze
2022-02-03 20:37:21 +00:00
parent 68ebef3aff
commit c61b811f78
12 changed files with 520 additions and 34 deletions

View File

@@ -172,6 +172,7 @@ class ProcessPriorityManagerImpl final : public nsIObserver,
static void StaticInit();
static bool PrefsEnabled();
static void SetProcessPriorityIfEnabled(int aPid, ProcessPriority aPriority);
static bool TestMode();
NS_DECL_ISUPPORTS
@@ -365,6 +366,17 @@ bool ProcessPriorityManagerImpl::PrefsEnabled() {
!StaticPrefs::dom_ipc_tabs_disabled();
}
/* static */
void ProcessPriorityManagerImpl::SetProcessPriorityIfEnabled(
int aPid, ProcessPriority aPriority) {
// The preference doesn't disable the process priority manager, but only its
// effect. This way the IPCs still happen and can be used to collect telemetry
// about CPU use.
if (PrefsEnabled()) {
hal::SetProcessPriority(aPid, aPriority);
}
}
/* static */
bool ProcessPriorityManagerImpl::TestMode() {
return StaticPrefs::dom_ipc_processPriorityManager_testMode();
@@ -382,20 +394,13 @@ void ProcessPriorityManagerImpl::StaticInit() {
return;
}
// If IPC tabs aren't enabled at startup, don't bother with any of this.
if (!PrefsEnabled()) {
LOG("InitProcessPriorityManager bailing due to prefs.");
// Run StaticInit() again if the prefs change. We don't expect this to
// happen in normal operation, but it happens during testing.
if (!sPrefListenersRegistered) {
sPrefListenersRegistered = true;
Preferences::RegisterCallback(PrefChangedCallback,
"dom.ipc.processPriorityManager.enabled");
Preferences::RegisterCallback(PrefChangedCallback,
"dom.ipc.tabs.disabled");
}
return;
// Run StaticInit() again if the prefs change. We don't expect this to
// happen in normal operation, but it happens during testing.
if (!sPrefListenersRegistered) {
sPrefListenersRegistered = true;
Preferences::RegisterCallback(PrefChangedCallback,
"dom.ipc.processPriorityManager.enabled");
Preferences::RegisterCallback(PrefChangedCallback, "dom.ipc.tabs.disabled");
}
sInitialized = true;
@@ -426,7 +431,7 @@ void ProcessPriorityManagerImpl::Init() {
// The parent process's priority never changes; set it here and then forget
// about it. We'll manage only subprocesses' priorities using the process
// priority manager.
hal::SetProcessPriority(getpid(), PROCESS_PRIORITY_PARENT_PROCESS);
SetProcessPriorityIfEnabled(getpid(), PROCESS_PRIORITY_PARENT_PROCESS);
nsCOMPtr<nsIObserverService> os = services::GetObserverService();
if (os) {
@@ -762,8 +767,7 @@ void ParticularProcessPriorityManager::SetPriorityNow(
return;
}
if (!ProcessPriorityManagerImpl::PrefsEnabled() || !mContentParent ||
mPriority == aPriority) {
if (!mContentParent || mPriority == aPriority) {
return;
}
@@ -794,7 +798,7 @@ void ParticularProcessPriorityManager::SetPriorityNow(
Telemetry::ScalarID::DOM_CONTENTPROCESS_OS_PRIORITY_LOWERED, 1);
}
hal::SetProcessPriority(Pid(), mPriority);
ProcessPriorityManagerImpl::SetProcessPriorityIfEnabled(Pid(), mPriority);
if (oldPriority != mPriority) {
ProcessPriorityManagerImpl::GetSingleton()->NotifyProcessPriorityChanged(