1 // RUN: %clangxx_xray -g -std=c++11 %s -o %t -fxray-modes=xray-fdr
2 // RUN: rm -f fdr-inmemory-test-*
3 // RUN: XRAY_OPTIONS="patch_premain=false xray_logfile_base=fdr-inmemory-test- \
5 // RUN: XRAY_FDR_OPTIONS="no_file_flush=true func_duration_threshold_us=0" \
6 // RUN: %run %t 2>&1 | FileCheck %s
7 // RUN: FILES=`find %T -name 'fdr-inmemory-test-*' | wc -l`
8 // RUN: [ $FILES -eq 0 ]
9 // RUN: rm -f fdr-inmemory-test-*
11 // REQUIRES: built-in-llvm-tree
13 #include "xray/xray_log_interface.h"
19 [[clang::xray_always_instrument
]] void __attribute__((noinline
)) f() { ++var
; }
21 int main(int argc
, char *argv
[]) {
22 assert(__xray_log_select_mode("xray-fdr") ==
23 XRayLogRegisterStatus::XRAY_REGISTRATION_OK
);
24 auto status
= __xray_log_init_mode(
26 "buffer_size=4096:buffer_max=10:func_duration_threshold_us=0");
27 assert(status
== XRayLogInitStatus::XRAY_LOG_INITIALIZED
);
30 // Create enough entries.
31 for (int i
= 0; i
!= 1 << 20; ++i
) {
35 // Then we want to verify that we're getting 10 buffers outside of the initial
37 auto finalize_status
= __xray_log_finalize();
38 assert(finalize_status
== XRayLogInitStatus::XRAY_LOG_FINALIZED
);
40 __xray_log_process_buffers([](const char *, XRayBuffer
) { ++buffers
; });
41 std::cout
<< "buffers = " << buffers
<< std::endl
;
42 assert(process_status
== XRayLogFlushStatus::XRAY_LOG_FLUSHED
);
43 auto flush_status
= __xray_log_flushLog();
44 assert(flush_status
== XRayLogFlushStatus::XRAY_LOG_FLUSHED
);
45 // We expect 11 buffers because 1 header buffer + 10 actual FDR buffers.
46 // CHECK: Buffers = 11
47 std::cout
<< "Buffers = " << buffers
<< std::endl
;