1251881Speter//===-- xray_fdr_log_records.h -------------------------------------------===// 2251881Speter// 3251881Speter// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4251881Speter// See https://llvm.org/LICENSE.txt for license information. 5251881Speter// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6251881Speter// 7251881Speter//===----------------------------------------------------------------------===// 8251881Speter// 9251881Speter// This file is a part of XRay, a function call tracing system. 10251881Speter// 11251881Speter//===----------------------------------------------------------------------===// 12251881Speter#ifndef XRAY_XRAY_FDR_LOG_RECORDS_H 13251881Speter#define XRAY_XRAY_FDR_LOG_RECORDS_H 14251881Speter#include <cstdint> 15251881Speter 16251881Speternamespace __xray { 17251881Speter 18251881Speterenum class RecordType : uint8_t { Function, Metadata }; 19251881Speter 20251881Speter// A MetadataRecord encodes the kind of record in its first byte, and have 15 21251881Speter// additional bytes in the end to hold free-form data. 22251881Speterstruct alignas(16) MetadataRecord { 23251881Speter // A MetadataRecord must always have a type of 1. 24251881Speter /* RecordType */ uint8_t Type : 1; 25251881Speter 26251881Speter // Each kind of record is represented as a 7-bit value (even though we use an 27251881Speter // unsigned 8-bit enum class to do so). 28251881Speter enum class RecordKinds : uint8_t { 29251881Speter NewBuffer, 30251881Speter EndOfBuffer, 31251881Speter NewCPUId, 32251881Speter TSCWrap, 33251881Speter WalltimeMarker, 34251881Speter CustomEventMarker, 35251881Speter CallArgument, 36251881Speter BufferExtents, 37251881Speter TypedEventMarker, 38251881Speter Pid, 39251881Speter }; 40251881Speter 41251881Speter // Use 7 bits to identify this record type. 42251881Speter /* RecordKinds */ uint8_t RecordKind : 7; 43251881Speter char Data[15]; 44251881Speter} __attribute__((packed)); 45251881Speter 46251881Speterstatic_assert(sizeof(MetadataRecord) == 16, "Wrong size for MetadataRecord."); 47251881Speter 48251881Speterstruct alignas(8) FunctionRecord { 49251881Speter // A FunctionRecord must always have a type of 0. 50251881Speter /* RecordType */ uint8_t Type : 1; 51251881Speter enum class RecordKinds { 52251881Speter FunctionEnter = 0x00, 53251881Speter FunctionExit = 0x01, 54251881Speter FunctionTailExit = 0x02, 55251881Speter }; 56251881Speter /* RecordKinds */ uint8_t RecordKind : 3; 57251881Speter 58251881Speter // We only use 28 bits of the function ID, so that we can use as few bytes as 59251881Speter // possible. This means we only support 2^28 (268,435,456) unique function ids 60251881Speter // in a single binary. 61251881Speter int FuncId : 28; 62251881Speter 63251881Speter // We use another 4 bytes to hold the delta between the previous entry's TSC. 64251881Speter // In case we've found that the distance is greater than the allowable 32 bits 65251881Speter // (either because we are running in a different CPU and the TSC might be 66251881Speter // different then), we should use a MetadataRecord before this FunctionRecord 67251881Speter // that will contain the full TSC for that CPU, and keep this to 0. 68251881Speter uint32_t TSCDelta; 69251881Speter} __attribute__((packed)); 70251881Speter 71251881Speterstatic_assert(sizeof(FunctionRecord) == 8, "Wrong size for FunctionRecord."); 72251881Speter 73251881Speter} // namespace __xray 74251881Speter 75251881Speter#endif // XRAY_XRAY_FDR_LOG_RECORDS_H 76251881Speter