Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a34ca7b

Browse files
authored
[Scheduler] Profiling features (facebook#16145)
* [Scheduler] Mark user-timing events 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. * Expose shared array buffer with profiling info Array contains - the priority Scheduler is currently running - the size of the queue - the id of the currently running task * Replace user-timing calls with event log Events are written to an array buffer using a custom instruction format. For now, this is only meant to be used during page start up, before the profiler worker has a chance to start up. Once the worker is ready, call `stopLoggingProfilerEvents` to return the log up to that point, then send the array buffer to the worker. Then switch to the sampling based approach. * Record the current run ID Each synchronous block of Scheduler work is given a unique run ID. This is different than a task ID because a single task will have more than one run if it yields with a continuation.
1 parent 5663635 commit a34ca7b

18 files changed

+919
-35
lines changed

.eslintrc.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ module.exports = {
140140
],
141141

142142
globals: {
143+
SharedArrayBuffer: true,
144+
143145
spyOnDev: true,
144146
spyOnDevAndProd: true,
145147
spyOnProd: true,

packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ describe('ReactDebugFiberPerf', () => {
136136
require('shared/ReactFeatureFlags').enableProfilerTimer = false;
137137
require('shared/ReactFeatureFlags').replayFailedUnitOfWorkWithInvokeGuardedCallback = false;
138138
require('shared/ReactFeatureFlags').debugRenderPhaseSideEffectsForStrictMode = false;
139+
require('scheduler/src/SchedulerFeatureFlags').enableProfiling = false;
139140

140141
// Import after the polyfill is set up:
141142
React = require('react');

packages/scheduler/npm/umd/scheduler.development.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,20 @@
110110
);
111111
}
112112

113+
function unstable_startLoggingProfilingEvents() {
114+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_startLoggingProfilingEvents.apply(
115+
this,
116+
arguments
117+
);
118+
}
119+
120+
function unstable_stopLoggingProfilingEvents() {
121+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_stopLoggingProfilingEvents.apply(
122+
this,
123+
arguments
124+
);
125+
}
126+
113127
return Object.freeze({
114128
unstable_now: unstable_now,
115129
unstable_scheduleCallback: unstable_scheduleCallback,
@@ -124,6 +138,8 @@
124138
unstable_pauseExecution: unstable_pauseExecution,
125139
unstable_getFirstCallbackNode: unstable_getFirstCallbackNode,
126140
unstable_forceFrameRate: unstable_forceFrameRate,
141+
unstable_startLoggingProfilingEvents: unstable_startLoggingProfilingEvents,
142+
unstable_stopLoggingProfilingEvents: unstable_stopLoggingProfilingEvents,
127143
get unstable_IdlePriority() {
128144
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
129145
.Scheduler.unstable_IdlePriority;
@@ -144,5 +160,9 @@
144160
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
145161
.Scheduler.unstable_UserBlockingPriority;
146162
},
163+
get unstable_sharedProfilingBuffer() {
164+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
165+
.Scheduler.unstable_getFirstCallbackNode;
166+
},
147167
});
148168
});

packages/scheduler/npm/umd/scheduler.production.min.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@
104104
);
105105
}
106106

107+
function unstable_startLoggingProfilingEvents() {
108+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_startLoggingProfilingEvents.apply(
109+
this,
110+
arguments
111+
);
112+
}
113+
114+
function unstable_stopLoggingProfilingEvents() {
115+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_stopLoggingProfilingEvents.apply(
116+
this,
117+
arguments
118+
);
119+
}
120+
107121
return Object.freeze({
108122
unstable_now: unstable_now,
109123
unstable_scheduleCallback: unstable_scheduleCallback,
@@ -118,6 +132,8 @@
118132
unstable_pauseExecution: unstable_pauseExecution,
119133
unstable_getFirstCallbackNode: unstable_getFirstCallbackNode,
120134
unstable_forceFrameRate: unstable_forceFrameRate,
135+
unstable_startLoggingProfilingEvents: unstable_startLoggingProfilingEvents,
136+
unstable_stopLoggingProfilingEvents: unstable_stopLoggingProfilingEvents,
121137
get unstable_IdlePriority() {
122138
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
123139
.Scheduler.unstable_IdlePriority;
@@ -138,5 +154,9 @@
138154
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
139155
.Scheduler.unstable_UserBlockingPriority;
140156
},
157+
get unstable_sharedProfilingBuffer() {
158+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
159+
.Scheduler.unstable_getFirstCallbackNode;
160+
},
141161
});
142162
});

packages/scheduler/npm/umd/scheduler.profiling.min.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,20 @@
104104
);
105105
}
106106

107+
function unstable_startLoggingProfilingEvents() {
108+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_startLoggingProfilingEvents.apply(
109+
this,
110+
arguments
111+
);
112+
}
113+
114+
function unstable_stopLoggingProfilingEvents() {
115+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.Scheduler.unstable_stopLoggingProfilingEvents.apply(
116+
this,
117+
arguments
118+
);
119+
}
120+
107121
return Object.freeze({
108122
unstable_now: unstable_now,
109123
unstable_scheduleCallback: unstable_scheduleCallback,
@@ -118,6 +132,8 @@
118132
unstable_pauseExecution: unstable_pauseExecution,
119133
unstable_getFirstCallbackNode: unstable_getFirstCallbackNode,
120134
unstable_forceFrameRate: unstable_forceFrameRate,
135+
unstable_startLoggingProfilingEvents: unstable_startLoggingProfilingEvents,
136+
unstable_stopLoggingProfilingEvents: unstable_stopLoggingProfilingEvents,
121137
get unstable_IdlePriority() {
122138
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
123139
.Scheduler.unstable_IdlePriority;
@@ -138,5 +154,9 @@
138154
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
139155
.Scheduler.unstable_UserBlockingPriority;
140156
},
157+
get unstable_sharedProfilingBuffer() {
158+
return global.React.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED
159+
.Scheduler.unstable_getFirstCallbackNode;
160+
},
141161
});
142162
});

0 commit comments

Comments
 (0)