brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.9 KiB · 58a800a Raw
52 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  return 0;51}52