1//===-- xray_fdr_log_records.h -------------------------------------------===// 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// This file is a part of XRay, a function call tracing system. 11// 12//===----------------------------------------------------------------------===// 13#ifndef XRAY_XRAY_FDR_LOG_RECORDS_H 14#define XRAY_XRAY_FDR_LOG_RECORDS_H 15#include <cstdint> 16 17namespace __xray { 18 19enum class RecordType : uint8_t { Function, Metadata }; 20 21// A MetadataRecord encodes the kind of record in its first byte, and have 15 22// additional bytes in the end to hold free-form data. 23struct alignas(16) MetadataRecord { 24 // A MetadataRecord must always have a type of 1. 25 /* RecordType */ uint8_t Type : 1; 26 27 // Each kind of record is represented as a 7-bit value (even though we use an 28 // unsigned 8-bit enum class to do so). 29 enum class RecordKinds : uint8_t { 30 NewBuffer, 31 EndOfBuffer, 32 NewCPUId, 33 TSCWrap, 34 WalltimeMarker, 35 CustomEventMarker, 36 CallArgument, 37 BufferExtents, 38 TypedEventMarker, 39 Pid, 40 }; 41 42 // Use 7 bits to identify this record type. 43 /* RecordKinds */ uint8_t RecordKind : 7; 44 char Data[15]; 45} __attribute__((packed)); 46 47static_assert(sizeof(MetadataRecord) == 16, "Wrong size for MetadataRecord."); 48 49struct alignas(8) FunctionRecord { 50 // A FunctionRecord must always have a type of 0. 51 /* RecordType */ uint8_t Type : 1; 52 enum class RecordKinds { 53 FunctionEnter = 0x00, 54 FunctionExit = 0x01, 55 FunctionTailExit = 0x02, 56 }; 57 /* RecordKinds */ uint8_t RecordKind : 3; 58 59 // We only use 28 bits of the function ID, so that we can use as few bytes as 60 // possible. This means we only support 2^28 (268,435,456) unique function ids 61 // in a single binary. 62 int FuncId : 28; 63 64 // We use another 4 bytes to hold the delta between the previous entry's TSC. 65 // In case we've found that the distance is greater than the allowable 32 bits 66 // (either because we are running in a different CPU and the TSC might be 67 // different then), we should use a MetadataRecord before this FunctionRecord 68 // that will contain the full TSC for that CPU, and keep this to 0. 69 uint32_t TSCDelta; 70} __attribute__((packed)); 71 72static_assert(sizeof(FunctionRecord) == 8, "Wrong size for FunctionRecord."); 73 74} // namespace __xray 75 76#endif // XRAY_XRAY_FDR_LOG_RECORDS_H 77