diff options
author | Todd Lipcon <tlipcon@google.com> | 2021-02-10 12:59:31 +1100 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2021-02-10 13:00:28 +1100 |
commit | 747c450e6f1f7238243150a6870daa6385476413 (patch) | |
tree | 6e733c21ee2ba4428f5b148a32837e7184702963 /llvm/tools/llvm-xray | |
parent | 5dd29d9922ad0c1e7c82f118444ccde7f2ae9aef (diff) | |
download | llvm-747c450e6f1f7238243150a6870daa6385476413.zip llvm-747c450e6f1f7238243150a6870daa6385476413.tar.gz llvm-747c450e6f1f7238243150a6870daa6385476413.tar.bz2 |
Fix JSON formatting when converting to trace event format
Reviewed By: dberris
Differential Revision: https://reviews.llvm.org/D96384
Diffstat (limited to 'llvm/tools/llvm-xray')
-rw-r--r-- | llvm/tools/llvm-xray/xray-converter.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/llvm/tools/llvm-xray/xray-converter.cpp b/llvm/tools/llvm-xray/xray-converter.cpp index c1a623f..645e2e3 100644 --- a/llvm/tools/llvm-xray/xray-converter.cpp +++ b/llvm/tools/llvm-xray/xray-converter.cpp @@ -269,19 +269,14 @@ void TraceConverter::exportAsChromeTraceEventFormat(const Trace &Records, auto CycleFreq = FH.CycleFrequency; unsigned id_counter = 0; + int NumOutputRecords = 0; - OS << "{\n \"traceEvents\": ["; + OS << "{\n \"traceEvents\": [\n"; DenseMap<uint32_t, StackTrieNode *> StackCursorByThreadId{}; DenseMap<uint32_t, SmallVector<StackTrieNode *, 4>> StackRootsByThreadId{}; DenseMap<unsigned, StackTrieNode *> StacksByStackId{}; std::forward_list<StackTrieNode> NodeStore{}; - int loop_count = 0; for (const auto &R : Records) { - if (loop_count++ == 0) - OS << "\n"; - else - OS << ",\n"; - // Chrome trace event format always wants data in micros. // CyclesPerMicro = CycleHertz / 10^6 // TSC / CyclesPerMicro == TSC * 10^6 / CycleHertz == MicroTimestamp @@ -306,6 +301,9 @@ void TraceConverter::exportAsChromeTraceEventFormat(const Trace &Records, // type of B for begin or E for end, thread id, process id, // timestamp in microseconds, and a stack frame id. The ids are logged // in an id dictionary after the events. + if (NumOutputRecords++ > 0) { + OS << ",\n"; + } writeTraceViewerRecord(Version, OS, R.FuncId, R.TId, R.PId, Symbolize, FuncIdHelper, EventTimestampUs, *StackCursor, "B"); break; @@ -318,7 +316,7 @@ void TraceConverter::exportAsChromeTraceEventFormat(const Trace &Records, // (And/Or in loop termination below) StackTrieNode *PreviousCursor = nullptr; do { - if (PreviousCursor != nullptr) { + if (NumOutputRecords++ > 0) { OS << ",\n"; } writeTraceViewerRecord(Version, OS, StackCursor->FuncId, R.TId, R.PId, |