XRayRecord.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- XRayRecord.h - XRay Trace Record -----------------------------------===//
  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. // This file replicates the record definition for XRay log entries. This should
  15. // follow the evolution of the log record versions supported in the compiler-rt
  16. // xray project.
  17. //
  18. //===----------------------------------------------------------------------===//
  19. #ifndef LLVM_XRAY_XRAYRECORD_H
  20. #define LLVM_XRAY_XRAYRECORD_H
  21. #include <cstdint>
  22. #include <vector>
  23. #include <string>
  24. namespace llvm {
  25. namespace xray {
  26. /// XRay traces all have a header providing some top-matter information useful
  27. /// to help tools determine how to interpret the information available in the
  28. /// trace.
  29. struct XRayFileHeader {
  30. /// Version of the XRay implementation that produced this file.
  31. uint16_t Version = 0;
  32. /// A numeric identifier for the type of file this is. Best used in
  33. /// combination with Version.
  34. uint16_t Type = 0;
  35. /// Whether the CPU that produced the timestamp counters (TSC) move at a
  36. /// constant rate.
  37. bool ConstantTSC;
  38. /// Whether the CPU that produced the timestamp counters (TSC) do not stop.
  39. bool NonstopTSC;
  40. /// The number of cycles per second for the CPU that produced the timestamp
  41. /// counter (TSC) values. Useful for estimating the amount of time that
  42. /// elapsed between two TSCs on some platforms.
  43. uint64_t CycleFrequency = 0;
  44. // This is different depending on the type of xray record. The naive format
  45. // stores a Wallclock timespec. FDR logging stores the size of a thread
  46. // buffer.
  47. char FreeFormData[16];
  48. };
  49. /// Determines the supported types of records that could be seen in XRay traces.
  50. /// This may or may not correspond to actual record types in the raw trace (as
  51. /// the loader implementation may synthesize this information in the process of
  52. /// of loading).
  53. enum class RecordTypes {
  54. ENTER,
  55. EXIT,
  56. TAIL_EXIT,
  57. ENTER_ARG,
  58. CUSTOM_EVENT,
  59. TYPED_EVENT
  60. };
  61. /// An XRayRecord is the denormalized view of data associated in a trace. These
  62. /// records may not correspond to actual entries in the raw traces, but they are
  63. /// the logical representation of records in a higher-level event log.
  64. struct XRayRecord {
  65. /// RecordType values are used as "sub-types" which have meaning in the
  66. /// context of the `Type` below. For function call and custom event records,
  67. /// the RecordType is always 0, while for typed events we store the type in
  68. /// the RecordType field.
  69. uint16_t RecordType;
  70. /// The CPU where the thread is running. We assume number of CPUs <= 65536.
  71. uint16_t CPU;
  72. /// Identifies the type of record.
  73. RecordTypes Type;
  74. /// The function ID for the record, if this is a function call record.
  75. int32_t FuncId;
  76. /// Get the full 8 bytes of the TSC when we get the log record.
  77. uint64_t TSC;
  78. /// The thread ID for the currently running thread.
  79. uint32_t TId;
  80. /// The process ID for the currently running process.
  81. uint32_t PId;
  82. /// The function call arguments.
  83. std::vector<uint64_t> CallArgs;
  84. /// For custom and typed events, we provide the raw data from the trace.
  85. std::string Data;
  86. };
  87. } // namespace xray
  88. } // namespace llvm
  89. #endif // LLVM_XRAY_XRAYRECORD_H
  90. #ifdef __GNUC__
  91. #pragma GCC diagnostic pop
  92. #endif