google / perfetto

Performance instrumentation and tracing for Android, Linux and Chrome (read-only mirror of https://android.googlesource.com/platform/external/perfetto/)

Home Page:https://www.perfetto.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Best way to open a trace file in the UI programmatically?

jacobdweightman opened this issue · comments

I'd like to use the Perfetto UI to visualize traces automatically through an IDE extension. I'm able to generate a JSON file with the trace events I'm interested in, and I'm able to automatically open up ui.perfetto.dev in my browser.

However, I haven't found a straightforward way to open the trace file programmatically — for example, is it possible to pass the file path as a query parameter? The behavior I'm looking for would be as if the user had clicked "open trace file" from the sidebar and selected a file, but without those manual steps.

If this isn't currently possible but would be accepted as a contribution, please suggest next steps.

Have a look at this script which allows opening a trace from the command line: https://github.com/google/perfetto/blob/master/tools/open_trace_in_ui

You can use it directly or adapt it to your needs.

Thanks, this works for me. It seems that it isn't possible to do this without an HTTP server to serve up the file — is that correct?

Yes that's correct. Due to security, web pages are not able to access the filesystem directly without explicit user selection (this is not restricted to the Perfetto UI but really to any website).

Yep browsers forbid that.
Imagine for a moment if you could just follow a linke like http://evil.com?file=~/.gitcookies and the browser allowed that action to pass through the file without an user UI interaction (file picker). Would be quite bad :)
For the same reason you can't just pass a trace file path in the URL in the Perfetto UI

Fair enough. I thought perhaps it would be possible to include the file contents in the request, but that would require sending the file to your server. Then I thought perhaps it would be possible to send the file to the web page over a socket or WebRTC, but that's not any simpler than spinning up an HTTP server. I wondered if perhaps you had some other clever solution.

At the end of the day, the only problem I have with the local HTTP server is that now I'm on the hook to configure it securely — which isn't that big of a deal. If perfetto.dev were to start acting like this ominous sounding evil.com, nothing should be compromised. 😈