brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.3 KiB · d3fd253 Raw
59 lines · cpp
1// RUN: rm -rf %t && mkdir %t2// RUN: %clangxx_xray -g -std=c++11 %s -o %t.exe3// RUN: env XRAY_OPTIONS="patch_premain=false \4// RUN:    xray_logfile_base=%t/ xray_mode=xray-fdr verbosity=1" \5// RUN:    XRAY_FDR_OPTIONS=func_duration_threshold_us=0 %run %t.exe 2>&1 | \6// RUN:    FileCheck %s7// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t.exe %t/*8// RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t.exe %t/* | \9// RUN:   FileCheck %s --check-prefix TRACE10 11// REQUIRES: target={{(aarch64|loongarch64|x86_64)-.*}}12// REQUIRES: built-in-llvm-tree13 14#include "xray/xray_log_interface.h"15#include <atomic>16#include <cassert>17#include <thread>18 19std::atomic<uint64_t> var{0};20 21[[clang::xray_always_instrument]] void __attribute__((noinline)) f1() {22  for (auto i = 0; i < 1 << 20; ++i)23    ++var;24}25 26[[clang::xray_always_instrument]] void __attribute__((noinline)) f2() {27  for (auto i = 0; i < 1 << 20; ++i)28    ++var;29}30 31int main(int argc, char *argv[]) {32  __xray_patch();33  assert(__xray_log_init_mode("xray-fdr", "") ==34         XRayLogInitStatus::XRAY_LOG_INITIALIZED);35 36  std::atomic_thread_fence(std::memory_order_acq_rel);37 38  {39    std::thread t1([] { f1(); });40    std::thread t2([] { f2(); });41    t1.join();42    t2.join();43  }44 45  std::atomic_thread_fence(std::memory_order_acq_rel);46  __xray_log_finalize();47  __xray_log_flushLog();48  __xray_unpatch();49  return var > 0 ? 0 : 1;50  // CHECK: {{.*}}XRay: Log file in '{{.*}}'51  // CHECK-NOT: Failed52}53 54// We want to make sure that the order of the function log doesn't matter.55// TRACE-DAG: - { type: 0, func-id: [[FID1:[0-9]+]], function: {{.*f1.*}}, cpu: {{.*}}, thread: [[THREAD1:[0-9]+]], process: [[PROCESS:[0-9]+]], kind: function-enter, tsc: {{[0-9]+}}, data: '' }56// TRACE-DAG: - { type: 0, func-id: [[FID2:[0-9]+]], function: {{.*f2.*}}, cpu: {{.*}}, thread: [[THREAD2:[0-9]+]], process: [[PROCESS]], kind: function-enter, tsc: {{[0-9]+}}, data: '' }57// TRACE-DAG: - { type: 0, func-id: [[FID1]], function: {{.*f1.*}}, cpu: {{.*}}, thread: [[THREAD1]], process: [[PROCESS]], kind: {{function-exit|function-tail-exit}}, tsc: {{[0-9]+}}, data: '' }58// TRACE-DAG: - { type: 0, func-id: [[FID2]], function: {{.*f2.*}}, cpu: {{.*}}, thread: [[THREAD2]], process: [[PROCESS]], kind: {{function-exit|function-tail-exit}}, tsc: {{[0-9]+}}, data: '' }59