RecordPrinter.cpp 3.1 KB

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