FDRRecordProducer.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- FDRRecordProducer.h - XRay FDR Mode Record Producer ----------------===//
  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. #ifndef LLVM_XRAY_FDRRECORDPRODUCER_H
  14. #define LLVM_XRAY_FDRRECORDPRODUCER_H
  15. #include "llvm/Support/Error.h"
  16. #include "llvm/XRay/FDRRecords.h"
  17. #include "llvm/XRay/XRayRecord.h"
  18. #include <memory>
  19. namespace llvm {
  20. namespace xray {
  21. class RecordProducer {
  22. public:
  23. /// All producer implementations must yield either an Error or a non-nullptr
  24. /// unique_ptr<Record>.
  25. virtual Expected<std::unique_ptr<Record>> produce() = 0;
  26. virtual ~RecordProducer() = default;
  27. };
  28. class FileBasedRecordProducer : public RecordProducer {
  29. const XRayFileHeader &Header;
  30. DataExtractor &E;
  31. uint64_t &OffsetPtr;
  32. uint32_t CurrentBufferBytes = 0;
  33. // Helper function which gets the next record by speculatively reading through
  34. // the log, finding a buffer extents record.
  35. Expected<std::unique_ptr<Record>> findNextBufferExtent();
  36. public:
  37. FileBasedRecordProducer(const XRayFileHeader &FH, DataExtractor &DE,
  38. uint64_t &OP)
  39. : Header(FH), E(DE), OffsetPtr(OP) {}
  40. /// This producer encapsulates the logic for loading a File-backed
  41. /// RecordProducer hidden behind a DataExtractor.
  42. Expected<std::unique_ptr<Record>> produce() override;
  43. };
  44. } // namespace xray
  45. } // namespace llvm
  46. #endif // LLVM_XRAY_FDRRECORDPRODUCER_H
  47. #ifdef __GNUC__
  48. #pragma GCC diagnostic pop
  49. #endif