FDRTraceExpander.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. //===- FDRTraceExpander.h - XRay FDR Mode Log Expander --------------------===//
  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. //
  9. // We define an FDR record visitor which can re-constitute XRayRecord instances
  10. // from a sequence of FDR mode records in arrival order into a collection.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_XRAY_FDRTRACEEXPANDER_H
  14. #define LLVM_XRAY_FDRTRACEEXPANDER_H
  15. #include "llvm/ADT/STLExtras.h"
  16. #include "llvm/XRay/FDRRecords.h"
  17. #include "llvm/XRay/XRayRecord.h"
  18. namespace llvm {
  19. namespace xray {
  20. class TraceExpander : public RecordVisitor {
  21. // Type-erased callback for handling individual XRayRecord instances.
  22. function_ref<void(const XRayRecord &)> C;
  23. int32_t PID = 0;
  24. int32_t TID = 0;
  25. uint64_t BaseTSC = 0;
  26. XRayRecord CurrentRecord{0, 0, RecordTypes::ENTER, 0, 0, 0, 0, {}, {}};
  27. uint16_t CPUId = 0;
  28. uint16_t LogVersion = 0;
  29. bool BuildingRecord = false;
  30. bool IgnoringRecords = false;
  31. void resetCurrentRecord();
  32. public:
  33. explicit TraceExpander(function_ref<void(const XRayRecord &)> F, uint16_t L)
  34. : RecordVisitor(), C(std::move(F)), LogVersion(L) {}
  35. Error visit(BufferExtents &) override;
  36. Error visit(WallclockRecord &) override;
  37. Error visit(NewCPUIDRecord &) override;
  38. Error visit(TSCWrapRecord &) override;
  39. Error visit(CustomEventRecord &) override;
  40. Error visit(CallArgRecord &) override;
  41. Error visit(PIDRecord &) override;
  42. Error visit(NewBufferRecord &) override;
  43. Error visit(EndBufferRecord &) override;
  44. Error visit(FunctionRecord &) override;
  45. Error visit(CustomEventRecordV5 &) override;
  46. Error visit(TypedEventRecord &) override;
  47. // Must be called after all the records have been processed, to handle the
  48. // most recent record generated.
  49. Error flush();
  50. };
  51. } // namespace xray
  52. } // namespace llvm
  53. #endif // LLVM_XRAY_FDRTRACEEXPANDER_H