blob: 3f49dc6dcb9d606800ddc96f84601b44f81c3b16 [file] [log] [blame]
Andrew Scull0372a572018-11-16 15:47:06 +00001//===- FDRLogBuilder.h - XRay FDR Log Building Utility --------------------===//
2//
Andrew Walbran16937d02019-10-22 13:54:20 +01003// 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
Andrew Scull0372a572018-11-16 15:47:06 +00006//
7//===----------------------------------------------------------------------===//
8#ifndef LLVM_INCLUDE_LLVM_XRAY_FDRLOGBUILDER_H_
9#define LLVM_INCLUDE_LLVM_XRAY_FDRLOGBUILDER_H_
10
11#include "llvm/XRay/FDRRecords.h"
12
13namespace llvm {
14namespace xray {
15
16/// The LogBuilder class allows for creating ad-hoc collections of records
17/// through the `add<...>(...)` function. An example use of this API is in
18/// crafting arbitrary sequences of records:
19///
20/// auto Records = LogBuilder()
21/// .add<BufferExtents>(256)
22/// .add<NewBufferRecord>(1)
23/// .consume();
24///
25class LogBuilder {
26 std::vector<std::unique_ptr<Record>> Records;
27
28public:
29 template <class R, class... T> LogBuilder &add(T &&... A) {
30 Records.emplace_back(new R(std::forward<T>(A)...));
31 return *this;
32 }
33
34 std::vector<std::unique_ptr<Record>> consume() { return std::move(Records); }
35};
36
37} // namespace xray
38} // namespace llvm
39
40#endif // LLVM_INCLUDE_LLVM_XRAY_FDRLOGBUILDER_H_