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

Cache CPU profiles for selected frames #3121

Merged
merged 4 commits into from
Jun 14, 2021

Conversation

kenzieschmoll
Copy link
Member

This will prevent users from losing CPU profile data for frames they have already selected. We have seen users in user studies hit problems with CPU samples falling out of the CPU sample buffer.

We now cache profiles with their respective frames in the performance page. For timeline events within that frame, we will generate a sub profile from the frame's cached profile upon selection.

This PR also improves the performance of the CPU profiler by caching the callTreeRoots and bottomUpRoots for an instance of CpuProfileData.

This will improve #2631

@kenzieschmoll kenzieschmoll requested a review from jacob314 June 11, 2021 22:12
@@ -61,6 +61,8 @@ class PerformanceController
ValueListenable<List<FlutterFrame>> get flutterFrames => _flutterFrames;
final _flutterFrames = ValueNotifier<List<FlutterFrame>>([]);

final _flutterFramesById = <String, FlutterFrame>{};
Copy link
Member Author

Choose a reason for hiding this comment

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

The changes in this file are duplicated from performance/legacy/performance_controller.dart. These two files will diverge soon once the files under performance/ are migrated to use the FrameTiming API for flutter frames, though changes like this will continue to need to be applied to both files until the changes we need to use the FrameTiming API hit flutter stable.

_store[time] = profile;
}

void _maybeGenerateSubProfile(TimeRange time) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: this is generating a bunch of overlapping profiles in the cache. That would make it a bit harder to later serialize this. Is computing the sub profiles expensive enough that it worth it to add completely overlapping ranges to the cache. It makes sense we will need some overlap as frames overlap but having completely overlapping entries seems a little odd.

Copy link
Member Author

Choose a reason for hiding this comment

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

when a sub profile is generated, it has to be created (not expensive) and then processed - this is the expensive part. So if we don't cache each subprofile, there will be processing cost for each time we have to regenerate the sub profile from a super profile.

Copy link
Contributor

@jacob314 jacob314 left a comment

Choose a reason for hiding this comment

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

lgtm

@kenzieschmoll kenzieschmoll merged commit 870f4e3 into flutter:master Jun 14, 2021
@kenzieschmoll kenzieschmoll deleted the profile-for-frame branch June 14, 2021 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants