Skip to content

Commit 6472453

Browse files
committed
Separate v1 v2 data
1 parent 9093665 commit 6472453

3 files changed

Lines changed: 76 additions & 14 deletions

File tree

src/App.js

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// @flow
22

3-
import type {FlamechartData, ReactProfilerDataV2} from './types';
3+
import type {
4+
FlamechartData,
5+
ReactProfilerData,
6+
ReactProfilerDataV2,
7+
} from './types';
48

59
import React, {useState, useCallback} from 'react';
610
import {unstable_batchedUpdates} from 'react-dom';
@@ -11,15 +15,19 @@ import ImportPage from './ImportPage';
1115
import CanvasPage from './CanvasPage';
1216

1317
export default function App() {
14-
const [profilerData, setProfilerData] = useState<ReactProfilerDataV2 | null>(
18+
const [profilerData, setProfilerData] = useState<ReactProfilerData | null>(
1519
null,
1620
);
21+
const [
22+
profilerDataV2,
23+
setProfilerDataV2,
24+
] = useState<ReactProfilerDataV2 | null>(null);
1725
const [flamechart, setFlamechart] = useState<FlamechartData | null>(null);
1826
const [schedulerCanvasHeight, setSchedulerCanvasHeight] = useState<number>(0);
1927

2028
const handleDataImported = useCallback(
2129
(
22-
importedProfilerData: ReactProfilerDataV2,
30+
importedProfilerData: ReactProfilerData,
2331
importedFlamechart: FlamechartData,
2432
) => {
2533
unstable_batchedUpdates(() => {
@@ -34,15 +42,39 @@ export default function App() {
3442
},
3543
);
3644

37-
if (profilerData && flamechart) {
45+
// TODO: Migrate and completely remove V2 stuff
46+
const handleDataImportedV2 = useCallback(
47+
(
48+
importedProfilerData: ReactProfilerDataV2,
49+
importedFlamechart: FlamechartData,
50+
) => {
51+
unstable_batchedUpdates(() => {
52+
setSchedulerCanvasHeight(
53+
REACT_PRIORITIES.reduce((height, priority) => {
54+
return height + getPriorityHeight(importedProfilerData, priority);
55+
}, 0),
56+
);
57+
setProfilerDataV2(importedProfilerData);
58+
setFlamechart(importedFlamechart);
59+
});
60+
},
61+
);
62+
63+
if (profilerData && profilerDataV2 && flamechart) {
3864
return (
3965
<CanvasPage
4066
profilerData={profilerData}
67+
profilerDataV2={profilerDataV2}
4168
flamechart={flamechart}
4269
schedulerCanvasHeight={schedulerCanvasHeight}
4370
/>
4471
);
4572
} else {
46-
return <ImportPage onDataImported={handleDataImported} />;
73+
return (
74+
<ImportPage
75+
onDataImported={handleDataImported}
76+
onDataImportedV2={handleDataImportedV2}
77+
/>
78+
);
4779
}
4880
}

src/CanvasPage.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,19 +35,24 @@ import type {
3535

3636
type ContextMenuContextData = {|
3737
data: ReactProfilerData,
38-
dataV2: ReactProfilerDataV2,
3938
flamechart: FlamechartData,
4039
hoveredEvent: ReactHoverContextInfo | null,
4140
state: PanAndZoomState,
4241
|};
4342

4443
type Props = {|
45-
profilerData: ReactProfilerDataV2,
44+
profilerData: ReactProfilerData,
45+
profilerDataV2: ReactProfilerDataV2,
4646
flamechart: FlamechartData,
4747
schedulerCanvasHeight: number,
4848
|};
4949

50-
function CanvasPage({profilerData, flamechart, schedulerCanvasHeight}: Props) {
50+
function CanvasPage({
51+
profilerData,
52+
profilerDataV2,
53+
flamechart,
54+
schedulerCanvasHeight,
55+
}: Props) {
5156
return (
5257
<div
5358
className={styles.CanvasPage}
@@ -56,6 +61,7 @@ function CanvasPage({profilerData, flamechart, schedulerCanvasHeight}: Props) {
5661
{({height, width}: {height: number, width: number}) => (
5762
<AutoSizedCanvas
5863
data={profilerData}
64+
dataV2={profilerDataV2}
5965
flamechart={flamechart}
6066
height={height}
6167
schedulerCanvasHeight={schedulerCanvasHeight}
@@ -121,7 +127,7 @@ function AutoSizedCanvas({
121127
canvasWidth: width,
122128
fixedColumnWidth: LABEL_FIXED_WIDTH,
123129
fixedHeaderHeight: HEADER_HEIGHT_FIXED,
124-
unscaledContentWidth: data.duration,
130+
unscaledContentWidth: dataV2.duration,
125131
unscaledContentHeight:
126132
schedulerCanvasHeight +
127133
flamechart.layers.length * FLAMECHART_FRAME_HEIGHT,

src/ImportPage.js

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,34 @@
11
// @flow
22

33
import type {TimelineEvent} from './speedscope/import/chrome';
4-
import type {FlamechartData, ReactProfilerDataV2} from './types';
4+
import type {
5+
FlamechartData,
6+
ReactProfilerData,
7+
ReactProfilerDataV2,
8+
} from './types';
59

610
import React, {useEffect} from 'react';
711

812
import preprocessData from './util/preprocessData';
9-
// import preprocessDataNew from './util/preprocessDataV2';
13+
import preprocessDataV2 from './util/preprocessDataV2';
1014
import preprocessFlamechart from './util/preprocessFlamechart';
1115

1216
// TODO: Add import button but keep a static path until canvas layout is ready
1317
import JSON_PATH from 'url:../static/small-devtools.json';
18+
import JSON_PATHV2 from 'url:../static/Profile-20200625T133129.json';
1419

1520
type Props = {|
1621
onDataImported: (
22+
profilerData: ReactProfilerData,
23+
flamechart: FlamechartData,
24+
) => void,
25+
onDataImportedV2: (
1726
profilerData: ReactProfilerDataV2,
1827
flamechart: FlamechartData,
1928
) => void,
2029
|};
2130

22-
export default function ImportPage({onDataImported}: Props) {
31+
export default function ImportPage({onDataImported, onDataImportedV2}: Props) {
2332
useEffect(() => {
2433
fetch(JSON_PATH)
2534
.then(res => res.json())
@@ -30,15 +39,30 @@ export default function ImportPage({onDataImported}: Props) {
3039
events = events.filter(Boolean).sort((a, b) => (a.ts > b.ts ? 1 : -1));
3140

3241
if (events.length > 0) {
33-
// TODO: Remove old preprocessData call
34-
// const processedDataNew = preprocessDataNew(events);
3542
const processedData = preprocessData(events);
3643
const processedFlamechart = preprocessFlamechart(events);
3744
onDataImported(processedData, processedFlamechart);
3845
}
3946
});
4047
}, []);
4148

49+
useEffect(() => {
50+
fetch(JSON_PATHV2)
51+
.then(res => res.json())
52+
.then((events: TimelineEvent[]) => {
53+
// Filter null entries and sort by timestamp.
54+
// I would not expect to have to do either of this,
55+
// but some of the data being passed in requires it.
56+
events = events.filter(Boolean).sort((a, b) => (a.ts > b.ts ? 1 : -1));
57+
58+
if (events.length > 0) {
59+
const processedData = preprocessDataV2(events);
60+
const processedFlamechart = preprocessFlamechart(events);
61+
onDataImportedV2(processedData, processedFlamechart);
62+
}
63+
});
64+
}, []);
65+
4266
return (
4367
<div>
4468
LOADING. TODO: Turn this into an import page. This page currently just

0 commit comments

Comments
 (0)