Skip to content

Commit 562faec

Browse files
committed
Bug 1651842: Fix event delay being not/incorrecty reported when using TaskController. r=mstange
Differential Revision: https://phabricator.services.mozilla.com/D83542
1 parent b5033e8 commit 562faec

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

xpcom/threads/TaskController.cpp

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,10 @@ void TaskController::AddTask(already_AddRefed<Task>&& aTask) {
119119
task->mPriorityModifier = manager->mCurrentPriorityModifier;
120120
}
121121

122+
#ifdef MOZ_GECKO_PROFILER
123+
task->mInsertionTime = TimeStamp::Now();
124+
#endif
125+
122126
#ifdef DEBUG
123127
task->mIsInGraph = true;
124128

@@ -166,10 +170,6 @@ void TaskController::ProcessPendingMTTask(bool aMayWait) {
166170
if (mMTTaskRunnableProcessedTask || !aMayWait) {
167171
break;
168172
}
169-
nsCOMPtr<nsIThread> mainIThread;
170-
NS_GetMainThread(getter_AddRefs(mainIThread));
171-
nsThread* mainThread = static_cast<nsThread*>(mainIThread.get());
172-
mainThread->SetRunningEventDelay(TimeDuration(), TimeStamp());
173173

174174
BackgroundHangMonitor().NotifyWait();
175175

@@ -181,8 +181,6 @@ void TaskController::ProcessPendingMTTask(bool aMayWait) {
181181
mMainThreadCV.Wait();
182182
}
183183

184-
// See bug 1651842
185-
mainThread->SetRunningEventDelay(TimeDuration(), TimeStamp::Now());
186184
BackgroundHangMonitor().NotifyActivity();
187185
}
188186

@@ -417,6 +415,11 @@ bool TaskController::ExecuteNextTaskOnlyMainThreadInternal(
417415

418416
bool TaskController::DoExecuteNextTaskOnlyMainThreadInternal(
419417
const MutexAutoLock& aProofOfLock) {
418+
nsCOMPtr<nsIThread> mainIThread;
419+
NS_GetMainThread(getter_AddRefs(mainIThread));
420+
nsThread* mainThread = static_cast<nsThread*>(mainIThread.get());
421+
mainThread->SetRunningEventDelay(TimeDuration(), TimeStamp());
422+
420423
uint32_t totalSuspended = 0;
421424
for (TaskManager* manager : mTaskManagers) {
422425
bool modifierChanged =
@@ -489,9 +492,19 @@ bool TaskController::DoExecuteNextTaskOnlyMainThreadInternal(
489492
mIdleTaskManager->State().ClearCachedIdleDeadline();
490493
}
491494

495+
TimeStamp now = TimeStamp::Now();
496+
497+
#ifdef MOZ_GECKO_PROFILER
498+
if (task->GetPriority() < uint32_t(EventQueuePriority::InputHigh)) {
499+
mainThread->SetRunningEventDelay(TimeDuration(), now);
500+
} else {
501+
mainThread->SetRunningEventDelay(now - task->mInsertionTime, now);
502+
}
503+
#endif
504+
492505
PerformanceCounterState::Snapshot snapshot =
493506
mPerformanceCounterState->RunnableWillRun(
494-
task->GetPerformanceCounter(), TimeStamp::Now(),
507+
task->GetPerformanceCounter(), now,
495508
manager == mIdleTaskManager);
496509

497510
{

xpcom/threads/TaskController.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -217,6 +217,11 @@ class Task {
217217
uint32_t mPriority;
218218
// Modifier currently being applied to this task by its taskmanager.
219219
int32_t mPriorityModifier = 0;
220+
#ifdef MOZ_GECKO_PROFILER
221+
// Time this task was inserted into the task graph, this is used by the
222+
// profiler.
223+
mozilla::TimeStamp mInsertionTime;
224+
#endif
220225
};
221226

222227
// A task manager implementation for priority levels that should only

0 commit comments

Comments
 (0)