Skip to content

Add "Load all CPU samples" button to the CPU profiler - #2943

Merged
kenzieschmoll merged 8 commits into
flutter:masterfrom
kenzieschmoll:profiler
May 20, 2021
Merged

kenzieschmoll merged 8 commits into
flutter:masterfrom
kenzieschmoll:profiler

Conversation

@kenzieschmoll

@kenzieschmoll kenzieschmoll commented Apr 26, 2021 •

Copy link
Copy Markdown
Member

Screen Shot 2021-04-26 at 3 39 41 PM

This will allow for profiling app start, since clicking this button pulls all the available CPU samples the VM has access to.

This CL also refactors some of the cpu profiler code to use widgets instead of helper methods

@kenzieschmoll
kenzieschmoll requested a review from jacob314 April 26, 2021 22:47
return Row(
mainAxisAlignment: MainAxisAlignment.end,
children: [
RefreshButton(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Fyi @InMatrix. I'm not sure users will understand what "Load all CPU samples" does. Any ideas for a detailed tooltip and/or an alternate name that makes it clearer?
This is basically the refresh button from the Performance page but in addition to the existing record and pause buttons. What we are trying to say is.
"The VM already has N seconds of recorded CPU profile samples in a buffer of recent activity. Display that data on this page?"

@InMatrix InMatrix Apr 27, 2021 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Do we expect this button to be used for debugging slow app start only? If that's the case, maybe giving it a name that reflects the user's goal, something like "Load samples from app start," and limit how much data is loaded (e.g., anything before first user interaction).

"The VM already has N seconds of recorded CPU profile samples in a buffer of recent activity. Display that data on this page?"

I wonder if the data would be misleading if the earliest available sample doesn't go all the way back to the app's start. For example, if the user clicks this button 10 minutes after they started their app, is there any guarantee that they'll still have samples from the start? Can we show timestamps relative to the app start time?

@kenzieschmoll kenzieschmoll Apr 27, 2021 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

if the user clicks this button 10 minutes after they started their app, is there any guarantee that they'll still have samples from the start?

No, there is not. And if the user was actually interacting with their app, it's almost certain that we will not have samples from app start.

Can we show timestamps relative to the app start time?

This would be possible if we had a way to access the timestamp of app start. We could probably get close by taking the timestamp of the first timeline event we have, but that wouldn't be entirely accurate. @bkonyi do you know how we could get the timestamp of app start?

What if the button said "Load all available data" and then the tooltip said something more detailed like, "Load all CPU profile samples available in the VM sample buffer. This will include CPU samples from app start if this button is clicked immediately after your app finishes startup."

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

What's sufficient for a "timestamp" in this case? getVMTimelineMicros returns the approximate time the VM has been running in microseconds.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is there a use case for loading all available data after the data from app start is gone? If this button won't be useful in that situation, it's probably better to disable that and show a tooltip explaining the intended workflow.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

As a temporary solution while we finalize a more robust design using DDS, I'd like to change the button text to "Profile app startup", and manually request a profile in DevTools from time 0 to the timestamp of the Flutter.FirstFrame event. This runs the risk that samples in that timeframe will not be available, and if that happens, we can show a description for why that is. When we move to a more robust solution, this problem will go away, but this could give users something to work with for now.

For Dart CLI apps, we can request the first 30 seconds or just not show the button.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Running into another problem here where the Flutter.Frame and Flutter.FirstFrame event timestamps don't match the timestamps that the VM uses for timeline events and CPU samples. @bkonyi @jonahwilliams ideas for ways around this?

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Is this another case where having frame number of the CPU traces themselves would solve the problem?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

If we had a 0-based or 1-based frame numbering system, then we could look for the 0th or 1st frame. If we couldn't guarantee what the first frame number would be, then this wouldn't work, but if we can, then that would solve it.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

FWIW this is landing here: flutter/flutter#82934

@jacob314 jacob314 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@kenzieschmoll

Copy link
Copy Markdown
Member Author

I'm going to land this PR as a temporary solution to this use case. Once @bkonyi has completed the necessary work in DDS I will work on the improved implementation for profiling app start.

@kenzieschmoll
kenzieschmoll merged commit 398b99d into flutter:master May 20, 2021
@kenzieschmoll
kenzieschmoll deleted the profiler branch May 20, 2021 18:58
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.

5 participants