BlockPrinter.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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. namespace llvm {
  10. namespace xray {
  11. Error BlockPrinter::visit(BufferExtents &R) {
  12. OS << "\n[New Block]\n";
  13. CurrentState = State::Preamble;
  14. return RP.visit(R);
  15. }
  16. // Preamble printing.
  17. Error BlockPrinter::visit(NewBufferRecord &R) {
  18. if (CurrentState == State::Start)
  19. OS << "\n[New Block]\n";
  20. OS << "Preamble: \n";
  21. CurrentState = State::Preamble;
  22. return RP.visit(R);
  23. }
  24. Error BlockPrinter::visit(WallclockRecord &R) {
  25. CurrentState = State::Preamble;
  26. return RP.visit(R);
  27. }
  28. Error BlockPrinter::visit(PIDRecord &R) {
  29. CurrentState = State::Preamble;
  30. return RP.visit(R);
  31. }
  32. // Metadata printing.
  33. Error BlockPrinter::visit(NewCPUIDRecord &R) {
  34. if (CurrentState == State::Preamble)
  35. OS << "\nBody:\n";
  36. if (CurrentState == State::Function)
  37. OS << "\nMetadata: ";
  38. CurrentState = State::Metadata;
  39. OS << " ";
  40. auto E = RP.visit(R);
  41. return E;
  42. }
  43. Error BlockPrinter::visit(TSCWrapRecord &R) {
  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. // Custom events will be rendered like "function" events.
  52. Error BlockPrinter::visit(CustomEventRecord &R) {
  53. if (CurrentState == State::Metadata)
  54. OS << "\n";
  55. CurrentState = State::CustomEvent;
  56. OS << "* ";
  57. auto E = RP.visit(R);
  58. return E;
  59. }
  60. Error BlockPrinter::visit(CustomEventRecordV5 &R) {
  61. if (CurrentState == State::Metadata)
  62. OS << "\n";
  63. CurrentState = State::CustomEvent;
  64. OS << "* ";
  65. auto E = RP.visit(R);
  66. return E;
  67. }
  68. Error BlockPrinter::visit(TypedEventRecord &R) {
  69. if (CurrentState == State::Metadata)
  70. OS << "\n";
  71. CurrentState = State::CustomEvent;
  72. OS << "* ";
  73. auto E = RP.visit(R);
  74. return E;
  75. }
  76. // Function call printing.
  77. Error BlockPrinter::visit(FunctionRecord &R) {
  78. if (CurrentState == State::Metadata)
  79. OS << "\n";
  80. CurrentState = State::Function;
  81. OS << "- ";
  82. auto E = RP.visit(R);
  83. return E;
  84. }
  85. Error BlockPrinter::visit(CallArgRecord &R) {
  86. CurrentState = State::Arg;
  87. OS << " : ";
  88. auto E = RP.visit(R);
  89. return E;
  90. }
  91. Error BlockPrinter::visit(EndBufferRecord &R) {
  92. CurrentState = State::End;
  93. OS << " *** ";
  94. auto E = RP.visit(R);
  95. return E;
  96. }
  97. } // namespace xray
  98. } // namespace llvm