FDRTraceExpander.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. //===- FDRTraceExpander.cpp -----------------------------------------------===//
  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/FDRTraceExpander.h"
  9. namespace llvm {
  10. namespace xray {
  11. void TraceExpander::resetCurrentRecord() {
  12. if (BuildingRecord)
  13. C(CurrentRecord);
  14. BuildingRecord = false;
  15. CurrentRecord.CallArgs.clear();
  16. CurrentRecord.Data.clear();
  17. }
  18. Error TraceExpander::visit(BufferExtents &) {
  19. resetCurrentRecord();
  20. return Error::success();
  21. }
  22. Error TraceExpander::visit(WallclockRecord &) { return Error::success(); }
  23. Error TraceExpander::visit(NewCPUIDRecord &R) {
  24. CPUId = R.cpuid();
  25. BaseTSC = R.tsc();
  26. return Error::success();
  27. }
  28. Error TraceExpander::visit(TSCWrapRecord &R) {
  29. BaseTSC = R.tsc();
  30. return Error::success();
  31. }
  32. Error TraceExpander::visit(CustomEventRecord &R) {
  33. resetCurrentRecord();
  34. if (!IgnoringRecords) {
  35. CurrentRecord.TSC = R.tsc();
  36. CurrentRecord.CPU = R.cpu();
  37. CurrentRecord.PId = PID;
  38. CurrentRecord.TId = TID;
  39. CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
  40. CurrentRecord.Data = std::string(R.data());
  41. BuildingRecord = true;
  42. }
  43. return Error::success();
  44. }
  45. Error TraceExpander::visit(CustomEventRecordV5 &R) {
  46. resetCurrentRecord();
  47. if (!IgnoringRecords) {
  48. BaseTSC += R.delta();
  49. CurrentRecord.TSC = BaseTSC;
  50. CurrentRecord.CPU = CPUId;
  51. CurrentRecord.PId = PID;
  52. CurrentRecord.TId = TID;
  53. CurrentRecord.Type = RecordTypes::CUSTOM_EVENT;
  54. CurrentRecord.Data = std::string(R.data());
  55. BuildingRecord = true;
  56. }
  57. return Error::success();
  58. }
  59. Error TraceExpander::visit(TypedEventRecord &R) {
  60. resetCurrentRecord();
  61. if (!IgnoringRecords) {
  62. BaseTSC += R.delta();
  63. CurrentRecord.TSC = BaseTSC;
  64. CurrentRecord.CPU = CPUId;
  65. CurrentRecord.PId = PID;
  66. CurrentRecord.TId = TID;
  67. CurrentRecord.RecordType = R.eventType();
  68. CurrentRecord.Type = RecordTypes::TYPED_EVENT;
  69. CurrentRecord.Data = std::string(R.data());
  70. BuildingRecord = true;
  71. }
  72. return Error::success();
  73. }
  74. Error TraceExpander::visit(CallArgRecord &R) {
  75. CurrentRecord.CallArgs.push_back(R.arg());
  76. CurrentRecord.Type = RecordTypes::ENTER_ARG;
  77. return Error::success();
  78. }
  79. Error TraceExpander::visit(PIDRecord &R) {
  80. PID = R.pid();
  81. return Error::success();
  82. }
  83. Error TraceExpander::visit(NewBufferRecord &R) {
  84. if (IgnoringRecords)
  85. IgnoringRecords = false;
  86. TID = R.tid();
  87. if (LogVersion == 2)
  88. PID = R.tid();
  89. return Error::success();
  90. }
  91. Error TraceExpander::visit(EndBufferRecord &) {
  92. IgnoringRecords = true;
  93. resetCurrentRecord();
  94. return Error::success();
  95. }
  96. Error TraceExpander::visit(FunctionRecord &R) {
  97. resetCurrentRecord();
  98. if (!IgnoringRecords) {
  99. BaseTSC += R.delta();
  100. CurrentRecord.Type = R.recordType();
  101. CurrentRecord.FuncId = R.functionId();
  102. CurrentRecord.TSC = BaseTSC;
  103. CurrentRecord.PId = PID;
  104. CurrentRecord.TId = TID;
  105. CurrentRecord.CPU = CPUId;
  106. BuildingRecord = true;
  107. }
  108. return Error::success();
  109. }
  110. Error TraceExpander::flush() {
  111. resetCurrentRecord();
  112. return Error::success();
  113. }
  114. } // namespace xray
  115. } // namespace llvm