summaryrefslogtreecommitdiffstats
path: root/compiler-rt/lib/xray/xray_buffer_queue.h
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2017-01-03 03:38:17 +0000
committerDean Michael Berris <dberris@google.com>2017-01-03 03:38:17 +0000
commit33d305b54b0b4cc8c03b6d53a12f8a3f5ebf9d9b (patch)
treeb5fa32974a7c75d720b0b5f99bd242ada54d1251 /compiler-rt/lib/xray/xray_buffer_queue.h
parentedd09b3db2a40e6e1e39e0a74411a354398417f3 (diff)
downloadbcm5719-llvm-33d305b54b0b4cc8c03b6d53a12f8a3f5ebf9d9b.tar.gz
bcm5719-llvm-33d305b54b0b4cc8c03b6d53a12f8a3f5ebf9d9b.zip
[XRay][compiler-rt] XRay Flight Data Recorder Mode
Summary: In this change we introduce the notion of a "flight data recorder" mode for XRay logging, where XRay logs in-memory first, and write out data on-demand as required (as opposed to the naive implementation that keeps logging while tracing is "on"). This depends on D26232 where we implement the core data structure for holding the buffers that threads will be using to write out records of operation. This implementation only currently works on x86_64 and depends heavily on the TSC math to write out smaller records to the inmemory buffers. Also, this implementation defines two different kinds of records with different sizes (compared to the current naive implementation): a MetadataRecord (16 bytes) and a FunctionRecord (8 bytes). MetadataRecord entries are meant to write out information like the thread ID for which the metadata record is defined for, whether the execution of a thread moved to a different CPU, etc. while a FunctionRecord represents the different kinds of function call entry/exit records we might encounter in the course of a thread's execution along with a delta from the last time the logging handler was called. While this implementation is not exactly what is described in the original XRay whitepaper, this one gives us an initial implementation that we can iterate and build upon. Reviewers: echristo, rSerge, majnemer Subscribers: mehdi_amini, llvm-commits, mgorny Differential Revision: https://reviews.llvm.org/D27038 llvm-svn: 290852
Diffstat (limited to 'compiler-rt/lib/xray/xray_buffer_queue.h')
-rw-r--r--compiler-rt/lib/xray/xray_buffer_queue.h37
1 files changed, 27 insertions, 10 deletions
diff --git a/compiler-rt/lib/xray/xray_buffer_queue.h b/compiler-rt/lib/xray/xray_buffer_queue.h
index bf0b7af9df4..c6926e00209 100644
--- a/compiler-rt/lib/xray/xray_buffer_queue.h
+++ b/compiler-rt/lib/xray/xray_buffer_queue.h
@@ -21,6 +21,7 @@
#include <mutex>
#include <system_error>
#include <unordered_set>
+#include <utility>
namespace __xray {
@@ -38,14 +39,18 @@ public:
private:
std::size_t BufferSize;
- std::deque<Buffer> Buffers;
+
+ // We use a bool to indicate whether the Buffer has been used in this
+ // freelist implementation.
+ std::deque<std::tuple<Buffer, bool>> Buffers;
std::mutex Mutex;
std::unordered_set<void *> OwnedBuffers;
std::atomic<bool> Finalizing;
public:
- /// Initialise a queue of size |N| with buffers of size |B|.
- BufferQueue(std::size_t B, std::size_t N);
+ /// Initialise a queue of size |N| with buffers of size |B|. We report success
+ /// through |Success|.
+ BufferQueue(std::size_t B, std::size_t N, bool& Success);
/// Updates |Buf| to contain the pointer to an appropriate buffer. Returns an
/// error in case there are no available buffers to return when we will run
@@ -68,15 +73,27 @@ public:
bool finalizing() const { return Finalizing.load(std::memory_order_acquire); }
- // Sets the state of the BufferQueue to finalizing, which ensures that:
- //
- // - All subsequent attempts to retrieve a Buffer will fail.
- // - All releaseBuffer operations will not fail.
- //
- // After a call to finalize succeeds, all subsequent calls to finalize will
- // fail with std::errc::state_not_recoverable.
+ /// Sets the state of the BufferQueue to finalizing, which ensures that:
+ ///
+ /// - All subsequent attempts to retrieve a Buffer will fail.
+ /// - All releaseBuffer operations will not fail.
+ ///
+ /// After a call to finalize succeeds, all subsequent calls to finalize will
+ /// fail with std::errc::state_not_recoverable.
std::error_code finalize();
+ /// Applies the provided function F to each Buffer in the queue, only if the
+ /// Buffer is marked 'used' (i.e. has been the result of getBuffer(...) and a
+ /// releaseBuffer(...) operation.
+ template <class F> void apply(F Fn) {
+ std::lock_guard<std::mutex> G(Mutex);
+ for (const auto &T : Buffers) {
+ if (std::get<1>(T)) {
+ Fn(std::get<0>(T));
+ }
+ }
+ }
+
// Cleans up allocated buffers.
~BufferQueue();
};
OpenPOWER on IntegriCloud