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