xray_fdr_log_records.h revision 317021
1154133Sharti//===-- xray_fdr_log_records.h  -------------------------------------------===//
2154133Sharti//
3154133Sharti//                     The LLVM Compiler Infrastructure
4154133Sharti//
5154133Sharti// This file is distributed under the University of Illinois Open Source
6154133Sharti// License. See LICENSE.TXT for details.
7154133Sharti//
8154133Sharti//===----------------------------------------------------------------------===//
9154133Sharti//
10154133Sharti// This file is a part of XRay, a function call tracing system.
11154133Sharti//
12154133Sharti//===----------------------------------------------------------------------===//
13154133Sharti#ifndef XRAY_XRAY_FDR_LOG_RECORDS_H
14154133Sharti#define XRAY_XRAY_FDR_LOG_RECORDS_H
15154133Sharti
16154133Shartienum class RecordType : uint8_t { Function, Metadata };
17154133Sharti
18154133Sharti// A MetadataRecord encodes the kind of record in its first byte, and have 15
19154133Sharti// additional bytes in the end to hold free-form data.
20154133Shartistruct alignas(16) MetadataRecord {
21154133Sharti  // A MetadataRecord must always have a type of 1.
22154133Sharti  /* RecordType */ uint8_t Type : 1;
23154133Sharti
24154133Sharti  // Each kind of record is represented as a 7-bit value (even though we use an
25154133Sharti  // unsigned 8-bit enum class to do so).
26154133Sharti  enum class RecordKinds : uint8_t {
27154133Sharti    NewBuffer,
28154133Sharti    EndOfBuffer,
29154133Sharti    NewCPUId,
30154133Sharti    TSCWrap,
31154133Sharti    WalltimeMarker,
32154133Sharti  };
33154133Sharti  // Use 7 bits to identify this record type.
34154133Sharti  /* RecordKinds */ uint8_t RecordKind : 7;
35154133Sharti  char Data[15];
36154133Sharti} __attribute__((packed));
37154133Sharti
38154133Shartistatic_assert(sizeof(MetadataRecord) == 16, "Wrong size for MetadataRecord.");
39154133Sharti
40154133Shartistruct alignas(8) FunctionRecord {
41154133Sharti  // A FunctionRecord must always have a type of 0.
42154133Sharti  /* RecordType */ uint8_t Type : 1;
43154133Sharti  enum class RecordKinds {
44154133Sharti    FunctionEnter = 0x00,
45154133Sharti    FunctionExit = 0x01,
46160341Sharti    FunctionTailExit = 0x02,
47154133Sharti  };
48154133Sharti  /* RecordKinds */ uint8_t RecordKind : 3;
49154133Sharti
50154133Sharti  // We only use 28 bits of the function ID, so that we can use as few bytes as
51154133Sharti  // possible. This means we only support 2^28 (268,435,456) unique function ids
52160341Sharti  // in a single binary.
53160341Sharti  int FuncId : 28;
54160341Sharti
55160341Sharti  // We use another 4 bytes to hold the delta between the previous entry's TSC.
56160341Sharti  // In case we've found that the distance is greater than the allowable 32 bits
57160341Sharti  // (either because we are running in a different CPU and the TSC might be
58160341Sharti  // different then), we should use a MetadataRecord before this FunctionRecord
59154133Sharti  // that will contain the full TSC for that CPU, and keep this to 0.
60154133Sharti  uint32_t TSCDelta;
61154133Sharti} __attribute__((packed));
62154133Sharti
63154133Shartistatic_assert(sizeof(FunctionRecord) == 8, "Wrong size for FunctionRecord.");
64154133Sharti
65154133Sharti#endif // XRAY_XRAY_FDR_LOG_RECORDS_H
66154133Sharti