Skip to content

Commit 6397f26

Browse files
committed
xray: add global xray instrumentation support
1 parent 5f938c9 commit 6397f26

4 files changed

Lines changed: 27 additions & 1 deletion

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
*.stderr
2222
*.stdout
2323

24+
# llvm-xray logs
25+
xray-log.*
26+
2427
/docs/build
2528
/docs/publish
2629
/docs/edit

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ add_library(global-libs INTERFACE)
119119

120120
include (cmake/sanitize.cmake)
121121

122+
include (cmake/instrument.cmake)
123+
122124
option(ENABLE_COLORED_BUILD "Enable colors in compiler output" ON)
123125

124126
set (CMAKE_COLOR_MAKEFILE ${ENABLE_COLORED_BUILD}) # works only for the makefile generator

cmake/instrument.cmake

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# https://llvm.org/docs/XRay.html
2+
3+
option (ENABLE_XRAY "Enable LLVM XRay" OFF)
4+
5+
if (NOT ENABLE_XRAY)
6+
message (STATUS "Not using LLVM XRay")
7+
return()
8+
endif()
9+
10+
if (NOT (ARCH_AMD64 AND (OS_LINUX OR OS_FREEBSD)))
11+
message (STATUS "Not using LLVM XRay, only amd64 Linux or FreeBSD are supported")
12+
return()
13+
endif()
14+
15+
# The target clang must support xray, otherwise it should error on invalid option
16+
set (XRAY_FLAGS "-fxray-instrument -DUSE_XRAY")
17+
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${XRAY_FLAGS}")
18+
set (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${XRAY_FLAGS}")
19+
20+
message (STATUS "Using LLVM XRay")

src/Daemon/BaseDaemon.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -738,6 +738,7 @@ std::string BaseDaemon::getDefaultConfigFileName() const
738738

739739
void BaseDaemon::closeFDs()
740740
{
741+
#if !defined(USE_XRAY)
741742
/// NOTE: may benefit from close_range() (linux 5.9+)
742743
#if defined(OS_FREEBSD) || defined(OS_DARWIN)
743744
fs::path proc_path{"/dev/fd"};
@@ -785,13 +786,13 @@ void BaseDaemon::closeFDs()
785786
}
786787
}
787788
}
789+
#endif
788790
}
789791

790792

791793
void BaseDaemon::initialize(Application & self)
792794
{
793795
closeFDs();
794-
795796
ServerApplication::initialize(self);
796797

797798
/// now highest priority (lowest value) is PRIO_APPLICATION = -100, we want higher!

0 commit comments

Comments
 (0)