1//===-- xray_fdr_log_records.h -------------------------------------------===//
2//
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
6//
7//===----------------------------------------------------------------------===//
8//
9// This file is a part of XRay, a function call tracing system.
10//
11//===----------------------------------------------------------------------===//
12#ifndef XRAY_XRAY_FDR_LOG_RECORDS_H
13#define XRAY_XRAY_FDR_LOG_RECORDS_H
14#include <cstdint>
15
16namespace __xray {
17
18enum class RecordType : uint8_t { Function, Metadata };
19
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.
22struct alignas(16) MetadataRecord {
23 // A MetadataRecord must always have a type of 1.
24 /* RecordType */ uint8_t Type : 1;
25
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 {
29 NewBuffer,
30 EndOfBuffer,
31 NewCPUId,
32 TSCWrap,
33 WalltimeMarker,
34 CustomEventMarker,
35 CallArgument,
36 BufferExtents,
37 TypedEventMarker,
38 Pid,
39 };
40
41 // Use 7 bits to identify this record type.
42 /* RecordKinds */ uint8_t RecordKind : 7;
43 char Data[15];
44} __attribute__((packed));
45
46static_assert(sizeof(MetadataRecord) == 16, "Wrong size for MetadataRecord.");
47
48struct alignas(8) FunctionRecord {
49 // A FunctionRecord must always have a type of 0.
50 /* RecordType */ uint8_t Type : 1;
51 enum class RecordKinds {
52 FunctionEnter = 0x00,
53 FunctionExit = 0x01,
54 FunctionTailExit = 0x02,
55 };
56 /* RecordKinds */ uint8_t RecordKind : 3;
57
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.
61 int FuncId : 28;
62
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.
68 uint32_t TSCDelta;
69} __attribute__((packed));
70
71static_assert(sizeof(FunctionRecord) == 8, "Wrong size for FunctionRecord.");
72
73} // namespace __xray
74
75#endif // XRAY_XRAY_FDR_LOG_RECORDS_H
76

source code of compiler-rt/lib/xray/xray_fdr_log_records.h