xref: /llvm-project/llvm/lib/XRay/BlockPrinter.cpp (revision dd01efc56d7ef3a335aad3d9cfe1b53d0f8524f8)
1 //===- BlockPrinter.cpp - FDR Block Pretty Printer Implementation --------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 #include "llvm/XRay/BlockPrinter.h"
10 
11 namespace llvm {
12 namespace xray {
13 
14 Error BlockPrinter::visit(BufferExtents &R) {
15   OS << "\n[New Block]\n";
16   CurrentState = State::Preamble;
17   return RP.visit(R);
18 }
19 
20 // Preamble printing.
21 Error BlockPrinter::visit(NewBufferRecord &R) {
22   if (CurrentState == State::Start)
23     OS << "\n[New Block]\n";
24 
25   OS << "Preamble: \n";
26   CurrentState = State::Preamble;
27   return RP.visit(R);
28 }
29 
30 Error BlockPrinter::visit(WallclockRecord &R) {
31   CurrentState = State::Preamble;
32   return RP.visit(R);
33 }
34 
35 Error BlockPrinter::visit(PIDRecord &R) {
36   CurrentState = State::Preamble;
37   return RP.visit(R);
38 }
39 
40 // Metadata printing.
41 Error BlockPrinter::visit(NewCPUIDRecord &R) {
42   if (CurrentState == State::Preamble)
43     OS << "\nBody:\n";
44   if (CurrentState == State::Function)
45     OS << "\nMetadata: ";
46   CurrentState = State::Metadata;
47   OS << " ";
48   auto E = RP.visit(R);
49   return E;
50 }
51 
52 Error BlockPrinter::visit(TSCWrapRecord &R) {
53   if (CurrentState == State::Function)
54     OS << "\nMetadata:";
55   CurrentState = State::Metadata;
56   OS << " ";
57   auto E = RP.visit(R);
58   return E;
59 }
60 
61 // Custom events will be rendered like "function" events.
62 Error BlockPrinter::visit(CustomEventRecord &R) {
63   if (CurrentState == State::Metadata)
64     OS << "\n";
65   CurrentState = State::CustomEvent;
66   OS << "*  ";
67   auto E = RP.visit(R);
68   return E;
69 }
70 
71 // Function call printing.
72 Error BlockPrinter::visit(FunctionRecord &R) {
73   if (CurrentState == State::Metadata)
74     OS << "\n";
75   CurrentState = State::Function;
76   OS << "-  ";
77   auto E = RP.visit(R);
78   return E;
79 }
80 
81 Error BlockPrinter::visit(CallArgRecord &R) {
82   CurrentState = State::Arg;
83   OS << " : ";
84   auto E = RP.visit(R);
85   return E;
86 }
87 
88 Error BlockPrinter::visit(EndBufferRecord &R) {
89     CurrentState = State::End;
90     OS << " *** ";
91     auto E = RP.visit(R);
92     return E;
93 }
94 
95 } // namespace xray
96 } // namespace llvm
97