File: xray_fdr_log_records.h

package info (click to toggle)
llvm-toolchain-7 1%3A7.0.1-8~deb9u3
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 733,456 kB
  • sloc: cpp: 3,776,651; ansic: 633,271; asm: 350,301; python: 142,716; objc: 107,612; sh: 22,626; lisp: 11,056; perl: 7,999; pascal: 6,742; ml: 5,537; awk: 3,536; makefile: 2,557; cs: 2,027; xml: 841; ruby: 156
file content (71 lines) | stat: -rw-r--r-- 2,471 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//===-- xray_fdr_log_records.h  -------------------------------------------===//
//
//                     The LLVM Compiler Infrastructure
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//
//
// This file is a part of XRay, a function call tracing system.
//
//===----------------------------------------------------------------------===//
#ifndef XRAY_XRAY_FDR_LOG_RECORDS_H
#define XRAY_XRAY_FDR_LOG_RECORDS_H

enum class RecordType : uint8_t { Function, Metadata };

// A MetadataRecord encodes the kind of record in its first byte, and have 15
// additional bytes in the end to hold free-form data.
struct alignas(16) MetadataRecord {
  // A MetadataRecord must always have a type of 1.
  /* RecordType */ uint8_t Type : 1;

  // Each kind of record is represented as a 7-bit value (even though we use an
  // unsigned 8-bit enum class to do so).
  enum class RecordKinds : uint8_t {
    NewBuffer,
    EndOfBuffer,
    NewCPUId,
    TSCWrap,
    WalltimeMarker,
    CustomEventMarker,
    CallArgument,
    BufferExtents,
    TypedEventMarker,
    Pid,
  };

  // Use 7 bits to identify this record type.
  /* RecordKinds */ uint8_t RecordKind : 7;
  char Data[15];
} __attribute__((packed));

static_assert(sizeof(MetadataRecord) == 16, "Wrong size for MetadataRecord.");

struct alignas(8) FunctionRecord {
  // A FunctionRecord must always have a type of 0.
  /* RecordType */ uint8_t Type : 1;
  enum class RecordKinds {
    FunctionEnter = 0x00,
    FunctionExit = 0x01,
    FunctionTailExit = 0x02,
  };
  /* RecordKinds */ uint8_t RecordKind : 3;

  // We only use 28 bits of the function ID, so that we can use as few bytes as
  // possible. This means we only support 2^28 (268,435,456) unique function ids
  // in a single binary.
  int FuncId : 28;

  // We use another 4 bytes to hold the delta between the previous entry's TSC.
  // In case we've found that the distance is greater than the allowable 32 bits
  // (either because we are running in a different CPU and the TSC might be
  // different then), we should use a MetadataRecord before this FunctionRecord
  // that will contain the full TSC for that CPU, and keep this to 0.
  uint32_t TSCDelta;
} __attribute__((packed));

static_assert(sizeof(FunctionRecord) == 8, "Wrong size for FunctionRecord.");

#endif // XRAY_XRAY_FDR_LOG_RECORDS_H