[llvm/Object] - Convert SectionRef::getName() to return Expected<>
[llvm-complete.git] / lib / XRay / BlockPrinter.cpp
blob63a60c3c56a3889cd3337442f6bab818fb245c7f
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"
10 namespace llvm {
11 namespace xray {
13 Error BlockPrinter::visit(BufferExtents &R) {
14 OS << "\n[New Block]\n";
15 CurrentState = State::Preamble;
16 return RP.visit(R);
19 // Preamble printing.
20 Error BlockPrinter::visit(NewBufferRecord &R) {
21 if (CurrentState == State::Start)
22 OS << "\n[New Block]\n";
24 OS << "Preamble: \n";
25 CurrentState = State::Preamble;
26 return RP.visit(R);
29 Error BlockPrinter::visit(WallclockRecord &R) {
30 CurrentState = State::Preamble;
31 return RP.visit(R);
34 Error BlockPrinter::visit(PIDRecord &R) {
35 CurrentState = State::Preamble;
36 return RP.visit(R);
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;
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;
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;
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;
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;
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;
98 Error BlockPrinter::visit(CallArgRecord &R) {
99 CurrentState = State::Arg;
100 OS << " : ";
101 auto E = RP.visit(R);
102 return E;
105 Error BlockPrinter::visit(EndBufferRecord &R) {
106 CurrentState = State::End;
107 OS << " *** ";
108 auto E = RP.visit(R);
109 return E;
112 } // namespace xray
113 } // namespace llvm