blob: abce8ff60a94d3a5ecb79d4455fce1cef63caf4b [file] [log] [blame]
Dean Michael Berris429bac82017-01-12 07:38:13 +00001//===- xray-record-yaml.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_TOOLS_LLVM_XRAY_XRAY_RECORD_YAML_H
14#define LLVM_TOOLS_LLVM_XRAY_XRAY_RECORD_YAML_H
15
16#include <type_traits>
17
18#include "xray-record.h"
19#include "llvm/Support/YAMLTraits.h"
20
21namespace llvm {
22namespace xray {
23
24struct YAMLXRayFileHeader {
25 uint16_t Version;
26 uint16_t Type;
27 bool ConstantTSC;
28 bool NonstopTSC;
29 uint64_t CycleFrequency;
30};
31
32struct YAMLXRayRecord {
33 uint16_t RecordType;
34 uint8_t CPU;
35 RecordTypes Type;
36 int32_t FuncId;
37 std::string Function;
38 uint64_t TSC;
39 uint32_t TId;
40};
41
42struct YAMLXRayTrace {
43 YAMLXRayFileHeader Header;
44 std::vector<YAMLXRayRecord> Records;
45};
46
47using XRayRecordStorage =
48 std::aligned_storage<sizeof(XRayRecord), alignof(XRayRecord)>::type;
49
50} // namespace xray
51
52namespace yaml {
53
54// YAML Traits
55// -----------
56template <> 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 }
61};
62
63template <> struct MappingTraits<xray::YAMLXRayFileHeader> {
64 static void mapping(IO &IO, xray::YAMLXRayFileHeader &Header) {
65 IO.mapRequired("version", Header.Version);
66 IO.mapRequired("type", Header.Type);
67 IO.mapRequired("constant-tsc", Header.ConstantTSC);
68 IO.mapRequired("nonstop-tsc", Header.NonstopTSC);
69 IO.mapRequired("cycle-frequency", Header.CycleFrequency);
70 }
71};
72
73template <> struct MappingTraits<xray::YAMLXRayRecord> {
74 static void mapping(IO &IO, xray::YAMLXRayRecord &Record) {
75 // FIXME: Make this type actually be descriptive
76 IO.mapRequired("type", Record.RecordType);
77 IO.mapRequired("func-id", Record.FuncId);
78 IO.mapOptional("function", Record.Function);
79 IO.mapRequired("cpu", Record.CPU);
80 IO.mapRequired("thread", Record.TId);
81 IO.mapRequired("kind", Record.Type);
82 IO.mapRequired("tsc", Record.TSC);
83 }
84
85 static constexpr bool flow = true;
86};
87
88template <> struct MappingTraits<xray::YAMLXRayTrace> {
89 static void mapping(IO &IO, xray::YAMLXRayTrace &Trace) {
90 // A trace file contains two parts, the header and the list of all the
91 // trace records.
92 IO.mapRequired("header", Trace.Header);
93 IO.mapRequired("records", Trace.Records);
94 }
95};
96
97} // namespace yaml
98} // namespace llvm
99
100LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRayRecord)
101
102#endif // LLVM_TOOLS_LLVM_XRAY_XRAY_RECORD_YAML_H