1 | //===- RecordPrinter.cpp - FDR Record Printer -----------------------------===// |
2 | // |
3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
4 | // See https://llvm.org/LICENSE.txt for license information. |
5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
6 | // |
7 | //===----------------------------------------------------------------------===// |
8 | #include "llvm/XRay/RecordPrinter.h" |
9 | |
10 | #include "llvm/Support/FormatVariadic.h" |
11 | |
12 | namespace llvm { |
13 | namespace xray { |
14 | |
15 | Error RecordPrinter::visit(BufferExtents &R) { |
16 | OS << formatv(Fmt: "<Buffer: size = {0} bytes>" , Vals: R.size()) << Delim; |
17 | return Error::success(); |
18 | } |
19 | |
20 | Error RecordPrinter::visit(WallclockRecord &R) { |
21 | OS << formatv(Fmt: "<Wall Time: seconds = {0}.{1,0+6}>" , Vals: R.seconds(), Vals: R.nanos()) |
22 | << Delim; |
23 | return Error::success(); |
24 | } |
25 | |
26 | Error RecordPrinter::visit(NewCPUIDRecord &R) { |
27 | OS << formatv(Fmt: "<CPU: id = {0}, tsc = {1}>" , Vals: R.cpuid(), Vals: R.tsc()) << Delim; |
28 | return Error::success(); |
29 | } |
30 | |
31 | Error RecordPrinter::visit(TSCWrapRecord &R) { |
32 | OS << formatv(Fmt: "<TSC Wrap: base = {0}>" , Vals: R.tsc()) << Delim; |
33 | return Error::success(); |
34 | } |
35 | |
36 | Error RecordPrinter::visit(CustomEventRecord &R) { |
37 | OS << formatv( |
38 | Fmt: "<Custom Event: tsc = {0}, cpu = {1}, size = {2}, data = '{3}'>" , |
39 | Vals: R.tsc(), Vals: R.cpu(), Vals: R.size(), Vals: R.data()) |
40 | << Delim; |
41 | return Error::success(); |
42 | } |
43 | |
44 | Error RecordPrinter::visit(CustomEventRecordV5 &R) { |
45 | OS << formatv(Fmt: "<Custom Event: delta = +{0}, size = {1}, data = '{2}'>" , |
46 | Vals: R.delta(), Vals: R.size(), Vals: R.data()) |
47 | << Delim; |
48 | return Error::success(); |
49 | } |
50 | |
51 | Error RecordPrinter::visit(TypedEventRecord &R) { |
52 | OS << formatv( |
53 | Fmt: "<Typed Event: delta = +{0}, type = {1}, size = {2}, data = '{3}'" , |
54 | Vals: R.delta(), Vals: R.eventType(), Vals: R.size(), Vals: R.data()) |
55 | << Delim; |
56 | return Error::success(); |
57 | } |
58 | |
59 | Error RecordPrinter::visit(CallArgRecord &R) { |
60 | OS << formatv(Fmt: "<Call Argument: data = {0} (hex = {0:x})>" , Vals: R.arg()) << Delim; |
61 | return Error::success(); |
62 | } |
63 | |
64 | Error RecordPrinter::visit(PIDRecord &R) { |
65 | OS << formatv(Fmt: "<PID: {0}>" , Vals: R.pid()) << Delim; |
66 | return Error::success(); |
67 | } |
68 | |
69 | Error RecordPrinter::visit(NewBufferRecord &R) { |
70 | OS << formatv(Fmt: "<Thread ID: {0}>" , Vals: R.tid()) << Delim; |
71 | return Error::success(); |
72 | } |
73 | |
74 | Error RecordPrinter::visit(EndBufferRecord &R) { |
75 | OS << "<End of Buffer>" << Delim; |
76 | return Error::success(); |
77 | } |
78 | |
79 | Error RecordPrinter::visit(FunctionRecord &R) { |
80 | // FIXME: Support symbolization here? |
81 | switch (R.recordType()) { |
82 | case RecordTypes::ENTER: |
83 | OS << formatv(Fmt: "<Function Enter: #{0} delta = +{1}>" , Vals: R.functionId(), |
84 | Vals: R.delta()); |
85 | break; |
86 | case RecordTypes::ENTER_ARG: |
87 | OS << formatv(Fmt: "<Function Enter With Arg: #{0} delta = +{1}>" , |
88 | Vals: R.functionId(), Vals: R.delta()); |
89 | break; |
90 | case RecordTypes::EXIT: |
91 | OS << formatv(Fmt: "<Function Exit: #{0} delta = +{1}>" , Vals: R.functionId(), |
92 | Vals: R.delta()); |
93 | break; |
94 | case RecordTypes::TAIL_EXIT: |
95 | OS << formatv(Fmt: "<Function Tail Exit: #{0} delta = +{1}>" , Vals: R.functionId(), |
96 | Vals: R.delta()); |
97 | break; |
98 | case RecordTypes::CUSTOM_EVENT: |
99 | case RecordTypes::TYPED_EVENT: |
100 | // TODO: Flag as a bug? |
101 | break; |
102 | } |
103 | OS << Delim; |
104 | return Error::success(); |
105 | } |
106 | |
107 | } // namespace xray |
108 | } // namespace llvm |
109 | |