FDRRecordConsumer.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- FDRRecordConsumer.h - XRay Flight Data Recorder Mode Records -------===//
  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_INCLUDE_LLVM_XRAY_FDRRECORDCONSUMER_H_
  14. #define LLVM_INCLUDE_LLVM_XRAY_FDRRECORDCONSUMER_H_
  15. #include "llvm/Support/Error.h"
  16. #include "llvm/XRay/FDRRecords.h"
  17. #include <algorithm>
  18. #include <memory>
  19. #include <vector>
  20. namespace llvm {
  21. namespace xray {
  22. class RecordConsumer {
  23. public:
  24. virtual Error consume(std::unique_ptr<Record> R) = 0;
  25. virtual ~RecordConsumer() = default;
  26. };
  27. // This consumer will collect all the records into a vector of records, in
  28. // arrival order.
  29. class LogBuilderConsumer : public RecordConsumer {
  30. std::vector<std::unique_ptr<Record>> &Records;
  31. public:
  32. explicit LogBuilderConsumer(std::vector<std::unique_ptr<Record>> &R)
  33. : RecordConsumer(), Records(R) {}
  34. Error consume(std::unique_ptr<Record> R) override;
  35. };
  36. // A PipelineConsumer applies a set of visitors to every consumed Record, in the
  37. // order by which the visitors are added to the pipeline in the order of
  38. // appearance.
  39. class PipelineConsumer : public RecordConsumer {
  40. std::vector<RecordVisitor *> Visitors;
  41. public:
  42. PipelineConsumer(std::initializer_list<RecordVisitor *> V)
  43. : RecordConsumer(), Visitors(V) {}
  44. Error consume(std::unique_ptr<Record> R) override;
  45. };
  46. } // namespace xray
  47. } // namespace llvm
  48. #endif // LLVM_INCLUDE_LLVM_XRAY_FDRRECORDCONSUMER_H_
  49. #ifdef __GNUC__
  50. #pragma GCC diagnostic pop
  51. #endif