Skip to content

Commit 6b25ecd

Browse files
authored
Merge pull request #36 from MLH-Fellowship/migration-to-v2-data
Migration to V2 data
2 parents b5c3dfb + 9876341 commit 6b25ecd

3 files changed

Lines changed: 71 additions & 7 deletions

File tree

src/App.js

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

3-
import type {FlamechartData, ReactProfilerData} 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';
@@ -14,6 +18,10 @@ export default function App() {
1418
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

@@ -34,15 +42,34 @@ 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+
setProfilerDataV2(importedProfilerData);
53+
setFlamechart(importedFlamechart);
54+
});
55+
},
56+
);
57+
58+
if (profilerData && profilerDataV2 && flamechart) {
3859
return (
3960
<CanvasPage
4061
profilerData={profilerData}
62+
profilerDataV2={profilerDataV2}
4163
flamechart={flamechart}
4264
schedulerCanvasHeight={schedulerCanvasHeight}
4365
/>
4466
);
4567
} else {
46-
return <ImportPage onDataImported={handleDataImported} />;
68+
return (
69+
<ImportPage
70+
onDataImported={handleDataImported}
71+
onDataImportedV2={handleDataImportedV2}
72+
/>
73+
);
4774
}
4875
}

src/CanvasPage.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import type {
3030
ReactHoverContextInfo,
3131
ReactMeasure,
3232
ReactProfilerData,
33+
ReactProfilerDataV2,
3334
} from './types';
3435

3536
type ContextMenuContextData = {|
@@ -41,11 +42,17 @@ type ContextMenuContextData = {|
4142

4243
type Props = {|
4344
profilerData: ReactProfilerData,
45+
profilerDataV2: ReactProfilerDataV2,
4446
flamechart: FlamechartData,
4547
schedulerCanvasHeight: number,
4648
|};
4749

48-
function CanvasPage({profilerData, flamechart, schedulerCanvasHeight}: Props) {
50+
function CanvasPage({
51+
profilerData,
52+
profilerDataV2,
53+
flamechart,
54+
schedulerCanvasHeight,
55+
}: Props) {
4956
return (
5057
<div
5158
className={styles.CanvasPage}
@@ -54,6 +61,7 @@ function CanvasPage({profilerData, flamechart, schedulerCanvasHeight}: Props) {
5461
{({height, width}: {height: number, width: number}) => (
5562
<AutoSizedCanvas
5663
data={profilerData}
64+
dataV2={profilerDataV2}
5765
flamechart={flamechart}
5866
height={height}
5967
schedulerCanvasHeight={schedulerCanvasHeight}
@@ -96,6 +104,7 @@ const zoomToBatch = (
96104

97105
type AutoSizedCanvasProps = {|
98106
data: ReactProfilerData,
107+
dataV2: ReactProfilerDataV2,
99108
flamechart: FlamechartData,
100109
height: number,
101110
schedulerCanvasHeight: number,
@@ -104,6 +113,7 @@ type AutoSizedCanvasProps = {|
104113

105114
function AutoSizedCanvas({
106115
data,
116+
dataV2,
107117
flamechart,
108118
height,
109119
schedulerCanvasHeight,
@@ -117,7 +127,7 @@ function AutoSizedCanvas({
117127
canvasWidth: width,
118128
fixedColumnWidth: LABEL_FIXED_WIDTH,
119129
fixedHeaderHeight: HEADER_HEIGHT_FIXED,
120-
unscaledContentWidth: data.duration,
130+
unscaledContentWidth: dataV2.duration,
121131
unscaledContentHeight:
122132
schedulerCanvasHeight +
123133
flamechart.layers.length * FLAMECHART_FRAME_HEIGHT,

src/ImportPage.js

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

33
import type {TimelineEvent} from './speedscope/import/chrome';
4-
import type {FlamechartData, ReactProfilerData} 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';
13+
import preprocessDataV2 from './util/preprocessDataV2';
914
import preprocessFlamechart from './util/preprocessFlamechart';
1015

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

1420
type Props = {|
1521
onDataImported: (
1622
profilerData: ReactProfilerData,
1723
flamechart: FlamechartData,
1824
) => void,
25+
onDataImportedV2: (
26+
profilerData: ReactProfilerDataV2,
27+
flamechart: FlamechartData,
28+
) => void,
1929
|};
2030

21-
export default function ImportPage({onDataImported}: Props) {
31+
export default function ImportPage({onDataImported, onDataImportedV2}: Props) {
2232
useEffect(() => {
2333
fetch(JSON_PATH)
2434
.then(res => res.json())
@@ -36,6 +46,23 @@ export default function ImportPage({onDataImported}: Props) {
3646
});
3747
}, []);
3848

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+
3966
return (
4067
<div>
4168
LOADING. TODO: Turn this into an import page. This page currently just

0 commit comments

Comments
 (0)