summaryrefslogtreecommitdiff
path: root/test/xray
diff options
context:
space:
mode:
authorDean Michael Berris <dberris@google.com>2018-05-14 03:35:01 +0000
committerDean Michael Berris <dberris@google.com>2018-05-14 03:35:01 +0000
commit5a9177f73890bc7d385f0b53730ae3eb26a98376 (patch)
tree5a748add1114674886d031f0a0413c5cd9d3250b /test/xray
parent1aadbfb2c12bd64cab1c315b50960377fc422c9e (diff)
[XRay][compiler-rt] Support in-memory processing of FDR mode logs
Summary: This change allows for handling the in-memory data associated with the FDR mode implementation through the new `__xray_log_process_buffers` API. With this change, we can now allow users to process the data in-memory of the process instead of through writing files. This for example allows users to stream the data of the FDR logging implementation through network sockets, or through other mechanisms instead of saving them to local files. We introduce an FDR-specific flag, for "no_file_flush" which lets the flushing logic skip opening/writing to files. This option can be defaulted to `true` when building the compiler-rt XRay runtime through the `XRAY_FDR_OPTIONS` preprocessor macro. Reviewers: kpw, echristo, pelikan, eizan Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D46574 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@332208 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/xray')
-rw-r--r--test/xray/TestCases/Posix/fdr-mode-inmemory.cc50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/xray/TestCases/Posix/fdr-mode-inmemory.cc b/test/xray/TestCases/Posix/fdr-mode-inmemory.cc
new file mode 100644
index 000000000..db18cc459
--- /dev/null
+++ b/test/xray/TestCases/Posix/fdr-mode-inmemory.cc
@@ -0,0 +1,50 @@
+// RUN: %clangxx_xray -g -std=c++11 %s -o %t -fxray-modes=xray-fdr
+// RUN: rm fdr-inmemory-test-* || true
+// RUN: XRAY_OPTIONS="patch_premain=false xray_logfile_base=fdr-inmemory-test- \
+// RUN: verbosity=1" \
+// RUN: XRAY_FDR_OPTIONS="no_file_flush=true func_duration_threshold_us=0" \
+// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: FILES=`find %T -name 'fdr-inmemory-test-*' | wc -l`
+// RUN: [ $FILES -eq 0 ]
+// RUN: rm fdr-inmemory-test-* || true
+//
+// REQUIRES: x86_64-target-arch
+// REQUIRES: built-in-llvm-tree
+
+#include "xray/xray_log_interface.h"
+#include <cassert>
+#include <iostream>
+
+uint64_t var = 0;
+uint64_t buffers = 0;
+[[clang::xray_always_instrument]] void __attribute__((noinline)) f() { ++var; }
+
+int main(int argc, char *argv[]) {
+ assert(__xray_log_select_mode("xray-fdr") ==
+ XRayLogRegisterStatus::XRAY_REGISTRATION_OK);
+ auto status = __xray_log_init_mode(
+ "xray-fdr",
+ "buffer_size=4096:buffer_max=10:func_duration_threshold_us=0");
+ assert(status == XRayLogInitStatus::XRAY_LOG_INITIALIZED);
+ __xray_patch();
+
+ // Create enough entries.
+ for (int i = 0; i != 1 << 20; ++i) {
+ f();
+ }
+
+ // Then we want to verify that we're getting 10 buffers outside of the initial
+ // header.
+ auto finalize_status = __xray_log_finalize();
+ assert(finalize_status == XRayLogInitStatus::XRAY_LOG_FINALIZED);
+ auto process_status =
+ __xray_log_process_buffers([](const char *, XRayBuffer) { ++buffers; });
+ std::cout << "buffers = " << buffers << std::endl;
+ assert(process_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED);
+ auto flush_status = __xray_log_flushLog();
+ assert(flush_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED);
+ // We expect 11 buffers because 1 header buffer + 10 actual FDR buffers.
+ // CHECK: Buffers = 11
+ std::cout << "Buffers = " << buffers << std::endl;
+ return 0;
+}