1*6db8c59fSFangrui Song // Check that we can get a profile from a single-threaded application, on 2*6db8c59fSFangrui Song // demand through the XRay logging implementation API. 3*6db8c59fSFangrui Song // 4*6db8c59fSFangrui Song // FIXME: Make -fxray-modes=xray-profiling part of the default? 5*6db8c59fSFangrui Song // RUN: %clangxx_xray -std=c++11 %s -o %t -fxray-modes=xray-profiling 6*6db8c59fSFangrui Song // RUN: rm -f xray-log.profiling-single-* 7*6db8c59fSFangrui Song // RUN: XRAY_OPTIONS=verbosity=1 \ 8*6db8c59fSFangrui Song // RUN: XRAY_PROFILING_OPTIONS=no_flush=true %run %t 9*6db8c59fSFangrui Song // RUN: XRAY_OPTIONS=verbosity=1 %run %t 10*6db8c59fSFangrui Song // RUN: PROFILES=`ls xray-log.profiling-single-* | wc -l` 11*6db8c59fSFangrui Song // RUN: [ $PROFILES -eq 2 ] 12*6db8c59fSFangrui Song // RUN: rm -f xray-log.profiling-single-* 13*6db8c59fSFangrui Song // 14*6db8c59fSFangrui Song // REQUIRES: built-in-llvm-tree 15*6db8c59fSFangrui Song 16*6db8c59fSFangrui Song #include "xray/xray_interface.h" 17*6db8c59fSFangrui Song #include "xray/xray_log_interface.h" 18*6db8c59fSFangrui Song #include <cassert> 19*6db8c59fSFangrui Song #include <cstdio> 20*6db8c59fSFangrui Song #include <string> 21*6db8c59fSFangrui Song f2()22*6db8c59fSFangrui Song[[clang::xray_always_instrument]] void f2() { return; } f1()23*6db8c59fSFangrui Song[[clang::xray_always_instrument]] void f1() { f2(); } f0()24*6db8c59fSFangrui Song[[clang::xray_always_instrument]] void f0() { f1(); } 25*6db8c59fSFangrui Song 26*6db8c59fSFangrui Song using namespace std; 27*6db8c59fSFangrui Song 28*6db8c59fSFangrui Song volatile int buffer_counter = 0; 29*6db8c59fSFangrui Song process_buffer(const char *,XRayBuffer)30*6db8c59fSFangrui Song[[clang::xray_never_instrument]] void process_buffer(const char *, XRayBuffer) { 31*6db8c59fSFangrui Song // FIXME: Actually assert the contents of the buffer. 32*6db8c59fSFangrui Song ++buffer_counter; 33*6db8c59fSFangrui Song } 34*6db8c59fSFangrui Song main(int,char **)35*6db8c59fSFangrui Song[[clang::xray_always_instrument]] int main(int, char **) { 36*6db8c59fSFangrui Song assert(__xray_log_select_mode("xray-profiling") == 37*6db8c59fSFangrui Song XRayLogRegisterStatus::XRAY_REGISTRATION_OK); 38*6db8c59fSFangrui Song assert(__xray_log_get_current_mode() != nullptr); 39*6db8c59fSFangrui Song std::string current_mode = __xray_log_get_current_mode(); 40*6db8c59fSFangrui Song assert(current_mode == "xray-profiling"); 41*6db8c59fSFangrui Song assert(__xray_patch() == XRayPatchingStatus::SUCCESS); 42*6db8c59fSFangrui Song assert(__xray_log_init_mode("xray-profiling", "") == 43*6db8c59fSFangrui Song XRayLogInitStatus::XRAY_LOG_INITIALIZED); 44*6db8c59fSFangrui Song f0(); 45*6db8c59fSFangrui Song assert(__xray_log_finalize() == XRayLogInitStatus::XRAY_LOG_FINALIZED); 46*6db8c59fSFangrui Song f0(); 47*6db8c59fSFangrui Song assert(__xray_log_process_buffers(process_buffer) == 48*6db8c59fSFangrui Song XRayLogFlushStatus::XRAY_LOG_FLUSHED); 49*6db8c59fSFangrui Song // There's always at least one buffer, containing the profile file header. We 50*6db8c59fSFangrui Song // assert that we have two, to indicate that we're expecting exactly one 51*6db8c59fSFangrui Song // thread's worth of data. 52*6db8c59fSFangrui Song assert(buffer_counter == 2); 53*6db8c59fSFangrui Song assert(__xray_log_flushLog() == XRayLogFlushStatus::XRAY_LOG_FLUSHED); 54*6db8c59fSFangrui Song 55*6db8c59fSFangrui Song // Let's reset the counter. 56*6db8c59fSFangrui Song buffer_counter = 0; 57*6db8c59fSFangrui Song 58*6db8c59fSFangrui Song assert(__xray_log_init_mode("xray-profiling", "") == 59*6db8c59fSFangrui Song XRayLogInitStatus::XRAY_LOG_INITIALIZED); 60*6db8c59fSFangrui Song f0(); 61*6db8c59fSFangrui Song assert(__xray_log_finalize() == XRayLogInitStatus::XRAY_LOG_FINALIZED); 62*6db8c59fSFangrui Song f0(); 63*6db8c59fSFangrui Song assert(__xray_log_process_buffers(process_buffer) == 64*6db8c59fSFangrui Song XRayLogFlushStatus::XRAY_LOG_FLUSHED); 65*6db8c59fSFangrui Song assert(buffer_counter == 2); 66*6db8c59fSFangrui Song assert(__xray_log_flushLog() == XRayLogFlushStatus::XRAY_LOG_FLUSHED); 67*6db8c59fSFangrui Song } 68