Skip to content

Commit

Permalink
[SYCL] Fix sycl-prof JSON output (#7128)
Browse files Browse the repository at this point in the history
This patch fixes a problem related to the JSON output. Every element of
`"traceEvents"` has a comma appended, this is a problem in the case of
the last element, e.g.,
```
{
  "traceEvents": [ 
 ...
{"name": "piTearDown", ... , "ts": "16..81"}, <-- here is  
],
"displayTimeUnit":"ns"
}
```
This comma prevents the display of the JSON output in
`chrome://tracing/` or [speedscope](https://www.speedscope.app/) due to
its invalid format. This patch solves the problem by adding an empty
element before finalizing the JSON output.
  • Loading branch information
pgorlani authored Nov 1, 2022
1 parent 0c541bd commit 37a74c7
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions sycl/tools/sycl-prof/writer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ class JSONWriter : public Writer {
if (!MOutFile.is_open())
return;

// add an empty element for not ending with '}, ]'
MOutFile << "{\"name\": \"\", \"cat\": \"\", \"ph\": \"\", \"pid\": \"\", "
"\"tid\": \"\", \"ts\": \"\"}\n";

MOutFile << "],\n";
MOutFile << "\"displayTimeUnit\":\"ns\"\n}\n";
MOutFile.close();
Expand Down

0 comments on commit 37a74c7

Please sign in to comment.