diff --git a/llvm/test/tools/llvm-xray/X86/convert-fdr-to-traceevent.txt b/llvm/test/tools/llvm-xray/X86/convert-fdr-to-traceevent.txt new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-xray/X86/convert-fdr-to-traceevent.txt @@ -0,0 +1,12 @@ +; RUN: llvm-xray convert %S/Inputs/fdr-log-version-1.xray -f=trace_event -o - \ +; RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \ +; RUN: | FileCheck %s + +; CHECK: "traceEvents": [ +; Check fields for an event are present +; CHECK: "name": +; CHECK-NEXT: "ph": +; CHECK-NEXT: "pid": +; CHECK-NEXT: "sf": +; CHECK-NEXT: "tid": +; CHECK-NEXT: "ts": diff --git a/llvm/test/tools/llvm-xray/X86/convert-traceevent-special-events.txt b/llvm/test/tools/llvm-xray/X86/convert-traceevent-special-events.txt new file mode 100644 --- /dev/null +++ b/llvm/test/tools/llvm-xray/X86/convert-traceevent-special-events.txt @@ -0,0 +1,24 @@ +# RUN: llvm-xray convert %s -f=trace_event -o - \ +# RUN: | %python -c 'import json, sys; json.dump(json.loads(sys.stdin.read()), sys.stdout, sort_keys=True, indent=2)' \ +# RUN: | FileCheck %s +--- +header: + version: 1 + type: 0 + constant-tsc: true + nonstop-tsc: true + cycle-frequency: 2601000000 +records: + - { type: 0, func-id: 1, cpu: 1, thread: 111, kind: function-enter, tsc: 10001 } + - { type: 0, func-id: 1, function: 'x', cpu: 1, thread: 111, process: 111, kind: custom-event, tsc: 2000, data: "\x03\0\0\0" } + - { type: 0, func-id: 1, cpu: 1, thread: 111, kind: function-exit, tsc: 10100 } +... + +# CHECK: "traceEvents": [ +# Check fields for an event are present +# CHECK: "name": +# CHECK-NEXT: "ph": +# CHECK-NEXT: "pid": +# CHECK-NEXT: "sf": +# CHECK-NEXT: "tid": +# CHECK-NEXT: "ts": diff --git a/llvm/tools/llvm-xray/xray-converter.cpp b/llvm/tools/llvm-xray/xray-converter.cpp --- a/llvm/tools/llvm-xray/xray-converter.cpp +++ b/llvm/tools/llvm-xray/xray-converter.cpp @@ -269,19 +269,14 @@ auto CycleFreq = FH.CycleFrequency; unsigned id_counter = 0; + int NumOutputRecords = 0; - OS << "{\n \"traceEvents\": ["; + OS << "{\n \"traceEvents\": [\n"; DenseMap StackCursorByThreadId{}; DenseMap> StackRootsByThreadId{}; DenseMap StacksByStackId{}; std::forward_list 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 @@ // 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 @@ // (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,