]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/compiler-rt/include/xray/xray_records.h
Merge ^/head r320398 through r320572.
[FreeBSD/FreeBSD.git] / contrib / compiler-rt / include / xray / xray_records.h
1 //===-- xray_records.h ------------------------------------------*- C++ -*-===//
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 dynamic runtime instrumentation system.
11 //
12 // This header exposes some record types useful for the XRay in-memory logging
13 // implementation.
14 //
15 //===----------------------------------------------------------------------===//
16
17 #ifndef XRAY_XRAY_RECORDS_H
18 #define XRAY_XRAY_RECORDS_H
19
20 namespace __xray {
21
22 enum FileTypes {
23   NAIVE_LOG = 0,
24   FDR_LOG = 1,
25 };
26
27 // FDR mode use of the union field in the XRayFileHeader.
28 struct alignas(16) FdrAdditionalHeaderData {
29   uint64_t ThreadBufferSize;
30 };
31
32 static_assert(sizeof(FdrAdditionalHeaderData) == 16,
33               "FdrAdditionalHeaderData != 16 bytes");
34
35 // This data structure is used to describe the contents of the file. We use this
36 // for versioning the supported XRay file formats.
37 struct alignas(32) XRayFileHeader {
38   uint16_t Version = 0;
39
40   // The type of file we're writing out. See the FileTypes enum for more
41   // information. This allows different implementations of the XRay logging to
42   // have different files for different information being stored.
43   uint16_t Type = 0;
44
45   // What follows are a set of flags that indicate useful things for when
46   // reading the data in the file.
47   bool ConstantTSC : 1;
48   bool NonstopTSC : 1;
49
50   // The frequency by which TSC increases per-second.
51   alignas(8) uint64_t CycleFrequency = 0;
52
53   union {
54     char FreeForm[16];
55     // The current civiltime timestamp, as retrived from 'clock_gettime'. This
56     // allows readers of the file to determine when the file was created or
57     // written down.
58     struct timespec TS;
59
60     struct FdrAdditionalHeaderData FdrData;
61   };
62 } __attribute__((packed));
63
64 static_assert(sizeof(XRayFileHeader) == 32, "XRayFileHeader != 32 bytes");
65
66 enum RecordTypes {
67   NORMAL = 0,
68 };
69
70 struct alignas(32) XRayRecord {
71   // This is the type of the record being written. We use 16 bits to allow us to
72   // treat this as a discriminant, and so that the first 4 bytes get packed
73   // properly. See RecordTypes for more supported types.
74   uint16_t RecordType = 0;
75
76   // The CPU where the thread is running. We assume number of CPUs <= 256.
77   uint8_t CPU = 0;
78
79   // The type of the event. Usually either ENTER = 0 or EXIT = 1.
80   uint8_t Type = 0;
81
82   // The function ID for the record.
83   int32_t FuncId = 0;
84
85   // Get the full 8 bytes of the TSC when we get the log record.
86   uint64_t TSC = 0;
87
88   // The thread ID for the currently running thread.
89   uint32_t TId = 0;
90
91   // Use some bytes in the end of the record for buffers.
92   char Buffer[4] = {};
93 } __attribute__((packed));
94
95 static_assert(sizeof(XRayRecord) == 32, "XRayRecord != 32 bytes");
96
97 } // namespace __xray
98
99 #endif // XRAY_XRAY_RECORDS_H