Stream background traces to multiple RNDT sessions if present #55351
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary:
Changelog: [Internal]
Behaviour
Fixes an edge case in the way background traces are emitted when multiple RNDT frontends (or other clients with the
ReactNativeApplicationdomain enabled) are connected to a single Host. Previously, only one of the clients would receive the CDP events for the trace. With this diff, all of them will.NOTE: This leaves another, even smaller edge case / inconsistency: if there are no RNDT frontends at the time a background trace ends, we still only send it to the first frontend (if any) that connects. This is logically more defensible than picking one client out of multiple active connections ( = what's fixed in this diff).
Implementation
Tracing functionality is somewhat awkwardly split between
HostTarget(background traces) andTracingAgent(CDP-initiated traces). This diff doesn't attempt to fully clean this up[1], but we do reduce duplication and boilerplate by creating a helper function used by both. This function encapsulates the gnarly/surprising details of dealing withtracing::HostTracingProfileobjects in a memory-efficient way:[1] In future work, we should probably move the Host's tracing state and logic into its own
TracingTargetclass. The naturally close coupling of a Target with its corresponding Agent would be helpful here.Differential Revision: D90888852