summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2016-08-26 06:39:33 +0000
committerDean Michael Berris <dberris@google.com>2016-08-26 06:39:33 +0000
commit403c24eb3557e96900db521b710391fc1e1dca31 (patch)
treedac66ebfd594ad5c5a33980c52cad0aad0c04759 /include
parent03689a458bbaa4fb04509f4d32a9605940472d9c (diff)
[compiler-rt][XRay] Initial per-thread inmemory logging implementation
Depends on D21612 which implements the building blocks for the compiler-rt implementation of the XRay runtime. We use a naive in-memory log of fixed-size entries that get written out to a log file when the buffers are full, and when the thread exits. This implementation lays some foundations on to allowing for more complex XRay records to be written to the log in subsequent changes. It also defines the format that the function call accounting tool in D21987 will start building upon. Once D21987 lands, we should be able to start defining more tests using that tool once the function call accounting tool becomes part of the llvm distribution. Reviewers: echristo, kcc, rnk, eugenis, majnemer, rSerge Subscribers: sdardis, rSerge, dberris, tberghammer, danalbert, srhines, majnemer, llvm-commits, mehdi_amini Differential Revision: https://reviews.llvm.org/D21982 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@279805 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include')
-rw-r--r--include/xray/xray_records.h80
1 files changed, 80 insertions, 0 deletions
diff --git a/include/xray/xray_records.h b/include/xray/xray_records.h
new file mode 100644
index 000000000..34c236b39
--- /dev/null
+++ b/include/xray/xray_records.h
@@ -0,0 +1,80 @@
+//===-- 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
+
+namespace __xray {
+
+enum FileTypes {
+ NAIVE_LOG = 0,
+};
+
+// 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;
+} __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