-
Notifications
You must be signed in to change notification settings - Fork 617
ui: encapsulate Perfetto UI start-up in a new API class #3275
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
Draft
cdamus
wants to merge
1
commit into
google:main
Choose a base branch
from
eclipsesource:feature/ui-frontend-api
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # Frontend Main API | ||
|
|
||
| This document provides an overview of the `Frontend` API in Perfetto UI, as defined in [`ui/src/frontend/frontend.ts`](../../ui/src/frontend/frontend.ts). | ||
| This API is the main application entry-point for the Perfetto UI and may be used by host (embedding) applications to customize various aspects of Perfetto UI's behavior, especially for advanced integration scenarios. | ||
|
|
||
| ## Overview | ||
|
|
||
| The `Frontend` class provides for the main start-up sequence of the Perfetto UI. | ||
| The various steps in this sequence are factored out into protected API methods that a host application can extend or override to control or redefined specific Perfetto UI behaviors. | ||
| The primary intended use case is in applications that take care of such concerns as acquiring and managing Perfetto traces but wish to reuse/embed the Perfetto UI for presentation of those traces to the user. | ||
|
|
||
| When a host application creates and starts the `Frontend`, it must be sure to do this *before* the main [Perfetto UI module](../../ui/src/frontend/index.ts) is loaded or, better, ensure that that main module is not loaded at all as it would not be needed. | ||
|
|
||
| Host applications can specialize the `Frontend` to customize the following aspects of the Perfetto UI app: | ||
|
|
||
| - **Custom Error Handling**: Suppress Perfetto UI's internal error handling, deferring to whatever the host application does in that regard. | ||
| - **UI Rendering Control**: Prevent the start-up of the Perfetto UI app from rendering its main interface, allowing the host application can selectively instantiate components. | ||
| - **Content Security Policy Strategy**: Customization of how the CSP is installed in the application, with optional filtering of the rules. | ||
| - **Storage Customization**: Prefix cache storage keys for coexistence with other applications' caches and for certain application frameworks' restrictions. | ||
| - **Routing Hooks**: Intercept or override URL navigation and route handling. | ||
| - **Custom PostMessage Handling**: Process unrecognized messages posted to the window. | ||
| - **Preloaded Trace Handling**: Indicate how Perfetto should deal with traces pre-loaded in the trace processor backend. | ||
| - **App State Restoration**: Delegate Perfetto app state persistence to the host application. | ||
|
|
||
| ### Example | ||
|
|
||
| Suppose you have an application integrating Perfetto: | ||
|
|
||
| ```typescript | ||
| // perfetto-setup.ts | ||
| import type {AppImpl} from 'perfetto/ui/dist/core/app_impl'; | ||
| import {Frontend} from 'perfetto/ui/dist/frontend/frontend'; | ||
|
|
||
| export class MyFrontend extends Frontend { | ||
| override protected installErrorHandlers(): void { | ||
| // I do my own error handling | ||
| } | ||
|
|
||
| override protected mountMainUI(): Disposable { | ||
| // I instantiate the UI at my own place in the DOM | ||
| return { | ||
| [Symbol.dispose]: () => {}, | ||
| }; | ||
| } | ||
|
|
||
| override protected createApp(args: AppInitArgs): AppImpl { | ||
| return super.createApp({ | ||
| ...args, | ||
| // Don't get initial route args from the window location | ||
| initialRouteArgs: {}, | ||
| }); | ||
| } | ||
|
|
||
| // ... other overrides | ||
|
|
||
| override start(): Promise<void> { | ||
| // Set a custom cache prefix for my application | ||
| setCachePrefix('https:/'); | ||
| return super.start(); | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| Then, in your application entrypoint: | ||
|
|
||
| ```typescript | ||
| // index.ts | ||
| import {MyFrontend} from './perfetto-setup'; | ||
|
|
||
| // ... | ||
|
|
||
| await new MyFrontend().start(); // Initialize the Perfetto UI | ||
| ``` | ||
|
|
||
| This ensures correct initialization of Perfetto's frontend with your application's customizations. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
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.
Could you share your
Frontendimplementation? I'd be interested to see what parts of the code you override and what you keep. In essence, it'd be interesting to see what your embeddability requirements are so I can get a better understanding of your challenges.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.
My application is not open-source so I cannot post code here, but perhaps there are other ways. I shall follow that up.
At any rate, we do customize every one of the extension points currently defined in the
Frontendclass (and previously in theEmbedderContext) as otherwise they wouldn't be defined. And for the most part the customizations address three peculiarities of our application as compared to the SPA deployment of Perfetto UI:window— especially dealing with location, navigation, and messaging — are different to how an SPA like Perfetto UI would operate and they are the responsibility of the framework on which our application is built