xref: /freebsd/contrib/llvm-project/llvm/lib/XRay/BlockPrinter.cpp (revision b077aed33b7b6aefca7b17ddb250cf521f938613)
1 //===- BlockPrinter.cpp - FDR Block Pretty Printer Implementation --------===//
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/BlockPrinter.h"
9 
10 namespace llvm {
11 namespace xray {
12 
13 Error BlockPrinter::visit(BufferExtents &R) {
14   OS << "\n[New Block]\n";
15   CurrentState = State::Preamble;
16   return RP.visit(R);
17 }
18 
19 // Preamble printing.
20 Error BlockPrinter::visit(NewBufferRecord &R) {
21   if (CurrentState == State::Start)
22     OS << "\n[New Block]\n";
23 
24   OS << "Preamble: \n";
25   CurrentState = State::Preamble;
26   return RP.visit(R);
27 }
28 
29 Error BlockPrinter::visit(WallclockRecord &R) {
30   CurrentState = State::Preamble;
31   return RP.visit(R);
32 }
33 
34 Error BlockPrinter::visit(PIDRecord &R) {
35   CurrentState = State::Preamble;
36   return RP.visit(R);
37 }
38 
39 // Metadata printing.
40 Error BlockPrinter::visit(NewCPUIDRecord &R) {
41   if (CurrentState == State::Preamble)
42     OS << "\nBody:\n";
43   if (CurrentState == State::Function)
44     OS << "\nMetadata: ";
45   CurrentState = State::Metadata;
46   OS << " ";
47   auto E = RP.visit(R);
48   return E;
49 }
50 
51 Error BlockPrinter::visit(TSCWrapRecord &R) {
52   if (CurrentState == State::Function)
53     OS << "\nMetadata:";
54   CurrentState = State::Metadata;
55   OS << " ";
56   auto E = RP.visit(R);
57   return E;
58 }
59 
60 // Custom events will be rendered like "function" events.
61 Error BlockPrinter::visit(CustomEventRecord &R) {
62   if (CurrentState == State::Metadata)
63     OS << "\n";
64   CurrentState = State::CustomEvent;
65   OS << "*  ";
66   auto E = RP.visit(R);
67   return E;
68 }
69 
70 Error BlockPrinter::visit(CustomEventRecordV5 &R) {
71   if (CurrentState == State::Metadata)
72     OS << "\n";
73   CurrentState = State::CustomEvent;
74   OS << "*  ";
75   auto E = RP.visit(R);
76   return E;
77 }
78 
79 Error BlockPrinter::visit(TypedEventRecord &R) {
80   if (CurrentState == State::Metadata)
81     OS << "\n";
82   CurrentState = State::CustomEvent;
83   OS << "*  ";
84   auto E = RP.visit(R);
85   return E;
86 }
87 
88 // Function call printing.
89 Error BlockPrinter::visit(FunctionRecord &R) {
90   if (CurrentState == State::Metadata)
91     OS << "\n";
92   CurrentState = State::Function;
93   OS << "-  ";
94   auto E = RP.visit(R);
95   return E;
96 }
97 
98 Error BlockPrinter::visit(CallArgRecord &R) {
99   CurrentState = State::Arg;
100   OS << " : ";
101   auto E = RP.visit(R);
102   return E;
103 }
104 
105 Error BlockPrinter::visit(EndBufferRecord &R) {
106     CurrentState = State::End;
107     OS << " *** ";
108     auto E = RP.visit(R);
109     return E;
110 }
111 
112 } // namespace xray
113 } // namespace llvm
114