Skip to content

Commit

Permalink
[scheduler][profiler] Start time of delayed tasks (#16809)
Browse files Browse the repository at this point in the history
Fixes a bug in the Scheduler profiler where the start time of a delayed
tasks is always 0.
  • Loading branch information
acdlite authored Sep 17, 2019
1 parent f40ceb0 commit 901139c
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/scheduler/src/Scheduler.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ function advanceTimers(currentTime) {
timer.sortIndex = timer.expirationTime;
push(taskQueue, timer);
if (enableProfiling) {
markTaskStart(timer);
markTaskStart(timer, currentTime);
timer.isQueued = true;
}
} else {
Expand Down
26 changes: 26 additions & 0 deletions packages/scheduler/src/__tests__/SchedulerProfiling-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,32 @@ Task 2 [Normal] │ ░░░░░░░░🡐 canceled
);
});

it('handles delayed tasks', () => {
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
scheduleCallback(
NormalPriority,
() => {
Scheduler.unstable_advanceTime(1000);
Scheduler.unstable_yieldValue('A');
},
{
delay: 1000,
},
);
expect(Scheduler).toFlushWithoutYielding();

Scheduler.unstable_advanceTime(1000);

expect(Scheduler).toFlushAndYield(['A']);

expect(stopProfilingAndPrintFlamegraph()).toEqual(
`
!!! Main thread │████████████████████░░░░░░░░░░░░░░░░░░░░
Task 1 [Normal] │ ████████████████████
`,
);
});

it('handles cancelling a delayed task', () => {
Scheduler.unstable_Profiling.startLoggingProfilingEvents();
const task = scheduleCallback(
Expand Down

0 comments on commit 901139c

Please sign in to comment.