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- \ |
4 | // RUN: verbosity=1" \ |
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-* |
10 | // |
11 | // REQUIRES: built-in-llvm-tree |
12 | |
13 | #include "xray/xray_log_interface.h" |
14 | #include <cassert> |
15 | #include <iostream> |
16 | |
17 | uint64_t var = 0; |
18 | uint64_t buffers = 0; |
19 | [[clang::xray_always_instrument]] void __attribute__((noinline)) f() { ++var; } |
20 | |
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( |
25 | Mode: "xray-fdr" , |
26 | Config: "buffer_size=4096:buffer_max=10:func_duration_threshold_us=0" ); |
27 | assert(status == XRayLogInitStatus::XRAY_LOG_INITIALIZED); |
28 | __xray_patch(); |
29 | |
30 | // Create enough entries. |
31 | for (int i = 0; i != 1 << 20; ++i) { |
32 | f(); |
33 | } |
34 | |
35 | // Then we want to verify that we're getting 10 buffers outside of the initial |
36 | // header. |
37 | auto finalize_status = __xray_log_finalize(); |
38 | assert(finalize_status == XRayLogInitStatus::XRAY_LOG_FINALIZED); |
39 | auto process_status = |
40 | __xray_log_process_buffers(Processor: [](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; |
48 | return 0; |
49 | } |
50 | |