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