Overlapping events in same thread display incorrectly
I am using v31.0-49206383f, but I also see the issue canary v31.0-72e9c123b.
If I open the file in chrome://tracing the start and duration stats look correct (albeit the display is not ideal).
I have significantly reduced the size of the JSON file, but the problem still persists.
You will see in the full JSON that Event6 has the following entries:
{
"name": "Event6",
"ph": "B",
"pid": 2,
"tid": 14,
"ts": 209948
},
{
"ph": "E",
"pid": 2,
"tid": 14,
"ts": 210012
},
So should have a duration of 64. However, looking at the trace, I see the follow:

Event5 also looks wrong: it should have duration 283, but has duration 322. The rest of the event durations look fine.
The full JSON:
[
{
"name": "Event1",
"ph": "B",
"pid": 2,
"tid": 13,
"ts": 0
},
{
"ph": "E",
"pid": 2,
"tid": 13,
"ts": 104562
},
{
"name": "Event2",
"ph": "B",
"pid": 2,
"tid": 13,
"ts": 104562
},
{
"ph": "E",
"pid": 2,
"tid": 13,
"ts": 209124
},
{
"name": "Event3",
"ph": "B",
"pid": 2,
"tid": 14,
"ts": 209124
},
{
"ph": "E",
"pid": 2,
"tid": 14,
"ts": 209407
},
{
"name": "Event4",
"ph": "B",
"pid": 2,
"tid": 15,
"ts": 209407
},
{
"ph": "E",
"pid": 2,
"tid": 15,
"ts": 209690
},
{
"name": "Event5",
"ph": "B",
"pid": 2,
"tid": 14,
"ts": 209690
},
{
"ph": "E",
"pid": 2,
"tid": 14,
"ts": 209973
},
{
"name": "Event6",
"ph": "B",
"pid": 2,
"tid": 14,
"ts": 209948
},
{
"ph": "E",
"pid": 2,
"tid": 14,
"ts": 210012
},
{
"name": "Event7",
"ph": "B",
"pid": 2,
"tid": 14,
"ts": 210012
},
{
"ph": "E",
"pid": 2,
"tid": 14,
"ts": 210033
},
{
"name": "Event8",
"ph": "B",
"pid": 2,
"tid": 14,
"ts": 210033
},
{
"ph": "E",
"pid": 2,
"tid": 14,
"ts": 210054
},
{
"name": "Event9",
"ph": "B",
"pid": 2,
"tid": 13,
"ts": 210054
},
{
"ph": "E",
"pid": 2,
"tid": 13,
"ts": 210193
}
]
Hi. We don't support overlapping events in JSON traces. I added a change to our FAQ mentioning this.
Couple of clarifications:
- this is not our choice: we simply are following the JSON tracing spec which bans overlapping B/E/X events. chrome://tracing happened to display something half reasonable but this behaviour was not well defined
- As well as switching to emitting our native proto format, you can also use b/e events in JSON which do support overlaps.
Thanks for the quick response!
I tried using async events (b/e events), but the output was not desirable; it gave me one row per 'id' field. I guess I could do some analysis to assign incrementing IDs based on overlap with other kernels, but that is kind of yucky.
I will try out the protobuf. Will I (eventually) find the docs here?
I think there are ways around having one row per id (the spec talks about this I believe) but it's surely not as flexible as emitting protobuf.
As for docs, there's a internal bug assigned to me where I need to write up how you can manually protos. In the mean time, consider reading https://perfetto.dev/docs/instrumentation/track-events and https://github.com/google/perfetto/issues/423 where I gave advice on how JSON events correspond to proto events.
I will try out the protobuf. Will I (eventually) find the docs here?
That's definitely not the right place to look - pie-gsi is the branch of Android from Android P which was released ~5 years ago :)
Thanks!
A lot of the examples I found were for visualizing the application when run. I am using the view to display how some MLIR might run: static performance analysis. So the examples don't do much for me.
I think there are ways around having one row per id (the spec talks about this I believe)
I will try to figure this out and if I find some time try to integrate the SDK and use protobufs.
I wouldn't use the SDK if you're writing static analysis tools. The SDK is intended for actually running applications. Instead I'd emit protos directly.