From 353e0c9e9679864a777e17c1bb7c6ba8b6eac96d Mon Sep 17 00:00:00 2001 From: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com> Date: Wed, 24 Jul 2024 13:11:05 +0100 Subject: [PATCH] cmake: Add `systemtap-sdt` optional package support --- CMakeLists.txt | 6 ++++ cmake/bitcoin-config.h.in | 4 +++ cmake/module/FindUSDT.cmake | 64 +++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 2 ++ src/wallet/CMakeLists.txt | 1 + 5 files changed, 77 insertions(+) create mode 100644 cmake/module/FindUSDT.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 6630d75d18..c4f12e4acc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -133,6 +133,11 @@ if(WITH_ZMQ) endif() endif() +option(WITH_USDT "Enable tracepoints for Userspace, Statically Defined Tracing." OFF) +if(WITH_USDT) + find_package(USDT MODULE REQUIRED) +endif() + set(configure_warnings) include(CheckPIESupported) @@ -309,6 +314,7 @@ message(" port mapping:") message(" - using NAT-PMP .................... ${WITH_NATPMP}") message(" - using UPnP ....................... ${WITH_MINIUPNPC}") message(" ZeroMQ .............................. ${WITH_ZMQ}") +message(" USDT tracing ........................ ${WITH_USDT}") message("Tests:") message(" test_bitcoin ........................ ${BUILD_TESTS}") message("") diff --git a/cmake/bitcoin-config.h.in b/cmake/bitcoin-config.h.in index d046913ce8..04590fc609 100644 --- a/cmake/bitcoin-config.h.in +++ b/cmake/bitcoin-config.h.in @@ -38,6 +38,10 @@ /* Define this symbol to build code that uses SSE4.1 intrinsics */ #cmakedefine ENABLE_SSE41 1 +/* Define to 1 to enable tracepoints for Userspace, Statically Defined Tracing + */ +#cmakedefine ENABLE_TRACING 1 + /* Define to 1 to enable wallet functions. */ #cmakedefine ENABLE_WALLET 1 diff --git a/cmake/module/FindUSDT.cmake b/cmake/module/FindUSDT.cmake new file mode 100644 index 0000000000..0ba9a58fc1 --- /dev/null +++ b/cmake/module/FindUSDT.cmake @@ -0,0 +1,64 @@ +# Copyright (c) 2024-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +#[=======================================================================[ +FindUSDT +-------- + +Finds the Userspace, Statically Defined Tracing header(s). + +Imported Targets +^^^^^^^^^^^^^^^^ + +This module provides imported target ``USDT::headers``, if +USDT has been found. + +Result Variables +^^^^^^^^^^^^^^^^ + +This module defines the following variables: + +``USDT_FOUND`` + "True" if USDT found. + +#]=======================================================================] + +find_path(USDT_INCLUDE_DIR + NAMES sys/sdt.h +) +mark_as_advanced(USDT_INCLUDE_DIR) + +if(USDT_INCLUDE_DIR) + include(CMakePushCheckState) + cmake_push_check_state(RESET) + + include(CheckCXXSourceCompiles) + set(CMAKE_REQUIRED_INCLUDES ${USDT_INCLUDE_DIR}) + check_cxx_source_compiles(" + #include + + int main() + { + DTRACE_PROBE(context, event); + int a, b, c, d, e, f, g; + DTRACE_PROBE7(context, event, a, b, c, d, e, f, g); + } + " HAVE_USDT_H + ) + + cmake_pop_check_state() +endif() + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(USDT + REQUIRED_VARS USDT_INCLUDE_DIR HAVE_USDT_H +) + +if(USDT_FOUND AND NOT TARGET USDT::headers) + add_library(USDT::headers INTERFACE IMPORTED) + set_target_properties(USDT::headers PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${USDT_INCLUDE_DIR}" + ) + set(ENABLE_TRACING TRUE) +endif() diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index ec26f372c5..30942f4e0d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -141,6 +141,7 @@ target_link_libraries(bitcoin_common univalue secp256k1 Boost::headers + $ $<$:ws2_32> ) @@ -274,6 +275,7 @@ target_link_libraries(bitcoin_node $ $ $ + $ ) diff --git a/src/wallet/CMakeLists.txt b/src/wallet/CMakeLists.txt index 19a05b16aa..121e6e3c83 100644 --- a/src/wallet/CMakeLists.txt +++ b/src/wallet/CMakeLists.txt @@ -39,6 +39,7 @@ target_link_libraries(bitcoin_wallet bitcoin_common univalue Boost::headers + $ ) if(NOT USE_SQLITE AND NOT USE_BDB)