perfetto icon indicating copy to clipboard operation
perfetto copied to clipboard

Opening chrome://tracing JSON format traces

Open jaywonchung opened this issue 4 years ago • 8 comments

Hi,

I was wondering if it would be possible to use the Perfetto UI to open the JSON traces that I used to open with chrome://tracing. The JSON traces are in the format described by this document and works perfectly with chrome://tracing, but when I open it with the Perfetto UI, it only displays an empty timeline.

Thanks in advance.

jaywonchung avatar Oct 21 '22 22:10 jaywonchung

Yes it is supported but on a best effort basis. Feel free to attach a trace which is not working and we'll look into why and fix if possible.

LalitMaganti avatar Oct 21 '22 23:10 LalitMaganti

{
    "schemaVersion": 1,
    "traceEvents": [
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "c10d::barrier",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382280874284,
            "dur": 1567655,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 1
            }
        },
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "record_param_comms",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382280874291,
            "dur": 1567647,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 2
            }
        },
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "aten::empty",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382280874333,
            "dur": 956319,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 3
            }
        },
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "record_param_comms",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382281830683,
            "dur": 611252,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 4
            }
        },
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "record_param_comms",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382281830685,
            "dur": 611248,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 5
            }
        },
        {
            "ph": "X",
            "cat": "user_annotation",
            "name": "nccl:all_reduce",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382282441741,
            "dur": 183,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 6
            }
        },
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "record_param_comms",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382282442058,
            "dur": 52,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 7
            }
        },
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "c10d::barrier",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382282442248,
            "dur": 93,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 8
            }
        },
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "record_param_comms",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382282442251,
            "dur": 89,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 9
            }
        },
        {
            "ph": "X",
            "cat": "cpu_op",
            "name": "aten::empty",
            "pid": 694985,
            "tid": 694985,
            "ts": 1666382282442255,
            "dur": 21,
            "args": {
                "Trace name": "PyTorch Profiler",
                "Trace iteration": 0,
                "External id": 10
            }
        }
    ],
    "traceName": "sample.json"
}

Thanks. I just took ten events from a big trace from the PyTorch profiler. The Perfetto UI still displays an empty timeline (Navigated to https://ui.perfetto.dev/ on Chrome and selected the JSON trace in "Open Trace File").

jaywonchung avatar Oct 21 '22 23:10 jaywonchung

https://android-review.googlesource.com/c/platform/external/perfetto/+/2266043 fixes this.

LalitMaganti avatar Oct 22 '22 00:10 LalitMaganti

Awesome. After the patch makes it into master, is there a quick way to try it out? I'd imagine it to take some time to be published as either canary or stable.

jaywonchung avatar Oct 22 '22 01:10 jaywonchung

There is an autopush channel that you can select via Support->Flags in the left hand menu of the Perfetto UI, that will reflect the change as soon as it gets submitted.

If you're in a hurry, you can already try the (temporary) UI version produced by the presubmit build: https://storage.googleapis.com/perfetto-ci-artifacts/20221022001553--cls-2266043-1--ui-clang-x86_64-release/ui/index.html

rsavitski avatar Oct 22 '22 14:10 rsavitski

Thanks! I tried out the presubmit build and it works perfectly for the original 250MB JSON trace that I have.

One small glitch is that JSON parsing fails with a "Failure parsing JSON: unknown data type in trace file for key deviceProperties" error when the trace has the "deviceProperties" key (added in by the PyTorch profiler). It looks like this:

{
    "schemaVersion": 1,
    "deviceProperties": [
        {
            "id": 0,
            "name": "NVIDIA A40",
            "totalGlobalMem": 47641198592,
            "computeMajor": 8,
            "computeMinor": 6,
            "maxThreadsPerBlock": 1024,
            "maxThreadsPerMultiprocessor": 1536,
            "regsPerBlock": 65536,
            "regsPerMultiprocessor": 65536,
            "warpSize": 32,
            "sharedMemPerBlock": 49152,
            "sharedMemPerMultiprocessor": 102400,
            "numSms": 84,
            "sharedMemPerBlockOptin": 101376
        },
        {
            "id": 1,
            "name": "NVIDIA A40",
            "totalGlobalMem": 47641198592,
            "computeMajor": 8,
            "computeMinor": 6,
            "maxThreadsPerBlock": 1024,
            "maxThreadsPerMultiprocessor": 1536,
            "regsPerBlock": 65536,
            "regsPerMultiprocessor": 65536,
            "warpSize": 32,
            "sharedMemPerBlock": 49152,
            "sharedMemPerMultiprocessor": 102400,
            "numSms": 84,
            "sharedMemPerBlockOptin": 101376
        },
    ],
    "traceEvents": [],
    "traceName": "sample.json"
}

I believe the Perfetto JSON parser can simply ignore keys that it does not recognize, since they are extra metadata:

Any other properties seen in the object, in this case otherData are assumed to be metadata for the trace. They will be collected and stored in an array in the trace model. This metadata is accessible through the Metadata button in Trace Viewer. (From the Chrome Trace format spec)

jaywonchung avatar Oct 22 '22 15:10 jaywonchung

Updated https://android-review.googlesource.com/c/platform/external/perfetto/+/2266043 to hande this.

LalitMaganti avatar Oct 24 '22 13:10 LalitMaganti

I tried out the autopush channel and I can confirm that 93f5bb8 fixed the problems mentioned in this issue. Thanks a lot for your help!

jaywonchung avatar Oct 24 '22 17:10 jaywonchung