brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · ffe43c9 Raw
78 lines · cpp
1// RUN: %clangxx_xray -g -std=c++11 %s -o %t -fxray-modes=xray-fdr2// RUN: rm -rf %t.dir3// RUN: mkdir -p %t.dir4// RUN: cd %t.dir5// RUN: env XRAY_OPTIONS="patch_premain=false xray_logfile_base=fdr-inmemory-test- \6// RUN:     verbosity=1" \7// RUN: env XRAY_FDR_OPTIONS="no_file_flush=true func_duration_threshold_us=0" \8// RUN:     %run %t 2>&1 | FileCheck %s9// RUN: find %t.dir -name 'fdr-inmemory-test-*' | wc -l | tr -d '\n' > %t.file_count10// RUN: %python -c "import sys; sys.exit(int(sys.argv[1]))" %{readfile:%t.file_count} 11// RUN: rm -rf %t.dir12//13// REQUIRES: built-in-llvm-tree14 15#include "xray/xray_log_interface.h"16#include <cassert>17#include <iostream>18 19uint64_t var = 0;20uint64_t buffers = 0;21[[clang::xray_always_instrument]] void __attribute__((noinline)) f() { ++var; }22 23int main(int argc, char *argv[]) {24  assert(__xray_log_select_mode("xray-fdr") ==25         XRayLogRegisterStatus::XRAY_REGISTRATION_OK);26  auto status = __xray_log_init_mode(27      "xray-fdr",28      "buffer_size=4096:buffer_max=10:func_duration_threshold_us=0");29  assert(status == XRayLogInitStatus::XRAY_LOG_INITIALIZED);30  __xray_patch();31 32  // Create enough entries.33  for (int i = 0; i != 1 << 20; ++i) {34    f();35  }36 37  // Then we want to verify that we're getting 10 buffers outside of the initial38  // header.39  auto finalize_status = __xray_log_finalize();40  assert(finalize_status == XRayLogInitStatus::XRAY_LOG_FINALIZED);41  auto process_status =42      __xray_log_process_buffers([](const char *, XRayBuffer) { ++buffers; });43  std::cout << "buffers = " << buffers << std::endl;44  assert(process_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED);45  auto flush_status = __xray_log_flushLog();46  assert(flush_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED);47  // We expect 11 buffers because 1 header buffer + 10 actual FDR buffers.48  // CHECK: Buffers = 1149  std::cout << "Buffers = " << buffers << std::endl;50 51  // In this test we ensure that we can restart the cycle after the flush.52  status = __xray_log_init_mode(53      "xray-fdr",54      "buffer_size=4096:buffer_max=10:func_duration_threshold_us=0");55  assert(status == XRayLogInitStatus::XRAY_LOG_INITIALIZED);56  __xray_patch();57 58  // Create enough entries.59  for (int i = 0; i != 1 << 20; ++i) {60    f();61  }62 63  // Then we want to verify that we're getting 10 buffers outside of the initial64  // header.65  finalize_status = __xray_log_finalize();66  assert(finalize_status == XRayLogInitStatus::XRAY_LOG_FINALIZED);67  process_status =68      __xray_log_process_buffers([](const char *, XRayBuffer) { ++buffers; });69  std::cout << "buffers = " << buffers << std::endl;70  assert(process_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED);71  flush_status = __xray_log_flushLog();72  assert(flush_status == XRayLogFlushStatus::XRAY_LOG_FLUSHED);73  // We expect 22 buffers because 1 header buffer + 10 actual FDR buffers, plus74  // the number of buffers we got from the previous run (also 11).75  // CHECK: Buffers = 2276  std::cout << "Buffers = " << buffers << std::endl;77}78