YAMLXRayRecord.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- YAMLXRayRecord.h - XRay Record YAML Support Definitions ------------===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // Types and traits specialisations for YAML I/O of XRay log entries.
  15. //
  16. //===----------------------------------------------------------------------===//
  17. #ifndef LLVM_XRAY_YAML_XRAY_RECORD_H
  18. #define LLVM_XRAY_YAML_XRAY_RECORD_H
  19. #include <type_traits>
  20. #include "llvm/Support/YAMLTraits.h"
  21. #include "llvm/XRay/XRayRecord.h"
  22. namespace llvm {
  23. namespace xray {
  24. struct YAMLXRayFileHeader {
  25. uint16_t Version;
  26. uint16_t Type;
  27. bool ConstantTSC;
  28. bool NonstopTSC;
  29. uint64_t CycleFrequency;
  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. struct YAMLXRayTrace {
  44. YAMLXRayFileHeader Header;
  45. std::vector<YAMLXRayRecord> Records;
  46. };
  47. } // namespace xray
  48. namespace yaml {
  49. // YAML Traits
  50. // -----------
  51. template <> struct ScalarEnumerationTraits<xray::RecordTypes> {
  52. static void enumeration(IO &IO, xray::RecordTypes &Type) {
  53. IO.enumCase(Type, "function-enter", xray::RecordTypes::ENTER);
  54. IO.enumCase(Type, "function-exit", xray::RecordTypes::EXIT);
  55. IO.enumCase(Type, "function-tail-exit", xray::RecordTypes::TAIL_EXIT);
  56. IO.enumCase(Type, "function-enter-arg", xray::RecordTypes::ENTER_ARG);
  57. IO.enumCase(Type, "custom-event", xray::RecordTypes::CUSTOM_EVENT);
  58. IO.enumCase(Type, "typed-event", xray::RecordTypes::TYPED_EVENT);
  59. }
  60. };
  61. template <> struct MappingTraits<xray::YAMLXRayFileHeader> {
  62. static void mapping(IO &IO, xray::YAMLXRayFileHeader &Header) {
  63. IO.mapRequired("version", Header.Version);
  64. IO.mapRequired("type", Header.Type);
  65. IO.mapRequired("constant-tsc", Header.ConstantTSC);
  66. IO.mapRequired("nonstop-tsc", Header.NonstopTSC);
  67. IO.mapRequired("cycle-frequency", Header.CycleFrequency);
  68. }
  69. };
  70. template <> struct MappingTraits<xray::YAMLXRayRecord> {
  71. static void mapping(IO &IO, xray::YAMLXRayRecord &Record) {
  72. IO.mapRequired("type", Record.RecordType);
  73. IO.mapOptional("func-id", Record.FuncId);
  74. IO.mapOptional("function", Record.Function);
  75. IO.mapOptional("args", Record.CallArgs);
  76. IO.mapRequired("cpu", Record.CPU);
  77. IO.mapOptional("thread", Record.TId, 0U);
  78. IO.mapOptional("process", Record.PId, 0U);
  79. IO.mapRequired("kind", Record.Type);
  80. IO.mapRequired("tsc", Record.TSC);
  81. IO.mapOptional("data", Record.Data);
  82. }
  83. static constexpr bool flow = true;
  84. };
  85. template <> struct MappingTraits<xray::YAMLXRayTrace> {
  86. static void mapping(IO &IO, xray::YAMLXRayTrace &Trace) {
  87. // A trace file contains two parts, the header and the list of all the
  88. // trace records.
  89. IO.mapRequired("header", Trace.Header);
  90. IO.mapRequired("records", Trace.Records);
  91. }
  92. };
  93. } // namespace yaml
  94. } // namespace llvm
  95. LLVM_YAML_IS_SEQUENCE_VECTOR(xray::YAMLXRayRecord)
  96. #endif // LLVM_XRAY_YAML_XRAY_RECORD_H
  97. #ifdef __GNUC__
  98. #pragma GCC diagnostic pop
  99. #endif