-
Notifications
You must be signed in to change notification settings - Fork 47.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Marks when Scheduler starts and stops running a task. Also marks when a task is initially scheduled, and when Scheduler is waiting for a callback, which can't be inferred from a sample-based JavaScript CPU profile alone. The plan is to use the user-timing events to build a Scheduler profiler that shows how the lifetime of tasks interact with each other and with unscheduled main thread work. The test suite works by printing an text representation of a Scheduler flamegraph.
- Loading branch information
Showing
7 changed files
with
606 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
export type PriorityLevel = 1 | 2 | 3 | 4 | 5; | ||
|
||
// TODO: Use symbols? | ||
export const ImmediatePriority = 1; | ||
export const UserBlockingPriority = 2; | ||
export const NormalPriority = 3; | ||
export const LowPriority = 4; | ||
export const IdlePriority = 5; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
* | ||
* @flow | ||
*/ | ||
|
||
import type {PriorityLevel} from './SchedulerPriorities'; | ||
import {enableProfiling as enableProfilingFeatureFlag} from './SchedulerFeatureFlags'; | ||
|
||
const enableProfiling = | ||
enableProfilingFeatureFlag && | ||
typeof performance !== 'undefined' && | ||
typeof performance.mark === 'function' && | ||
typeof performance.clearMarks === 'function'; | ||
|
||
let runIdCounter: number = 0; | ||
let mainThreadIdCounter: number = 0; | ||
|
||
export function markTaskStart(task: {id: number}) { | ||
if (enableProfiling) { | ||
// Use extra field to track if delayed task starts. | ||
const taskStartMark = `SchedulerTask-${task.id}-Start`; | ||
performance.mark(taskStartMark); | ||
performance.clearMarks(taskStartMark); | ||
} | ||
} | ||
|
||
export function markTaskCompleted(task: { | ||
id: number, | ||
priorityLevel: PriorityLevel, | ||
label?: string, | ||
}) { | ||
if (enableProfiling) { | ||
const info = JSON.stringify({ | ||
priorityLevel: task.priorityLevel, | ||
label: task.label, | ||
exitStatus: 'completed', | ||
}); | ||
const taskEndMark = `SchedulerTask-${task.id}-End-${info}`; | ||
performance.mark(taskEndMark); | ||
performance.clearMarks(taskEndMark); | ||
} | ||
} | ||
|
||
export function markTaskCanceled(task: { | ||
id: number, | ||
priorityLevel: PriorityLevel, | ||
label?: string, | ||
}) { | ||
if (enableProfiling) { | ||
const info = JSON.stringify({ | ||
priorityLevel: task.priorityLevel, | ||
label: task.label, | ||
exitStatus: 'canceled', | ||
}); | ||
const taskEndMark = `SchedulerTask-${task.id}-End-${info}`; | ||
performance.mark(taskEndMark); | ||
performance.clearMarks(taskEndMark); | ||
} | ||
} | ||
|
||
export function markTaskErrored(task: { | ||
id: number, | ||
priorityLevel: PriorityLevel, | ||
label?: string, | ||
}) { | ||
if (enableProfiling) { | ||
const info = JSON.stringify({ | ||
priorityLevel: task.priorityLevel, | ||
label: task.label, | ||
exitStatus: 'errored', | ||
}); | ||
const taskEndMark = `SchedulerTask-${task.id}-End-${info}`; | ||
performance.mark(taskEndMark); | ||
performance.clearMarks(taskEndMark); | ||
} | ||
} | ||
|
||
export function markTaskRun(task: {id: number}) { | ||
if (enableProfiling) { | ||
runIdCounter++; | ||
const runMark = `SchedulerTask-${task.id}-Run-${runIdCounter}`; | ||
performance.mark(runMark); | ||
performance.clearMarks(runMark); | ||
} | ||
} | ||
|
||
export function markTaskYield(task: {id: number}) { | ||
if (enableProfiling) { | ||
const yieldMark = `SchedulerTask-${task.id}-Yield-${runIdCounter}`; | ||
performance.mark(yieldMark); | ||
performance.clearMarks(yieldMark); | ||
} | ||
} | ||
|
||
export function markSchedulerSuspended() { | ||
if (enableProfiling) { | ||
mainThreadIdCounter++; | ||
const suspendStartMark = 'SchedulerSuspended-Start-' + mainThreadIdCounter; | ||
performance.mark(suspendStartMark); | ||
performance.clearMarks(suspendStartMark); | ||
} | ||
} | ||
|
||
export function markSchedulerUnsuspended() { | ||
if (enableProfiling) { | ||
const suspendedEndMark = 'SchedulerSuspended-End-' + mainThreadIdCounter; | ||
performance.mark(suspendedEndMark); | ||
performance.clearMarks(suspendedEndMark); | ||
} | ||
} |
Oops, something went wrong.