Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / xray / TestCases / Posix / fdr-thread-order.cpp
blob85284fc27ab38f0056f2f778bb9c6072e66b7957
1 // RUN: rm -rf %t && mkdir %t
2 // RUN: %clangxx_xray -g -std=c++11 %s -o %t.exe
3 // RUN: 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 %s
7 // 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 TRACE
11 // REQUIRES: target={{(aarch64|loongarch64|x86_64)-.*}}
12 // REQUIRES: built-in-llvm-tree
14 #include "xray/xray_log_interface.h"
15 #include <atomic>
16 #include <cassert>
17 #include <thread>
19 std::atomic<uint64_t> var{0};
21 [[clang::xray_always_instrument]] void __attribute__((noinline)) f1() {
22 for (auto i = 0; i < 1 << 20; ++i)
23 ++var;
26 [[clang::xray_always_instrument]] void __attribute__((noinline)) f2() {
27 for (auto i = 0; i < 1 << 20; ++i)
28 ++var;
31 int main(int argc, char *argv[]) {
32 __xray_patch();
33 assert(__xray_log_init_mode("xray-fdr", "") ==
34 XRayLogInitStatus::XRAY_LOG_INITIALIZED);
36 std::atomic_thread_fence(std::memory_order_acq_rel);
39 std::thread t1([] { f1(); });
40 std::thread t2([] { f2(); });
41 t1.join();
42 t2.join();
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: Failed
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: '' }