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
visit(BufferExtents & R)15 Error RecordPrinter::visit(BufferExtents &R) {
16 OS << formatv("<Buffer: size = {0} bytes>", R.size()) << Delim;
17 return Error::success();
18 }
19
visit(WallclockRecord & R)20 Error RecordPrinter::visit(WallclockRecord &R) {
21 OS << formatv("<Wall Time: seconds = {0}.{1,0+6}>", R.seconds(), R.nanos())
22 << Delim;
23 return Error::success();
24 }
25
visit(NewCPUIDRecord & R)26 Error RecordPrinter::visit(NewCPUIDRecord &R) {
27 OS << formatv("<CPU: id = {0}, tsc = {1}>", R.cpuid(), R.tsc()) << Delim;
28 return Error::success();
29 }
30
visit(TSCWrapRecord & R)31 Error RecordPrinter::visit(TSCWrapRecord &R) {
32 OS << formatv("<TSC Wrap: base = {0}>", R.tsc()) << Delim;
33 return Error::success();
34 }
35
visit(CustomEventRecord & R)36 Error RecordPrinter::visit(CustomEventRecord &R) {
37 OS << formatv(
38 "<Custom Event: tsc = {0}, cpu = {1}, size = {2}, data = '{3}'>",
39 R.tsc(), R.cpu(), R.size(), R.data())
40 << Delim;
41 return Error::success();
42 }
43
visit(CustomEventRecordV5 & R)44 Error RecordPrinter::visit(CustomEventRecordV5 &R) {
45 OS << formatv("<Custom Event: delta = +{0}, size = {1}, data = '{2}'>",
46 R.delta(), R.size(), R.data())
47 << Delim;
48 return Error::success();
49 }
50
visit(TypedEventRecord & R)51 Error RecordPrinter::visit(TypedEventRecord &R) {
52 OS << formatv(
53 "<Typed Event: delta = +{0}, type = {1}, size = {2}, data = '{3}'",
54 R.delta(), R.eventType(), R.size(), R.data())
55 << Delim;
56 return Error::success();
57 }
58
visit(CallArgRecord & R)59 Error RecordPrinter::visit(CallArgRecord &R) {
60 OS << formatv("<Call Argument: data = {0} (hex = {0:x})>", R.arg()) << Delim;
61 return Error::success();
62 }
63
visit(PIDRecord & R)64 Error RecordPrinter::visit(PIDRecord &R) {
65 OS << formatv("<PID: {0}>", R.pid()) << Delim;
66 return Error::success();
67 }
68
visit(NewBufferRecord & R)69 Error RecordPrinter::visit(NewBufferRecord &R) {
70 OS << formatv("<Thread ID: {0}>", R.tid()) << Delim;
71 return Error::success();
72 }
73
visit(EndBufferRecord & R)74 Error RecordPrinter::visit(EndBufferRecord &R) {
75 OS << "<End of Buffer>" << Delim;
76 return Error::success();
77 }
78
visit(FunctionRecord & R)79 Error RecordPrinter::visit(FunctionRecord &R) {
80 // FIXME: Support symbolization here?
81 switch (R.recordType()) {
82 case RecordTypes::ENTER:
83 OS << formatv("<Function Enter: #{0} delta = +{1}>", R.functionId(),
84 R.delta());
85 break;
86 case RecordTypes::ENTER_ARG:
87 OS << formatv("<Function Enter With Arg: #{0} delta = +{1}>",
88 R.functionId(), R.delta());
89 break;
90 case RecordTypes::EXIT:
91 OS << formatv("<Function Exit: #{0} delta = +{1}>", R.functionId(),
92 R.delta());
93 break;
94 case RecordTypes::TAIL_EXIT:
95 OS << formatv("<Function Tail Exit: #{0} delta = +{1}>", R.functionId(),
96 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