FDRTraceExpander.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- FDRTraceExpander.h - XRay FDR Mode Log Expander --------------------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // We define an FDR record visitor which can re-constitute XRayRecord instances
  15. // from a sequence of FDR mode records in arrival order into a collection.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_XRAY_FDRTRACEEXPANDER_H
  19. #define LLVM_XRAY_FDRTRACEEXPANDER_H
  20. #include "llvm/ADT/STLExtras.h"
  21. #include "llvm/XRay/FDRRecords.h"
  22. #include "llvm/XRay/XRayRecord.h"
  23. namespace llvm {
  24. namespace xray {
  25. class TraceExpander : public RecordVisitor {
  26. // Type-erased callback for handling individual XRayRecord instances.
  27. function_ref<void(const XRayRecord &)> C;
  28. int32_t PID = 0;
  29. int32_t TID = 0;
  30. uint64_t BaseTSC = 0;
  31. XRayRecord CurrentRecord{0, 0, RecordTypes::ENTER, 0, 0, 0, 0, {}, {}};
  32. uint16_t CPUId = 0;
  33. uint16_t LogVersion = 0;
  34. bool BuildingRecord = false;
  35. bool IgnoringRecords = false;
  36. void resetCurrentRecord();
  37. public:
  38. explicit TraceExpander(function_ref<void(const XRayRecord &)> F, uint16_t L)
  39. : C(std::move(F)), LogVersion(L) {}
  40. Error visit(BufferExtents &) override;
  41. Error visit(WallclockRecord &) override;
  42. Error visit(NewCPUIDRecord &) override;
  43. Error visit(TSCWrapRecord &) override;
  44. Error visit(CustomEventRecord &) override;
  45. Error visit(CallArgRecord &) override;
  46. Error visit(PIDRecord &) override;
  47. Error visit(NewBufferRecord &) override;
  48. Error visit(EndBufferRecord &) override;
  49. Error visit(FunctionRecord &) override;
  50. Error visit(CustomEventRecordV5 &) override;
  51. Error visit(TypedEventRecord &) override;
  52. // Must be called after all the records have been processed, to handle the
  53. // most recent record generated.
  54. Error flush();
  55. };
  56. } // namespace xray
  57. } // namespace llvm
  58. #endif // LLVM_XRAY_FDRTRACEEXPANDER_H
  59. #ifdef __GNUC__
  60. #pragma GCC diagnostic pop
  61. #endif