summaryrefslogtreecommitdiff
path: root/include/xray/xray_records.h
blob: 506755dbd633d6abbec60d008d27e194957e8fed (plain)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//===-- xray_records.h ------------------------------------------*- C++ -*-===//
//
//                     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 dynamic runtime instrumentation system.
//
// This header exposes some record types useful for the XRay in-memory logging
// implementation.
//
//===----------------------------------------------------------------------===//

#ifndef XRAY_XRAY_RECORDS_H
#define XRAY_XRAY_RECORDS_H

#include <cstdint>

namespace __xray {

enum FileTypes {
  NAIVE_LOG = 0,
  FDR_LOG = 1,
};

// FDR mode use of the union field in the XRayFileHeader.
struct alignas(16) FdrAdditionalHeaderData {
  uint64_t ThreadBufferSize;
};

static_assert(sizeof(FdrAdditionalHeaderData) == 16,
              "FdrAdditionalHeaderData != 16 bytes");

// This data structure is used to describe the contents of the file. We use this
// for versioning the supported XRay file formats.
struct alignas(32) XRayFileHeader {
  uint16_t Version = 0;

  // The type of file we're writing out. See the FileTypes enum for more
  // information. This allows different implementations of the XRay logging to
  // have different files for different information being stored.
  uint16_t Type = 0;

  // What follows are a set of flags that indicate useful things for when
  // reading the data in the file.
  bool ConstantTSC : 1;
  bool NonstopTSC : 1;

  // The frequency by which TSC increases per-second.
  alignas(8) uint64_t CycleFrequency = 0;

  union {
    char FreeForm[16];
    // The current civiltime timestamp, as retrived from 'clock_gettime'. This
    // allows readers of the file to determine when the file was created or
    // written down.
    struct timespec TS;

    struct FdrAdditionalHeaderData FdrData;
  };
} __attribute__((packed));

static_assert(sizeof(XRayFileHeader) == 32, "XRayFileHeader != 32 bytes");

enum RecordTypes {
  NORMAL = 0,
};

struct alignas(32) XRayRecord {
  // This is the type of the record being written. We use 16 bits to allow us to
  // treat this as a discriminant, and so that the first 4 bytes get packed
  // properly. See RecordTypes for more supported types.
  uint16_t RecordType = 0;

  // The CPU where the thread is running. We assume number of CPUs <= 256.
  uint8_t CPU = 0;

  // The type of the event. Usually either ENTER = 0 or EXIT = 1.
  uint8_t Type = 0;

  // The function ID for the record.
  int32_t FuncId = 0;

  // Get the full 8 bytes of the TSC when we get the log record.
  uint64_t TSC = 0;

  // The thread ID for the currently running thread.
  uint32_t TId = 0;

  // Use some bytes in the end of the record for buffers.
  char Buffer[4] = {};
} __attribute__((packed));

static_assert(sizeof(XRayRecord) == 32, "XRayRecord != 32 bytes");

} // namespace __xray

#endif // XRAY_XRAY_RECORDS_H