summaryrefslogtreecommitdiff
path: root/include/xray
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2018-03-07 02:45:14 +0000
committerDean Michael Berris <dberris@google.com>2018-03-07 02:45:14 +0000
commit74e7bc0d6590da2181fae37627e2658a4af6e487 (patch)
tree0cc9703e49adf7766e908ccfedd867fd305fe608 /include/xray
parent2e65830de05d20662908cce16498e139fe29887c (diff)
[XRay][compiler-rt] Add APIs for processing logs in memory
Summary: This change adds APIs to allow logging implementations to provide a function for iterating through in-memory buffers (if they hold in-memory buffers) and a way for users to generically deal with these buffers in-process. These APIs are: - __xray_log_set_buffer_iterator(...) and __xray_log_remove_buffer_iterator(): installs and removes an iterator function that takes an XRayBuffer and yields the next one. - __xray_log_process_buffers(...): takes a function pointer that can take a mode identifier (string) and an XRayBuffer to process this data as they see fit. The intent is to have the FDR mode implementation's buffers be available through this `__xray_log_process_buffers(...)` API, so that they can be streamed from memory instead of flushed to disk (useful for getting the data to a network, or doing in-process analysis). Basic mode logging will not support this mechanism as it's designed to write the data mostly to disk. Future implementations will may depend on this API as well, to allow for programmatically working through the XRay buffers exposed to the users in some fashion. Reviewers: eizan, kpw, pelikan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D43495 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@326866 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/xray')
-rw-r--r--include/xray/xray_log_interface.h64
1 files changed, 64 insertions, 0 deletions
diff --git a/include/xray/xray_log_interface.h b/include/xray/xray_log_interface.h
index 6c53cdaeb..5b24b5f40 100644
--- a/include/xray/xray_log_interface.h
+++ b/include/xray/xray_log_interface.h
@@ -72,6 +72,17 @@
/// // deal with the error here, if it is an error.
/// }
///
+/// // Alternatively, we can go through the buffers ourselves without
+/// // relying on the implementations' flushing semantics (if the
+/// // implementation supports exporting this data directly).
+/// auto MyBufferProcessor = +[](const char* mode, XRayBuffer buffer) {
+/// // Check the "mode" to see if it's something we know how to handle...
+/// // and/or do something with an XRayBuffer instance.
+/// };
+/// auto process_status = __xray_log_process_buffers(MyBufferProcessor);
+/// if (process_status != XRayLogFlushStatus::XRAY_LOG_FLUSHED) {
+/// // deal with the error here, if it is an error.
+/// }
///
/// NOTE: Before calling __xray_patch() again, consider re-initializing the
/// implementation first. Some implementations might stay in an "off" state when
@@ -227,6 +238,11 @@ XRayLogRegisterStatus __xray_log_register_mode(const char *Mode,
/// does not update the currently installed implementation.
XRayLogRegisterStatus __xray_log_select_mode(const char *Mode);
+/// Returns an identifier for the currently selected XRay mode chosen through
+/// the __xray_log_select_mode(...) function call. Returns nullptr if there is
+/// no currently installed mode.
+const char *__xray_log_get_current_mode();
+
/// This function removes the currently installed implementation. It will also
/// uninstall any handlers that have been previously installed. It does NOT
/// unpatch the instrumentation sleds.
@@ -257,6 +273,54 @@ XRayLogInitStatus __xray_log_finalize();
/// XRayLogFlushStatus for what the return values mean.
XRayLogFlushStatus __xray_log_flushLog();
+/// An XRayBuffer represents a section of memory which can be treated by log
+/// processing functions as bytes stored in the logging implementation's
+/// buffers.
+struct XRayBuffer {
+ const void *Data;
+ size_t Size;
+};
+
+/// Registers an iterator function which takes an XRayBuffer argument, then
+/// returns another XRayBuffer function representing the next buffer. When the
+/// Iterator function returns an empty XRayBuffer (Data = nullptr, Size = 0),
+/// this signifies the end of the buffers.
+///
+/// The first invocation of this Iterator function will always take an empty
+/// XRayBuffer (Data = nullptr, Size = 0).
+void __xray_log_set_buffer_iterator(XRayBuffer (*Iterator)(XRayBuffer));
+
+/// Removes the currently registered buffer iterator function.
+void __xray_log_remove_buffer_iterator();
+
+/// Invokes the provided handler to process data maintained by the logging
+/// handler. This API will be provided raw access to the data available in
+/// memory from the logging implementation. The callback function must:
+///
+/// 1) Not modify the data, to avoid running into undefined behaviour.
+///
+/// 2) Either know the data layout, or treat the data as raw bytes for later
+/// interpretation.
+///
+/// This API is best used in place of the `__xray_log_flushLog()` implementation
+/// above to enable the caller to provide an alternative means of extracting the
+/// data from the XRay implementation.
+///
+/// Implementations MUST then provide:
+///
+/// 1) A function that will return an XRayBuffer. Functions that return an
+/// "empty" XRayBuffer signifies that there are no more buffers to be
+/// processed. This function should be registered through the
+/// `__xray_log_set_buffer_iterator(...)` function.
+///
+/// 2) Its own means of converting data it holds in memory into an XRayBuffer
+/// structure.
+///
+/// See XRayLogFlushStatus for what the return values mean.
+///
+XRayLogFlushStatus __xray_log_process_buffers(void (*Processor)(const char *,
+ XRayBuffer));
+
} // extern "C"
namespace __xray {