-
Notifications
You must be signed in to change notification settings - Fork 6k
Add pipeline_state_observer interface #8970
Add pipeline_state_observer interface #8970
Conversation
Add a new pipeline observer interface, specified via an optionally set |std::function| on |flutter::Settings|. The callback is called by |Pipeline|, and provides information similar to what is implied by the existing pipeline flow events. The difference between the flow events and the new interface, is that this information is available at runtime even when tracing isn't enabled, and can be sent to a region of code that is able to call platform specific APIs. For example, one might want to provide this information to a system metrics API. PT-154 CF-776
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.
The overall direction seems sound. There are just a few nits and the issue with the abort not being fired. I dont see a unit-test for the pipeline. I'd appreciate if you added one to the "shell_unittests" target. But, if you dont want to set that up, file and issue for that and I'll wire it up. Thanks.
| #include "flutter/shell/common/animator.h" | ||
|
|
||
| #include "flutter/fml/trace_event.h" | ||
| #include "flutter/shell/common/pipeline.h" |
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.
How are you able to include this file here? This is in the common library which the shell depends on. This would make it a circular dependency. Did you run GN with the --check option?
|
|
||
| enum class PipelineItemStateChange { | ||
| // Indicates that a new pipeline item has started. | ||
| kBegin, |
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.
Suggestion, maybe call this kProducerBegin, kProducerEnd, kConsumerBegin, kConsumerEnd/Abort. Since this is a single producer single consumer queue, I believe that would make the enum values clearer. As you noted, kStep should not happen more than once. So let's just make the names clearer.
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.
Also, I think this Pipeline is not UI thread or GPU thread specific, as it can be used in other threads/TaskRunners, right? If so, maybe only mention UI and GPU thread as an example, and explain the high-level concept only using producer/consumer.
| // Called when pipeline items change states. See | ||
| // |Settings::pipeline_state_observer| for further details. | ||
| using PipelineStateObserver = | ||
| std::function<void(intptr_t pipeline_id, |
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.
A shell is guaranteed to have just one frame pipeline. Specifying the ID here is redundant as that information can just be associated in the std::function captures in the embedder.
| // Ensure the queue mutex is not held as that would be a pessimization. | ||
| available_.Signal(); | ||
|
|
||
| if (pipeline_state_observer_) { |
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.
I think the resource is always valid. You can probably just assert that here. I case of an aborted item, I believe that item is just dropped on the floor. So I don't actually think you will ever get an abort.
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.
If you add these state observer fire events right next to the calls to TRACE_EVENT_ASYNC BEGIN, STEP and END, you should get the right behavior.
|
Hmm, the presubmits caught the circular include. Maybe you are running this in the Fuchsia buildroot. I would have expected GN checks to be turned on there as well. In any case, if you move the typedef to the common header, it should fix the issue. |
|
cc @liyuqian |
liyuqian
left a comment
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.
I think this could be useful to monitor the pipeline items in general.
FYI, I'm also working on a frame build/raster specific API so the Flutter app can get those metrics in Dart: #8983
|
|
||
| enum class PipelineItemStateChange { | ||
| // Indicates that a new pipeline item has started. | ||
| kBegin, |
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.
Also, I think this Pipeline is not UI thread or GPU thread specific, as it can be used in other threads/TaskRunners, right? If so, maybe only mention UI and GPU thread as an example, and explain the high-level concept only using producer/consumer.
|
@nathanrogersgoogle checking as part of weekly PR review -- do you plan to address @chinmaygarde and @liyuqian 's comments and proceed with this PR? |
|
@nathanrogersgoogle looks like #8983 is merged. Do you intend to proceed with this PR? |
|
Let me review the final version of #8983 and see if any further changes are required for my use case. Will try and get back to this by tomorrow or Wednesday. |
|
Alright, I had a chance to look over #8983. I think in principle it has the information I'm looking for, however in practice even after setting |flutter::Settings::frame_rasterized_callback|, engine/shell/common/rasterizer.h Lines 30 to 33 in ae8e6d9
If that ends up requiring a Flutter engine patch, would you prefer me to upload that as a new patch set on this CL, or to start a new CL? I'm happy to do either. |
|
@nathanrogersgoogle : I think #9484 would solve your delegate problem |
Add a new pipeline observer interface, specified via an optionally set
|std::function| on |flutter::Settings|. The callback is called by
|Pipeline|, and provides information similar to what is implied by the
existing pipeline flow events. The difference between the flow events
and the new interface, is that this information is available at runtime
even when tracing isn't enabled, and can be sent to a region of code
that is able to call platform specific APIs. For example, one might
want to provide this information to a system metrics API.
PT-154
CF-776