FDRRecordConsumer.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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_XRAY_FDRRECORDCONSUMER_H
  14. #define 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. : 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) : Visitors(V) {}
  43. Error consume(std::unique_ptr<Record> R) override;
  44. };
  45. } // namespace xray
  46. } // namespace llvm
  47. #endif // LLVM_XRAY_FDRRECORDCONSUMER_H
  48. #ifdef __GNUC__
  49. #pragma GCC diagnostic pop
  50. #endif