9
10
/* eslint-disable react-internal/no-production-logging */
11
12
-import type {ReactComponentInfo} from 'shared/ReactTypes';
12
+import type {ReactComponentInfo, ReactIOInfo} from 'shared/ReactTypes';
13
14
import {enableProfilerTimer} from 'shared/ReactFeatureFlags';
15
18
typeof console !== 'undefined' &&
19
typeof console.timeStamp === 'function';
20
21
+const IO_TRACK = 'Server Requests ⚛';
22
const COMPONENTS_TRACK = 'Server Components ⚛';
23
24
export function markAllTracksInOrder() {
26
// Ensure we create the Server Component track groups earlier than the Client Scheduler
27
// and Client Components. We can always add the 0 time slot even if it's in the past.
28
// That's still considered for ordering.
29
+ console.timeStamp(
30
+ 'Server Requests Track',
31
+ 0.001,
32
+ 0.001,
33
+ IO_TRACK,
34
+ undefined,
35
+ 'primary-light',
36
+ );
37
console.timeStamp(
38
'Server Components Track',
39
0.001,
175
trackIdx: number,
176
startTime: number,
177
endTime: number,
178
+ rootEnv: string,
179
): void {
180
if (supportsUserTiming && endTime >= 0 && trackIdx < 10) {
181
+ const env = componentInfo.env;
182
const name = componentInfo.name;
183
+ const isPrimaryEnv = env === rootEnv;
184
+ const color = isPrimaryEnv ? 'primary-light' : 'secondary-light';
185
const entryName = name + ' [deduped]';
186
const debugTask = componentInfo.debugTask;
187
if (__DEV__ && debugTask) {
194
endTime,
195
trackNames[trackIdx],
196
COMPONENTS_TRACK,
184
- 'tertiary-light',
197
+ color,
198
),
199
);
200
} else {
204
endTime,
205
trackNames[trackIdx],
206
COMPONENTS_TRACK,
194
- 'tertiary-light',
207
+ color,
208
+ );
209
+ }
210
+ }
211
+}
212
+
213
+function getIOColor(
214
+ functionName: string,
215
+): 'tertiary-light' | 'tertiary' | 'tertiary-dark' {
216
+ // Add some color variation to be able to distinguish various sources.
217
+ switch (functionName.charCodeAt(0) % 3) {
218
+ case 0:
219
+ return 'tertiary-light';
220
+ case 1:
221
+ return 'tertiary';
222
+ default:
223
+ return 'tertiary-dark';
224
+ }
225
+}
226
+
227
+export function logIOInfo(ioInfo: ReactIOInfo): void {
228
+ const startTime = ioInfo.start;
229
+ const endTime = ioInfo.end;
230
+ if (supportsUserTiming && endTime >= 0) {
231
+ const name = ioInfo.name;
232
+ const debugTask = ioInfo.debugTask;
233
+ const color = getIOColor(name);
234
+ if (__DEV__ && debugTask) {
235
+ debugTask.run(
236
+ // $FlowFixMe[method-unbinding]
237
+ console.timeStamp.bind(
238
+ console,
239
+ name,
240
+ startTime < 0 ? 0 : startTime,
241
+ endTime,
242
+ IO_TRACK,
243
+ undefined,
244
+ color,
245
+ ),
246
+ );
247
+ } else {
248
+ console.timeStamp(
249
+ name,
250
+ startTime < 0 ? 0 : startTime,
251
+ endTime,
252
+ IO_TRACK,
253
+ undefined,
254
+ color,
255
);
256
}
257
}