Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ReactVersion to SchedulingProfiler render scheduled marks #19553

Merged
merged 2 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions packages/react-reconciler/src/SchedulingProfiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
enableSchedulingProfiler,
enableSchedulingProfilerComponentStacks,
} from 'shared/ReactFeatureFlags';
import ReactVersion from 'shared/ReactVersion';
import getComponentName from 'shared/getComponentName';
import {getStackByFiberInDevAndProd} from './ReactFiberComponentStack';

Expand All @@ -29,6 +30,13 @@ function formatLanes(laneOrLanes: Lane | Lanes): string {
return ((laneOrLanes: any): number).toString();
}

// Create a mark on React initialization
if (enableSchedulingProfiler) {
if (supportsUserTiming) {
performance.mark(`--react-init-${ReactVersion}`);
}
}

export function markCommitStarted(lanes: Lanes): void {
if (enableSchedulingProfiler) {
if (supportsUserTiming) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

'use strict';

import ReactVersion from 'shared/ReactVersion';

function normalizeCodeLocInfo(str) {
return (
str &&
Expand Down Expand Up @@ -54,6 +56,7 @@ describe('SchedulingProfiler', () => {
beforeEach(() => {
jest.resetModules();
global.performance = createUserTimingPolyfill();
marks = [];

React = require('react');

Expand All @@ -62,8 +65,6 @@ describe('SchedulingProfiler', () => {
ReactNoop = require('react-noop-renderer');

Scheduler = require('scheduler');

marks = [];
});

afterEach(() => {
Expand All @@ -76,11 +77,17 @@ describe('SchedulingProfiler', () => {
expect(marks).toEqual([]);
});

// @gate enableSchedulingProfiler
it('should log React version on initialization', () => {
expect(marks).toEqual([`--react-init-${ReactVersion}`]);
});

// @gate enableSchedulingProfiler
it('should mark sync render without suspends or state updates', () => {
ReactTestRenderer.create(<div />);

expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-1',
'--render-start-1',
'--render-stop',
Expand All @@ -95,7 +102,10 @@ describe('SchedulingProfiler', () => {
it('should mark concurrent render without suspends or state updates', () => {
ReactTestRenderer.create(<div />, {unstable_isConcurrent: true});

expect(marks).toEqual(['--schedule-render-512']);
expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
]);

marks.splice(0);

Expand Down Expand Up @@ -128,6 +138,7 @@ describe('SchedulingProfiler', () => {
expect(ReactNoop.flushNextYield()).toEqual(['Foo']);

expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
'--render-start-512',
'--render-yield',
Expand All @@ -148,6 +159,7 @@ describe('SchedulingProfiler', () => {
);

expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-1',
'--render-start-1',
toggleComponentStacks(
Expand Down Expand Up @@ -184,6 +196,7 @@ describe('SchedulingProfiler', () => {
);

expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-1',
'--render-start-1',
toggleComponentStacks(
Expand Down Expand Up @@ -220,7 +233,10 @@ describe('SchedulingProfiler', () => {
{unstable_isConcurrent: true},
);

expect(marks).toEqual(['--schedule-render-512']);
expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
]);

marks.splice(0);

Expand Down Expand Up @@ -262,7 +278,10 @@ describe('SchedulingProfiler', () => {
{unstable_isConcurrent: true},
);

expect(marks).toEqual(['--schedule-render-512']);
expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
]);

marks.splice(0);

Expand Down Expand Up @@ -304,7 +323,10 @@ describe('SchedulingProfiler', () => {

ReactTestRenderer.create(<Example />, {unstable_isConcurrent: true});

expect(marks).toEqual(['--schedule-render-512']);
expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
]);

marks.splice(0);

Expand Down Expand Up @@ -340,7 +362,10 @@ describe('SchedulingProfiler', () => {

ReactTestRenderer.create(<Example />, {unstable_isConcurrent: true});

expect(marks).toEqual(['--schedule-render-512']);
expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
]);

marks.splice(0);

Expand Down Expand Up @@ -377,7 +402,10 @@ describe('SchedulingProfiler', () => {

ReactTestRenderer.create(<Example />, {unstable_isConcurrent: true});

expect(marks).toEqual(['--schedule-render-512']);
expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
]);

marks.splice(0);

Expand Down Expand Up @@ -414,7 +442,10 @@ describe('SchedulingProfiler', () => {

ReactTestRenderer.create(<Example />, {unstable_isConcurrent: true});

expect(marks).toEqual(['--schedule-render-512']);
expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
]);

marks.splice(0);

Expand Down Expand Up @@ -449,7 +480,10 @@ describe('SchedulingProfiler', () => {

ReactTestRenderer.create(<Example />, {unstable_isConcurrent: true});

expect(marks).toEqual(['--schedule-render-512']);
expect(marks).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
]);

marks.splice(0);

Expand Down Expand Up @@ -489,6 +523,7 @@ describe('SchedulingProfiler', () => {
gate(({old}) => {
if (old) {
expect(marks.map(normalizeCodeLocInfo)).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
'--render-start-512',
'--render-stop',
Expand All @@ -508,6 +543,7 @@ describe('SchedulingProfiler', () => {
]);
} else {
expect(marks.map(normalizeCodeLocInfo)).toEqual([
`--react-init-${ReactVersion}`,
'--schedule-render-512',
'--render-start-512',
'--render-stop',
Expand Down