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

Add onReportTimings and FrameRasterizedCallback API #8983

Merged
merged 2 commits into from Jun 6, 2019

Conversation

liyuqian
Copy link
Contributor

@liyuqian liyuqian commented May 16, 2019

Using it, a Flutter app can monitor missing frames in the release mode, and a custom Flutter runner (e.g., Fuchsia) can add a custom FrameRasterizedCallback.

Related issues:
flutter/flutter#26154
flutter/flutter#31444
flutter/flutter#32447

Need review as soon as possible so we can merge this before the end of May to catch the milestone.

Tests added:

  • NoNeedToReportTimingsByDefault
  • NeedsReportTimingsIsSetWithCallback
  • ReportTimingsIsCalled
  • FrameRasterizedCallbackIsCalled
  • FrameTimingSetsAndGetsProperly
  • onReportTimings preserves callback zone
  • FrameTiming.toString has the correct format

This will need a manual engine roll as the TestWindow defined in the framework needs to implement onReportTimings.

@liyuqian
Copy link
Contributor Author

CC @kenzieschmoll @devoncarew : please let me know if this helps DevTools or other IDE tools to plot the performance information (e.g., GPU thread frame raster time).

@liyuqian
Copy link
Contributor Author

liyuqian commented May 17, 2019

I'll also try to see if we can add the C++ callback API defined in #8970 and https://fuchsia-review.googlesource.com/c/topaz/+/281255/1/runtime/flutter_runner/frame_stats.cc#42

@kenzieschmoll
Copy link
Member

Two Questions:

  1. Can we guarantee that all Timeline trace events will have timestamps within the timestamps of the FrameTiming object?

In the current state of determining frame timing, we use the PipelineItem flow events to signal frame start and end, but the corresponding trace events for the frame can have timestamps outside of the flow event timestamps. For example, sometimes the VSYNC event timestamp will be before the PipelineItem start flow event.

  1. How could we access this FrameTiming object from DevTools?

@liyuqian
Copy link
Contributor Author

@kenzieschmoll : I just scheduled a meeting on Wednesday for us to discuss those questions.

@nathanrogersgoogle : please check if the API added to settings.h here looks good to you

Meanwhile, I'm still figuring out how to add uni test to best exercise this API in the engine repo.

@liyuqian
Copy link
Contributor Author

@chinmaygarde @Hixie @cbracken @nathanrogersgoogle @kenzieschmoll : since flutter/flutter#26154 has a May milestone, it would be really nice if you can start reviewing this PR soon so it can be merged before the end of May.

@@ -58,6 +59,29 @@ void ShellTest::SetSnapshotsAndAssets(Settings& settings) {
}
}

void ShellTest::PlatformViewNotifyCreated(Shell* shell) {
Copy link
Member

Choose a reason for hiding this comment

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

Good call on moving these to the fixture.

shell/common/shell_test.h Outdated Show resolved Hide resolved
shell/common/animator.h Outdated Show resolved Hide resolved
common/settings.h Outdated Show resolved Hide resolved
@@ -35,6 +35,71 @@ typedef PlatformMessageResponseCallback = void Function(ByteData data);
typedef PlatformMessageCallback = void Function(
String name, ByteData data, PlatformMessageResponseCallback callback);

/// Time-related performance metrics of a frame.
Copy link
Contributor

Choose a reason for hiding this comment

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

this needs much more documentation. For example, how to get one of these, whether it makes sense to examine the data at all in debug mode, what it measures, etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a little more documentation. I'll continue to add more once I come up with other topics while polishing this PR.

@Hixie
Copy link
Contributor

Hixie commented May 21, 2019

Can we disable all this logic in the case where the callback isn't set?

@liyuqian liyuqian changed the title Add onReportTimings API from engine to framework Add onReportTimings and FrameRasterizedCallback API May 21, 2019

// TODO(liyuqian): in Fuchsia, the rasterization doesn't finish when
// Rasterizer::DoDraw finishes. Future work is needed to adapt the timestamp
// for Fuchsia.
Copy link
Contributor

Choose a reason for hiding this comment

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

What extra work after |Rasterizer::DoDraw| are you referring to specifically? Are you talking about the GPU work (as opposed to the CPU "GPU thread" work in Flutter)? What does the future work you mention here look like? In some Fuchsia traces I had lying around, the GPU thread's work (covered by the "GPURasterizer::Draw") does nearly end with |Rasterizer::DoDraw| (there's just a couple of microseconds after it). If I'm understanding this correctly, I'd be happy to clarify that this is just Flutter GPU thread work here, and have the burden of measuring GPU work be on Flutter runner.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right that Rasterizer::DoDraw and Rasterizer::Draw (which adds GPURasterizer::Draw tracing) are approximately equal. The extra work I referred was SceneUpdateContext::ExecutePaintTasks in scene_update_context.cc. I've added this info to the code comment.

@liyuqian liyuqian requested review from mehmetf and removed request for kenzieschmoll May 22, 2019 22:48
Copy link
Contributor Author

@liyuqian liyuqian left a comment

Choose a reason for hiding this comment

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

Thank you all @Hixie @chinmaygarde @nathanrogersgoogle for your comments! I've updated the PR accordingly. Please check if I missed something.

lib/stub_ui/lib/src/ui/window.dart Outdated Show resolved Hide resolved
lib/stub_ui/lib/src/ui/window.dart Outdated Show resolved Hide resolved
lib/stub_ui/lib/src/ui/window.dart Outdated Show resolved Hide resolved
lib/stub_ui/lib/src/ui/window.dart Outdated Show resolved Hide resolved
lib/ui/window.dart Show resolved Hide resolved
@@ -35,6 +35,71 @@ typedef PlatformMessageResponseCallback = void Function(ByteData data);
typedef PlatformMessageCallback = void Function(
String name, ByteData data, PlatformMessageResponseCallback callback);

/// Time-related performance metrics of a frame.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a little more documentation. I'll continue to add more once I come up with other topics while polishing this PR.

common/settings.h Outdated Show resolved Hide resolved
shell/common/shell_test.h Outdated Show resolved Hide resolved
shell/common/animator.h Outdated Show resolved Hide resolved

// TODO(liyuqian): in Fuchsia, the rasterization doesn't finish when
// Rasterizer::DoDraw finishes. Future work is needed to adapt the timestamp
// for Fuchsia.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right that Rasterizer::DoDraw and Rasterizer::Draw (which adds GPURasterizer::Draw tracing) are approximately equal. The extra work I referred was SceneUpdateContext::ExecutePaintTasks in scene_update_context.cc. I've added this info to the code comment.

@liyuqian liyuqian force-pushed the report_timings branch 2 times, most recently from 9ec8c6e to fd57ac2 Compare May 24, 2019 04:16
@@ -26,11 +26,17 @@ class ShellTest : public ThreadTest {
~ShellTest();

Settings CreateSettingsForFixture();

std::unique_ptr<Shell> CreateShell(Settings&& settings);
Copy link
Member

Choose a reason for hiding this comment

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

Both the settings and the task runners are copyable and movable. You can get rid of the double &.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// The engine might have been destructed in ~Shell while the rasterizer is
// still alive and calling this from OnFrameRasterized.
if (!engine_) {
Copy link
Member

Choose a reason for hiding this comment

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

This condition is not possible as the destruction of the shell will only happen after the engine is destroyed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this racy access to unique_ptr<Engine> engine_ on the GPU thread, and modified GetEngine as we discussed.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks. Updates look safe.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is this the renewed LGTM? 😄

Copy link
Member

Choose a reason for hiding this comment

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

Oh. Sorry. Yeah :)

Using it, a Flutter app can monitor missing frames in the release mode, and a custom Flutter runner (e.g., Fuchsia) can add a custom FrameRasterizedCallback.

Related issues:
flutter/flutter#26154
flutter/flutter#31444
flutter/flutter#32447

Need review as soon as possible so we can merge this before the end of May to catch the milestone.

Tests added:
* NoNeedToReportTimingsByDefault
* NeedsReportTimingsIsSetWithCallback
* ReportTimingsIsCalled
* FrameRasterizedCallbackIsCalled
* FrameTimingSetsAndGetsProperly
* onReportTimings preserves callback zone
* FrameTiming.toString has the correct format

This will need a manual engine roll as the TestWindow defined in the framework needs to implement onReportTimings.
@liyuqian liyuqian merged commit 9f088c6 into flutter:master Jun 6, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 6, 2019
liyuqian added a commit to liyuqian/flutter that referenced this pull request Jun 6, 2019
This will manually land flutter/engine#8983 in
the framework.
liyuqian added a commit to flutter/flutter that referenced this pull request Jun 6, 2019
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Jun 6, 2019
liyuqian added a commit that referenced this pull request Jun 7, 2019
This will catch failure early for cases like #9216 (which fixes manual roll for #8983).
@liyuqian liyuqian deleted the report_timings branch June 10, 2019 22:15
huqiuser pushed a commit to huqiuser/engine that referenced this pull request Jun 12, 2019
Using it, a Flutter app can monitor missing frames in the release mode, and a custom Flutter runner (e.g., Fuchsia) can add a custom FrameRasterizedCallback.

Related issues:
flutter/flutter#26154
flutter/flutter#31444
flutter/flutter#32447

Need review as soon as possible so we can merge this before the end of May to catch the milestone.

Tests added:
* NoNeedToReportTimingsByDefault
* NeedsReportTimingsIsSetWithCallback
* ReportTimingsIsCalled
* FrameRasterizedCallbackIsCalled
* FrameTimingSetsAndGetsProperly
* onReportTimings preserves callback zone
* FrameTiming.toString has the correct format

This will need a manual engine roll as the TestWindow defined in the framework needs to implement onReportTimings.
huqiuser pushed a commit to huqiuser/engine that referenced this pull request Jun 12, 2019
This will catch failure early for cases like flutter#9216 (which fixes manual roll for flutter#8983).
kiku-jw pushed a commit to kiku-jw/flutter that referenced this pull request Jun 14, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
8 participants