javascripttraceperfetto

How to open a chrome trace file with ui.perfetto.dev non interactively?


I generate chrome trace files and with to open them non interactively from a script. However, I do not want to use the default chrome://tracing page, instead I use https://ui.perfetto.dev which I find much more convenient.

The only problem is that it is an interactive process - I need to open the file dialog and select the trace file from there, then the traces in that file are displayed. There is no network traffic here, purely Javascript.

But maybe there is another way to open trace files in https://ui.perfetto.dev that can be scripted? Or maybe there is another site that gives the same kind of GUI, but also satisfies my requirement?

By scripting I mean I want to run a script with a trace file and as a result the default browser opens with the tracing page.


Solution

  • Look at what tools/record_android_trace does here: https://github.com/google/perfetto/blob/master/tools/record_android_trace#L345

    Essentially you can achieve that by:

    1. Serving the file over HTTP (it MUST be port 9001 to satisfy ui.perfetto.dev Content Security Oolicy)

    2. Open https://ui.perfetto.dev/#!/?url=http://127.0.0.1:9001/file.trace

    The url= argument will cause the UI code to automatically fetch the trace from your local web server. You can kill it soon after the GET request is done.