$ olly trace --format=json trace.json ./prog
$ python3 -c "import json; json.load(open('trace.json'))"
json.decoder.JSONDecodeError: Expecting value: line 482 column 1
$ tail -c 30 trace.json
"pid": 0, "tid": 0},
The array is never closed. create writes [ and close just closes the channel (olly_format_json.ml:9-12). That is a permitted variant of the Chrome Trace Event Format, where the trailing ] is optional and the Trace Viewer adds it, to support producers that cannot cleanly finish writing. olly writes to a file and has a close function, so it is not one of those producers and could simply emit the bracket.
Every event ends with a comma, including the last (olly_format_json.ml:20). That is the part that bites: appending ] by hand still does not parse, and the format documentation notes that trailing commas may throw off Chrome. So the fix is not a single character. Writing the separator before each event except the first, then ] on close, covers both.
The effect is that anything wanting to post-process a trace needs its own parser rather than the JSON library it already has. Perfetto and Chrome load the file fine, so this only shows up once someone tries to do something with a trace programmatically.
Unrelated but in the same file: ts_to_us converts the nanosecond runtime_events timestamp to microseconds by integer division, so any span shorter than a microsecond is recorded as zero width. gc-stats reports pause latencies to 0.01 ms, and the trace cannot represent the short end of that distribution at all. Worth checking whether a fractional ts is acceptable to the viewers before changing it, since the format documents microsecond granularity.
The array is never closed.
createwrites[andclosejust closes the channel (olly_format_json.ml:9-12). That is a permitted variant of the Chrome Trace Event Format, where the trailing]is optional and the Trace Viewer adds it, to support producers that cannot cleanly finish writing. olly writes to a file and has aclosefunction, so it is not one of those producers and could simply emit the bracket.Every event ends with a comma, including the last (
olly_format_json.ml:20). That is the part that bites: appending]by hand still does not parse, and the format documentation notes that trailing commas may throw off Chrome. So the fix is not a single character. Writing the separator before each event except the first, then]on close, covers both.The effect is that anything wanting to post-process a trace needs its own parser rather than the JSON library it already has. Perfetto and Chrome load the file fine, so this only shows up once someone tries to do something with a trace programmatically.
Unrelated but in the same file:
ts_to_usconverts the nanosecond runtime_events timestamp to microseconds by integer division, so any span shorter than a microsecond is recorded as zero width. gc-stats reports pause latencies to 0.01 ms, and the trace cannot represent the short end of that distribution at all. Worth checking whether a fractionaltsis acceptable to the viewers before changing it, since the format documents microsecond granularity.