1215976Sjmallett//===- XRayRecord.h - XRay Trace Record -----------------------------------===// 2215976Sjmallett// 3215976Sjmallett// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4215976Sjmallett// See https://llvm.org/LICENSE.txt for license information. 5215976Sjmallett// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6215976Sjmallett// 7215976Sjmallett//===----------------------------------------------------------------------===// 8215976Sjmallett// 9215976Sjmallett// This file replicates the record definition for XRay log entries. This should 10215976Sjmallett// follow the evolution of the log record versions supported in the compiler-rt 11215976Sjmallett// xray project. 12215976Sjmallett// 13215976Sjmallett//===----------------------------------------------------------------------===// 14215976Sjmallett#ifndef LLVM_XRAY_XRAYRECORD_H 15215976Sjmallett#define LLVM_XRAY_XRAYRECORD_H 16215976Sjmallett 17215976Sjmallett#include <cstdint> 18215976Sjmallett#include <vector> 19215976Sjmallett#include <string> 20215976Sjmallett 21215976Sjmallettnamespace llvm { 22215976Sjmallettnamespace xray { 23215976Sjmallett 24215976Sjmallett/// XRay traces all have a header providing some top-matter information useful 25215976Sjmallett/// to help tools determine how to interpret the information available in the 26215976Sjmallett/// trace. 27215976Sjmallettstruct XRayFileHeader { 28215976Sjmallett /// Version of the XRay implementation that produced this file. 29215976Sjmallett uint16_t Version = 0; 30215976Sjmallett 31215976Sjmallett /// A numeric identifier for the type of file this is. Best used in 32215976Sjmallett /// combination with Version. 33215976Sjmallett uint16_t Type = 0; 34215976Sjmallett 35215976Sjmallett /// Whether the CPU that produced the timestamp counters (TSC) move at a 36215976Sjmallett /// constant rate. 37215976Sjmallett bool ConstantTSC = false; 38215976Sjmallett 39215976Sjmallett /// Whether the CPU that produced the timestamp counters (TSC) do not stop. 40215976Sjmallett bool NonstopTSC = false; 41215976Sjmallett 42215976Sjmallett /// The number of cycles per second for the CPU that produced the timestamp 43215976Sjmallett /// counter (TSC) values. Useful for estimating the amount of time that 44215976Sjmallett /// elapsed between two TSCs on some platforms. 45215976Sjmallett uint64_t CycleFrequency = 0; 46215976Sjmallett 47215976Sjmallett // This is different depending on the type of xray record. The naive format 48215976Sjmallett // stores a Wallclock timespec. FDR logging stores the size of a thread 49215976Sjmallett // buffer. 50215976Sjmallett char FreeFormData[16] = {}; 51215976Sjmallett}; 52215976Sjmallett 53215976Sjmallett/// Determines the supported types of records that could be seen in XRay traces. 54215976Sjmallett/// This may or may not correspond to actual record types in the raw trace (as 55215976Sjmallett/// the loader implementation may synthesize this information in the process of 56215976Sjmallett/// of loading). 57215976Sjmallettenum class RecordTypes { 58215976Sjmallett ENTER, 59215976Sjmallett EXIT, 60215976Sjmallett TAIL_EXIT, 61215976Sjmallett ENTER_ARG, 62215976Sjmallett CUSTOM_EVENT, 63215976Sjmallett TYPED_EVENT 64215976Sjmallett}; 65215976Sjmallett 66215976Sjmallett/// An XRayRecord is the denormalized view of data associated in a trace. These 67215976Sjmallett/// records may not correspond to actual entries in the raw traces, but they are 68215976Sjmallett/// the logical representation of records in a higher-level event log. 69215976Sjmallettstruct XRayRecord { 70215976Sjmallett /// RecordType values are used as "sub-types" which have meaning in the 71215976Sjmallett /// context of the `Type` below. For function call and custom event records, 72215976Sjmallett /// the RecordType is always 0, while for typed events we store the type in 73215976Sjmallett /// the RecordType field. 74215976Sjmallett uint16_t RecordType; 75215976Sjmallett 76215976Sjmallett /// The CPU where the thread is running. We assume number of CPUs <= 65536. 77215976Sjmallett uint16_t CPU; 78215976Sjmallett 79215976Sjmallett /// Identifies the type of record. 80215976Sjmallett RecordTypes Type; 81215976Sjmallett 82215976Sjmallett /// The function ID for the record, if this is a function call record. 83215976Sjmallett int32_t FuncId; 84215976Sjmallett 85215976Sjmallett /// Get the full 8 bytes of the TSC when we get the log record. 86215976Sjmallett uint64_t TSC; 87215976Sjmallett 88215976Sjmallett /// The thread ID for the currently running thread. 89215976Sjmallett uint32_t TId; 90215976Sjmallett 91215976Sjmallett /// The process ID for the currently running process. 92215976Sjmallett uint32_t PId; 93215976Sjmallett 94215976Sjmallett /// The function call arguments. 95215976Sjmallett std::vector<uint64_t> CallArgs; 96215976Sjmallett 97215976Sjmallett /// For custom and typed events, we provide the raw data from the trace. 98215976Sjmallett std::string Data; 99215976Sjmallett}; 100215976Sjmallett 101215976Sjmallett} // namespace xray 102215976Sjmallett} // namespace llvm 103215976Sjmallett 104215976Sjmallett#endif // LLVM_XRAY_XRAYRECORD_H 105215976Sjmallett