Line data Source code
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 : };
43 :
44 69 : struct YAMLXRayTrace {
45 : YAMLXRayFileHeader Header;
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 659 : static void enumeration(IO &IO, xray::RecordTypes &Type) {
57 659 : IO.enumCase(Type, "function-enter", xray::RecordTypes::ENTER);
58 659 : IO.enumCase(Type, "function-exit", xray::RecordTypes::EXIT);
59 659 : IO.enumCase(Type, "function-tail-exit", xray::RecordTypes::TAIL_EXIT);
60 659 : IO.enumCase(Type, "function-enter-arg", xray::RecordTypes::ENTER_ARG);
61 659 : }
62 : };
63 :
64 : template <> struct MappingTraits<xray::YAMLXRayFileHeader> {
65 69 : static void mapping(IO &IO, xray::YAMLXRayFileHeader &Header) {
66 69 : IO.mapRequired("version", Header.Version);
67 69 : IO.mapRequired("type", Header.Type);
68 69 : IO.mapRequired("constant-tsc", Header.ConstantTSC);
69 69 : IO.mapRequired("nonstop-tsc", Header.NonstopTSC);
70 69 : IO.mapRequired("cycle-frequency", Header.CycleFrequency);
71 69 : }
72 : };
73 :
74 : template <> struct MappingTraits<xray::YAMLXRayRecord> {
75 659 : static void mapping(IO &IO, xray::YAMLXRayRecord &Record) {
76 : // FIXME: Make this type actually be descriptive
77 659 : IO.mapRequired("type", Record.RecordType);
78 659 : IO.mapRequired("func-id", Record.FuncId);
79 659 : IO.mapOptional("function", Record.Function);
80 659 : IO.mapOptional("args", Record.CallArgs);
81 659 : IO.mapRequired("cpu", Record.CPU);
82 659 : IO.mapRequired("thread", Record.TId);
83 659 : IO.mapOptional("process", Record.PId, 0U);
84 659 : IO.mapRequired("kind", Record.Type);
85 659 : IO.mapRequired("tsc", Record.TSC);
86 659 : }
87 :
88 : static constexpr bool flow = true;
89 : };
90 :
91 : template <> struct MappingTraits<xray::YAMLXRayTrace> {
92 69 : static void mapping(IO &IO, xray::YAMLXRayTrace &Trace) {
93 : // A trace file contains two parts, the header and the list of all the
94 : // trace records.
95 69 : IO.mapRequired("header", Trace.Header);
96 69 : IO.mapRequired("records", Trace.Records);
97 69 : }
98 : };
99 :
100 : } // namespace yaml
101 : } // namespace llvm
102 :
103 : LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRayRecord)
104 :
105 : #endif // LLVM_XRAY_YAML_XRAY_RECORD_H
|