Merge pull request #64592 from tomershafir/xray

xray: add global xray instrumentation support
This commit is contained in:
Alexey Milovidov 2024-06-05 01:25:25 +02:00 committed by GitHub
commit 5a5bdd87cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 1 deletions

3
.gitignore vendored
View File

@ -21,6 +21,9 @@
*.stderr *.stderr
*.stdout *.stdout
# llvm-xray logs
xray-log.*
/docs/build /docs/build
/docs/publish /docs/publish
/docs/edit /docs/edit

View File

@ -122,6 +122,8 @@ add_library(global-libs INTERFACE)
include (cmake/sanitize.cmake) include (cmake/sanitize.cmake)
include (cmake/instrument.cmake)
option(ENABLE_COLORED_BUILD "Enable colors in compiler output" ON) option(ENABLE_COLORED_BUILD "Enable colors in compiler output" ON)
set (CMAKE_COLOR_MAKEFILE ${ENABLE_COLORED_BUILD}) # works only for the makefile generator set (CMAKE_COLOR_MAKEFILE ${ENABLE_COLORED_BUILD}) # works only for the makefile generator

20
cmake/instrument.cmake Normal file
View File

@ -0,0 +1,20 @@
# https://llvm.org/docs/XRay.html
option (ENABLE_XRAY "Enable LLVM XRay" OFF)
if (NOT ENABLE_XRAY)
message (STATUS "Not using LLVM XRay")
return()
endif()
if (NOT (ARCH_AMD64 AND (OS_LINUX OR OS_FREEBSD)))
message (STATUS "Not using LLVM XRay, only amd64 Linux or FreeBSD are supported")
return()
endif()
# The target clang must support xray, otherwise it should error on invalid option
set (XRAY_FLAGS "-fxray-instrument -DUSE_XRAY")
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${XRAY_FLAGS}")
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XRAY_FLAGS}")
message (STATUS "Using LLVM XRay")

View File

@ -742,6 +742,7 @@ std::string BaseDaemon::getDefaultConfigFileName() const
void BaseDaemon::closeFDs() void BaseDaemon::closeFDs()
{ {
#if !defined(USE_XRAY)
/// NOTE: may benefit from close_range() (linux 5.9+) /// NOTE: may benefit from close_range() (linux 5.9+)
#if defined(OS_FREEBSD) || defined(OS_DARWIN) #if defined(OS_FREEBSD) || defined(OS_DARWIN)
fs::path proc_path{"/dev/fd"}; fs::path proc_path{"/dev/fd"};
@ -789,13 +790,13 @@ void BaseDaemon::closeFDs()
} }
} }
} }
#endif
} }
void BaseDaemon::initialize(Application & self) void BaseDaemon::initialize(Application & self)
{ {
closeFDs(); closeFDs();
ServerApplication::initialize(self); ServerApplication::initialize(self);
/// now highest priority (lowest value) is PRIO_APPLICATION = -100, we want higher! /// now highest priority (lowest value) is PRIO_APPLICATION = -100, we want higher!