diff options
author | Dean Michael Berris <dberris@google.com> | 2018-03-07 02:45:14 +0000 |
---|---|---|
committer | Dean Michael Berris <dberris@google.com> | 2018-03-07 02:45:14 +0000 |
commit | 74e7bc0d6590da2181fae37627e2658a4af6e487 (patch) | |
tree | 0cc9703e49adf7766e908ccfedd867fd305fe608 /test/xray | |
parent | 2e65830de05d20662908cce16498e139fe29887c (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 'test/xray')
-rw-r--r-- | test/xray/TestCases/Posix/logging-modes.cc | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/test/xray/TestCases/Posix/logging-modes.cc b/test/xray/TestCases/Posix/logging-modes.cc index 22f6942b7..b846cf675 100644 --- a/test/xray/TestCases/Posix/logging-modes.cc +++ b/test/xray/TestCases/Posix/logging-modes.cc @@ -9,6 +9,7 @@ #include "xray/xray_log_interface.h" #include <cassert> #include <cstdio> +#include <string> [[clang::xray_never_instrument]] void printing_handler(int32_t fid, XRayEntryType) { @@ -20,8 +21,19 @@ printing = false; } +[[clang::xray_never_instrument]] XRayBuffer next_buffer(XRayBuffer buffer) { + static const char data[10] = {}; + static const XRayBuffer first_and_last{data, 10}; + if (buffer.Data == nullptr) + return first_and_last; + if (buffer.Data == first_and_last.Data) + return XRayBuffer{nullptr, 0}; + assert(false && "Invalid buffer provided."); +} + [[clang::xray_never_instrument]] XRayLogInitStatus printing_init(size_t, size_t, void *, size_t) { + __xray_log_set_buffer_iterator(next_buffer); return XRayLogInitStatus::XRAY_LOG_INITIALIZED; } @@ -30,11 +42,16 @@ printing_init(size_t, size_t, void *, size_t) { } [[clang::xray_never_instrument]] XRayLogFlushStatus printing_flush_log() { + __xray_log_remove_buffer_iterator(); return XRayLogFlushStatus::XRAY_LOG_FLUSHED; } [[clang::xray_always_instrument]] void callme() { std::printf("called me!\n"); } +static auto buffer_counter = 0; + +void process_buffer(const char *, XRayBuffer) { ++buffer_counter; } + static bool unused = [] { assert(__xray_log_register_mode("custom", {printing_init, printing_finalize, @@ -46,6 +63,9 @@ static bool unused = [] { int main(int argc, char **argv) { assert(__xray_log_select_mode("custom") == XRayLogRegisterStatus::XRAY_REGISTRATION_OK); + assert(__xray_log_get_current_mode() != nullptr); + std::string current_mode = __xray_log_get_current_mode(); + assert(current_mode == "custom"); assert(__xray_patch() == XRayPatchingStatus::SUCCESS); assert(__xray_log_init(0, 0, nullptr, 0) == XRayLogInitStatus::XRAY_LOG_INITIALIZED); @@ -53,6 +73,9 @@ int main(int argc, char **argv) { callme(); // CHECK: called me! // CHECK: printing {{.*}} assert(__xray_log_finalize() == XRayLogInitStatus::XRAY_LOG_FINALIZED); + assert(__xray_log_process_buffers(process_buffer) == + XRayLogFlushStatus::XRAY_LOG_FLUSHED); + assert(buffer_counter == 1); assert(__xray_log_flushLog() == XRayLogFlushStatus::XRAY_LOG_FLUSHED); assert(__xray_log_select_mode("not-found") == XRayLogRegisterStatus::XRAY_MODE_NOT_FOUND); |