1 // Check to make sure that we are actually filtering records from the basic mode
2 // logging implementation.
3
4 // RUN: %clangxx_xray -std=c++11 %s -o %t -g
5 // RUN: rm -f basic-filtering-*
6 // RUN: XRAY_OPTIONS="patch_premain=true xray_mode=xray-basic verbosity=1 \
7 // RUN: xray_logfile_base=basic-filtering- \
8 // RUN: xray_naive_log_func_duration_threshold_us=1000 \
9 // RUN: xray_naive_log_max_stack_depth=2" %run %t 2>&1 | \
10 // RUN: FileCheck %s
11 // RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t \
12 // RUN: "`ls basic-filtering-* | head -1`" | \
13 // RUN: FileCheck %s --check-prefix TRACE
14 // RUN: rm -f basic-filtering-*
15 //
16 // Now check support for the XRAY_BASIC_OPTIONS environment variable.
17 // RUN: XRAY_OPTIONS="patch_premain=true xray_mode=xray-basic verbosity=1 \
18 // RUN: xray_logfile_base=basic-filtering-" \
19 // RUN: XRAY_BASIC_OPTIONS="func_duration_threshold_us=1000 max_stack_depth=2" \
20 // RUN: %run %t 2>&1 | FileCheck %s
21 // RUN: %llvm_xray convert --symbolize --output-format=yaml -instr_map=%t \
22 // RUN: "`ls basic-filtering-* | head -1`" | \
23 // RUN: FileCheck %s --check-prefix TRACE
24 // RUN: rm -f basic-filtering-*
25 //
26 // REQUIRES: x86_64-target-arch
27 // REQUIRES: built-in-llvm-tree
28
29 #include <cstdio>
30 #include <time.h>
31
filtered()32 [[clang::xray_always_instrument]] void __attribute__((noinline)) filtered() {
33 printf("filtered was called.\n");
34 }
35
beyond_stack()36 [[clang::xray_always_instrument]] void __attribute__((noinline)) beyond_stack() {
37 printf("beyond stack was called.\n");
38 }
39
40 [[clang::xray_always_instrument]] void __attribute__((noinline))
always_shows()41 always_shows() {
42 struct timespec sleep;
43 sleep.tv_nsec = 2000000;
44 sleep.tv_sec = 0;
45 struct timespec rem;
46 while (nanosleep(&sleep, &rem) == -1)
47 sleep = rem;
48 printf("always_shows was called.\n");
49 beyond_stack();
50 }
51
main(int argc,char * argv[])52 [[clang::xray_always_instrument]] int main(int argc, char *argv[]) {
53 filtered(); // CHECK: filtered was called.
54 always_shows(); // CHECK: always_shows was called.
55 // CHECK: beyond stack was called.
56 }
57
58 // TRACE-NOT: - { type: 0, func-id: {{.*}}, function: {{.*filtered.*}}, {{.*}} }
59 // TRACE-NOT: - { type: 0, func-id: {{.*}}, function: {{.*beyond_stack.*}}, {{.*}} }
60 // TRACE-DAG: - { type: 0, func-id: [[FID:[0-9]+]], function: {{.*always_shows.*}}, cpu: {{.*}}, thread: {{.*}}, kind: function-enter, tsc: {{[0-9]+}}, data: '' }
61 // TRACE-DAG: - { type: 0, func-id: [[FID]], function: {{.*always_shows.*}}, cpu: {{.*}}, thread: {{.*}}, kind: function-{{exit|tail-exit}}, tsc: {{[0-9]+}}, data: '' }
62