-
Notifications
You must be signed in to change notification settings - Fork 0
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
[Optimize flamechart][1/4] Add flamechart to ReactProfilerData #90
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,11 @@ | ||
// @flow | ||
|
||
import {importFromChromeTimeline, Flamechart} from '@elg/speedscope'; | ||
import type {TimelineEvent} from '@elg/speedscope'; | ||
import type { | ||
Milliseconds, | ||
BatchUID, | ||
FlamechartData, | ||
ReactLane, | ||
ReactMeasureType, | ||
ReactProfilerData, | ||
|
@@ -345,18 +347,34 @@ function processTimelineEvent( | |
} | ||
} | ||
|
||
function preprocessFlamechart(rawData: TimelineEvent[]): FlamechartData { | ||
const parsedData = importFromChromeTimeline(rawData, 'react-devtools'); | ||
const profile = parsedData.profiles[0]; // TODO: Choose the main CPU thread only | ||
const flamechart = new Flamechart({ | ||
getTotalWeight: profile.getTotalWeight.bind(profile), | ||
forEachCall: profile.forEachCall.bind(profile), | ||
formatValue: profile.formatValue.bind(profile), | ||
getColorBucketForFrame: () => 0, | ||
}); | ||
return flamechart; | ||
} | ||
|
||
export default function preprocessData( | ||
timeline: TimelineEvent[], | ||
): ReactProfilerData { | ||
const profilerData = { | ||
const flamechart = preprocessFlamechart(timeline); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Might wanna remove this extra line for no reason. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This empty line was intentional as I want to separate the profiler data declaration that belongs to the rest of this function from the flamechart computation. Imo they're doing different things conceptually so they should be in separate "paragraphs" |
||
const profilerData: ReactProfilerData = { | ||
startTime: 0, | ||
duration: 0, | ||
events: [], | ||
measures: [], | ||
flamechart, | ||
}; | ||
|
||
// TODO: Sort `timeline`. JSON Array Format trace events need not be ordered. See: | ||
// Sort `timeline`. JSON Array Format trace events need not be ordered. See: | ||
// https://docs.google.com/document/d/1CvAClvFfyA5R-PhYUmn5OOQtYMH4h6I0nSsKchNAySU/preview#heading=h.f2f0yd51wi15 | ||
timeline = timeline.filter(Boolean).sort((a, b) => (a.ts > b.ts ? 1 : -1)); | ||
|
||
// Events displayed in flamechart have timestamps relative to the profile | ||
// event's startTime. Source: https://github.com/v8/v8/blob/44bd8fd7/src/inspector/js_protocol.json#L1486 | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is from #89's commit, that's also in this PR.
@kartikcho I'll be trying to rebase merge this PR, to see if #89's commit will appear twice on master (let's hope it doesn't). If #89's commit appears twice, I'll force push to the remaining PRs in this stack before merging them, to prevent polluting master.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: Only one commit appeared on master :D We're all good