1174993Srafan//===- YAMLXRayRecord.h - XRay Record YAML Support Definitions ------------===// 2174993Srafan// 3174993Srafan// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4174993Srafan// See https://llvm.org/LICENSE.txt for license information. 5174993Srafan// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6174993Srafan// 7174993Srafan//===----------------------------------------------------------------------===// 8174993Srafan// 9174993Srafan// Types and traits specialisations for YAML I/O of XRay log entries. 10174993Srafan// 11174993Srafan//===----------------------------------------------------------------------===// 12174993Srafan#ifndef LLVM_XRAY_YAMLXRAYRECORD_H 13174993Srafan#define LLVM_XRAY_YAMLXRAYRECORD_H 14174993Srafan 15174993Srafan#include <type_traits> 16174993Srafan 17174993Srafan#include "llvm/Support/YAMLTraits.h" 18174993Srafan#include "llvm/XRay/XRayRecord.h" 19174993Srafan 20174993Srafannamespace llvm { 21174993Srafannamespace xray { 22174993Srafan 23174993Srafanstruct YAMLXRayFileHeader { 24174993Srafan uint16_t Version; 25174993Srafan uint16_t Type; 26174993Srafan bool ConstantTSC; 27174993Srafan bool NonstopTSC; 28174993Srafan uint64_t CycleFrequency; 29174993Srafan}; 30174993Srafan 31174993Srafanstruct YAMLXRayRecord { 32174993Srafan uint16_t RecordType; 33174993Srafan uint16_t CPU; 34174993Srafan RecordTypes Type; 35174993Srafan int32_t FuncId; 36174993Srafan std::string Function; 37174993Srafan uint64_t TSC; 38174993Srafan uint32_t TId; 39174993Srafan uint32_t PId; 40174993Srafan std::vector<uint64_t> CallArgs; 41174993Srafan std::string Data; 42174993Srafan}; 43174993Srafan 44174993Srafanstruct YAMLXRayTrace { 45174993Srafan YAMLXRayFileHeader Header; 46174993Srafan std::vector<YAMLXRayRecord> Records; 47174993Srafan}; 48174993Srafan 49174993Srafan} // namespace xray 50174993Srafan 51174993Srafannamespace yaml { 52174993Srafan 53174993Srafan// YAML Traits 54174993Srafan// ----------- 55174993Srafantemplate <> struct ScalarEnumerationTraits<xray::RecordTypes> { 56174993Srafan static void enumeration(IO &IO, xray::RecordTypes &Type) { 57174993Srafan IO.enumCase(Type, "function-enter", xray::RecordTypes::ENTER); 58174993Srafan IO.enumCase(Type, "function-exit", xray::RecordTypes::EXIT); 59174993Srafan IO.enumCase(Type, "function-tail-exit", xray::RecordTypes::TAIL_EXIT); 60174993Srafan IO.enumCase(Type, "function-enter-arg", xray::RecordTypes::ENTER_ARG); 61174993Srafan IO.enumCase(Type, "custom-event", xray::RecordTypes::CUSTOM_EVENT); 62174993Srafan IO.enumCase(Type, "typed-event", xray::RecordTypes::TYPED_EVENT); 63174993Srafan } 64174993Srafan}; 65174993Srafan 66174993Srafantemplate <> struct MappingTraits<xray::YAMLXRayFileHeader> { 67174993Srafan static void mapping(IO &IO, xray::YAMLXRayFileHeader &Header) { 68174993Srafan IO.mapRequired("version", Header.Version); 69174993Srafan IO.mapRequired("type", Header.Type); 70174993Srafan IO.mapRequired("constant-tsc", Header.ConstantTSC); 71174993Srafan IO.mapRequired("nonstop-tsc", Header.NonstopTSC); 72174993Srafan IO.mapRequired("cycle-frequency", Header.CycleFrequency); 73174993Srafan } 74174993Srafan}; 75174993Srafan 76174993Srafantemplate <> struct MappingTraits<xray::YAMLXRayRecord> { 77174993Srafan static void mapping(IO &IO, xray::YAMLXRayRecord &Record) { 78174993Srafan IO.mapRequired("type", Record.RecordType); 79174993Srafan IO.mapOptional("func-id", Record.FuncId); 80174993Srafan IO.mapOptional("function", Record.Function); 81174993Srafan IO.mapOptional("args", Record.CallArgs); 82174993Srafan IO.mapRequired("cpu", Record.CPU); 83174993Srafan IO.mapOptional("thread", Record.TId, 0U); 84174993Srafan IO.mapOptional("process", Record.PId, 0U); 85174993Srafan IO.mapRequired("kind", Record.Type); 86174993Srafan IO.mapRequired("tsc", Record.TSC); 87174993Srafan IO.mapOptional("data", Record.Data); 88174993Srafan } 89174993Srafan 90174993Srafan static constexpr bool flow = true; 91174993Srafan}; 92174993Srafan 93174993Srafantemplate <> struct MappingTraits<xray::YAMLXRayTrace> { 94174993Srafan static void mapping(IO &IO, xray::YAMLXRayTrace &Trace) { 95174993Srafan // A trace file contains two parts, the header and the list of all the 96174993Srafan // trace records. 97174993Srafan IO.mapRequired("header", Trace.Header); 98174993Srafan IO.mapRequired("records", Trace.Records); 99174993Srafan } 100174993Srafan}; 101174993Srafan 102174993Srafan} // namespace yaml 103174993Srafan} // namespace llvm 104174993Srafan 105174993SrafanLLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRayRecord) 106174993Srafan 107174993Srafan#endif // LLVM_XRAY_YAMLXRAYRECORD_H 108174993Srafan