FDRLogBuilder.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- FDRLogBuilder.h - XRay FDR Log Building Utility --------------------===//
  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_FDRLOGBUILDER_H
  14. #define LLVM_XRAY_FDRLOGBUILDER_H
  15. #include "llvm/XRay/FDRRecords.h"
  16. namespace llvm {
  17. namespace xray {
  18. /// The LogBuilder class allows for creating ad-hoc collections of records
  19. /// through the `add<...>(...)` function. An example use of this API is in
  20. /// crafting arbitrary sequences of records:
  21. ///
  22. /// auto Records = LogBuilder()
  23. /// .add<BufferExtents>(256)
  24. /// .add<NewBufferRecord>(1)
  25. /// .consume();
  26. ///
  27. class LogBuilder {
  28. std::vector<std::unique_ptr<Record>> Records;
  29. public:
  30. template <class R, class... T> LogBuilder &add(T &&... A) {
  31. Records.emplace_back(new R(std::forward<T>(A)...));
  32. return *this;
  33. }
  34. std::vector<std::unique_ptr<Record>> consume() { return std::move(Records); }
  35. };
  36. } // namespace xray
  37. } // namespace llvm
  38. #endif // LLVM_XRAY_FDRLOGBUILDER_H
  39. #ifdef __GNUC__
  40. #pragma GCC diagnostic pop
  41. #endif