1 //===-- xray_fdr_log_records.h -------------------------------------------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 // This file is a part of XRay, a function call tracing system.
11 //===----------------------------------------------------------------------===//
12 #ifndef XRAY_XRAY_FDR_LOG_RECORDS_H
13 #define XRAY_XRAY_FDR_LOG_RECORDS_H
18 enum class RecordType
: uint8_t { Function
, Metadata
};
20 // A MetadataRecord encodes the kind of record in its first byte, and have 15
21 // additional bytes in the end to hold free-form data.
22 struct alignas(16) MetadataRecord
{
23 // A MetadataRecord must always have a type of 1.
24 /* RecordType */ uint8_t Type
: 1;
26 // Each kind of record is represented as a 7-bit value (even though we use an
27 // unsigned 8-bit enum class to do so).
28 enum class RecordKinds
: uint8_t {
41 // Use 7 bits to identify this record type.
42 /* RecordKinds */ uint8_t RecordKind
: 7;
44 } __attribute__((packed
));
46 static_assert(sizeof(MetadataRecord
) == 16, "Wrong size for MetadataRecord.");
48 struct alignas(8) FunctionRecord
{
49 // A FunctionRecord must always have a type of 0.
50 /* RecordType */ uint8_t Type
: 1;
51 enum class RecordKinds
{
54 FunctionTailExit
= 0x02,
56 /* RecordKinds */ uint8_t RecordKind
: 3;
58 // We only use 28 bits of the function ID, so that we can use as few bytes as
59 // possible. This means we only support 2^28 (268,435,456) unique function ids
60 // in a single binary.
63 // We use another 4 bytes to hold the delta between the previous entry's TSC.
64 // In case we've found that the distance is greater than the allowable 32 bits
65 // (either because we are running in a different CPU and the TSC might be
66 // different then), we should use a MetadataRecord before this FunctionRecord
67 // that will contain the full TSC for that CPU, and keep this to 0.
69 } __attribute__((packed
));
71 static_assert(sizeof(FunctionRecord
) == 8, "Wrong size for FunctionRecord.");
75 #endif // XRAY_XRAY_FDR_LOG_RECORDS_H