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

core(tracehouse): use tasks to improve profiler timing data #11446

Merged
merged 5 commits into from
Oct 19, 2020

Conversation

patrickhulce
Copy link
Collaborator

@patrickhulce patrickhulce commented Sep 17, 2020

Summary
The next phase of CPU profiler work got really out of hand really quickly, so stopping at a reasonable checkpoint. This PR improves the timing of sampling profiler data using other task information from a trace. The sampling profiler is still out of the normal flow of Lighthouse, so the test cases are the only actual usage.

Also a nice juicy debug function for task data which should help generate those nice "artistic" rendering of traces :)

Related Issues/PRs
ref #8526

* @param {{printWidth: number, startTime?: number, endTime?: number, taskLabelFn?: (node: TaskNode) => string}} options
* @return {string}
*/
static printTaskTreeToDebugString(tasks, options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

its not the biggest function but i'm wondering if we should put this (and our other debug-only functions) in separate modules to we can easily exclude them from our browserify bundles....

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My initial impression is that it doesn't seem worth it to move away from the place that the debugging helps, but a followup for relocating all of our debugging utils sgtm

lighthouse-core/lib/tracehouse/cpu-profile-model.js Outdated Show resolved Hide resolved
@@ -65,6 +65,40 @@ describe('CPU Profiler Model', () => {
]);
});

it('should create events while aware of other tasks', () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sweet thanks, when we get to the skipped sample logic we'll definitely incorporate those 👍

* @param {{earliestPossibleTimestamp: number, latestPossibleTimestamp: number, lastKnownTaskStartTimeIndex: number, lastKnownTaskEndTimeIndex: number, knownTasksByStartTime: Array<{startTime: number, endTime: number}>, knownTasksByEndTime: Array<{startTime: number, endTime: number}>}} data
* @return {{timestamp: number, lastStartTimeIndex: number, lastEndTimeIndex: number}}
*/
_findEffectiveTimestamp(data) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's some decent complexity here and i feel odd having it untested.

i'm wondering if we could test this more clearly with some dedicated _findEffectiveTimestamp() unit tests or doing it higher up at either the cpu profiler model level or the main thread tasks level

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing it higher up at either the cpu profiler model level or the main thread tasks level

that's exactly what the unit test added in this PR does ;)

I can add explicit unit tests for this private method as well if you think the current cases aren't sufficient 👍

* @param {Array<{startTime: number, endTime: number}>} knownTasks
* @param {{type: 'startTime'|'endTime', lastKnownTaskIndex: number, earliestPossibleTimestamp: number, latestPossibleTimestamp: number}} options
*/
_getTasksInRange(knownTasks, options) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, personal taste, but i figure these helper methods are better if defined after their use. makes reading the file (or reviewing) from top to bottom a little more straightforward.

Copy link
Collaborator Author

@patrickhulce patrickhulce Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would you like all of them moved or just the new ones? I'm a little concerned about muddying the diff with a move of all private methods here (and a little concerned about the consistency if we only move the new ones)

knownTasksByEndTime,
});

profilerTimestamp += timeDelta;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we mutate this one? seems odd that it would be changing but maybe i'm misunderstanding its use.

Copy link
Collaborator Author

@patrickhulce patrickhulce Oct 8, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is just a rename of the old timestamp which is the raw timestamp of a sample as reported by the profiler's timeDeltas, but it sounds like the new name made that less clear to you :)

currentProfilerTimestamp
currentTimestampAsReportedByProfiler
rawTimestamp
currentRawTimestamp

like any of those better?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

went with currentProfilerTimestamp

Co-authored-by: Paul Irish <paulirish@google.com>
@paulirish paulirish merged commit 8095bec into master Oct 19, 2020
@paulirish paulirish deleted the cpu_profiler_task_conflicts_part_a branch October 19, 2020 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants