]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/include/llvm/XRay/YAMLXRayRecord.h
Merge llvm, clang, compiler-rt, libc++, libunwind, lld, lldb and openmp
[FreeBSD/FreeBSD.git] / contrib / llvm / include / llvm / XRay / YAMLXRayRecord.h
1 //===- YAMLXRayRecord.h - XRay Record YAML Support Definitions ------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 //
10 // Types and traits specialisations for YAML I/O of XRay log entries.
11 //
12 //===----------------------------------------------------------------------===//
13 #ifndef LLVM_XRAY_YAML_XRAY_RECORD_H
14 #define LLVM_XRAY_YAML_XRAY_RECORD_H
15
16 #include <type_traits>
17
18 #include "llvm/Support/YAMLTraits.h"
19 #include "llvm/XRay/XRayRecord.h"
20
21 namespace llvm {
22 namespace xray {
23
24 struct YAMLXRayFileHeader {
25   uint16_t Version;
26   uint16_t Type;
27   bool ConstantTSC;
28   bool NonstopTSC;
29   uint64_t CycleFrequency;
30 };
31
32 struct YAMLXRayRecord {
33   uint16_t RecordType;
34   uint16_t CPU;
35   RecordTypes Type;
36   int32_t FuncId;
37   std::string Function;
38   uint64_t TSC;
39   uint32_t TId;
40   uint32_t PId;
41   std::vector<uint64_t> CallArgs;
42   std::string Data;
43 };
44
45 struct YAMLXRayTrace {
46   YAMLXRayFileHeader Header;
47   std::vector<YAMLXRayRecord> Records;
48 };
49
50 } // namespace xray
51
52 namespace yaml {
53
54 // YAML Traits
55 // -----------
56 template <> struct ScalarEnumerationTraits<xray::RecordTypes> {
57   static void enumeration(IO &IO, xray::RecordTypes &Type) {
58     IO.enumCase(Type, "function-enter", xray::RecordTypes::ENTER);
59     IO.enumCase(Type, "function-exit", xray::RecordTypes::EXIT);
60     IO.enumCase(Type, "function-tail-exit", xray::RecordTypes::TAIL_EXIT);
61     IO.enumCase(Type, "function-enter-arg", xray::RecordTypes::ENTER_ARG);
62     IO.enumCase(Type, "custom-event", xray::RecordTypes::CUSTOM_EVENT);
63     IO.enumCase(Type, "typed-event", xray::RecordTypes::TYPED_EVENT);
64   }
65 };
66
67 template <> struct MappingTraits<xray::YAMLXRayFileHeader> {
68   static void mapping(IO &IO, xray::YAMLXRayFileHeader &Header) {
69     IO.mapRequired("version", Header.Version);
70     IO.mapRequired("type", Header.Type);
71     IO.mapRequired("constant-tsc", Header.ConstantTSC);
72     IO.mapRequired("nonstop-tsc", Header.NonstopTSC);
73     IO.mapRequired("cycle-frequency", Header.CycleFrequency);
74   }
75 };
76
77 template <> struct MappingTraits<xray::YAMLXRayRecord> {
78   static void mapping(IO &IO, xray::YAMLXRayRecord &Record) {
79     IO.mapRequired("type", Record.RecordType);
80     IO.mapOptional("func-id", Record.FuncId);
81     IO.mapOptional("function", Record.Function);
82     IO.mapOptional("args", Record.CallArgs);
83     IO.mapRequired("cpu", Record.CPU);
84     IO.mapOptional("thread", Record.TId, 0U);
85     IO.mapOptional("process", Record.PId, 0U);
86     IO.mapRequired("kind", Record.Type);
87     IO.mapRequired("tsc", Record.TSC);
88     IO.mapOptional("data", Record.Data);
89   }
90
91   static constexpr bool flow = true;
92 };
93
94 template <> struct MappingTraits<xray::YAMLXRayTrace> {
95   static void mapping(IO &IO, xray::YAMLXRayTrace &Trace) {
96     // A trace file contains two parts, the header and the list of all the
97     // trace records.
98     IO.mapRequired("header", Trace.Header);
99     IO.mapRequired("records", Trace.Records);
100   }
101 };
102
103 } // namespace yaml
104 } // namespace llvm
105
106 LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRayRecord)
107
108 #endif // LLVM_XRAY_YAML_XRAY_RECORD_H