bitcoin/cmake/module/FindUSDT.cmake
0xb10c d524c1ec06
tracing: dedup TRACE macros & rename to TRACEPOINT
This deduplicates the TRACEx macros by using systemtaps STAP_PROBEV[0]
variadic macro instead of the DTrace compability DTRACE_PROBE[1] macros.
Bitcoin Core never had DTrace tracepoints, so we don't need to use the
drop-in replacement for it. As noted in pr25541[2], these macros aren't
compatibile with DTrace on macOS anyway.

This also renames the TRACEx macro to TRACEPOINT to clarify what the
macro does: inserting a tracepoint vs tracing (logging) something.

[0]: https://sourceware.org/git/?p=systemtap.git;a=blob;f=includes/sys/sdt.h;h=24d5e01c37805e55c36f7202e5d4e821b85167a1;hb=ecab2afea46099b4e7dfd551462689224afdbe3a#l407
[1]: https://sourceware.org/git/?p=systemtap.git;a=blob;f=includes/sys/sdt.h;h=24d5e01c37805e55c36f7202e5d4e821b85167a1;hb=ecab2afea46099b4e7dfd551462689224afdbe3a#l490
[2]: https://github.com/bitcoin/bitcoin/pull/25541/files#diff-553886c5f808e01e3452c7b21e879cc355da388ef7680bf310f6acb926d43266R30-R31

Co-authored-by: Martin Leitner-Ankerl <martin.ankerl@gmail.com>
2024-10-28 14:23:47 +01:00

67 lines
1.7 KiB
CMake

# 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("
// Setting SDT_USE_VARIADIC lets systemtap (sys/sdt.h) know that we want to use
// the optional variadic macros to define tracepoints.
#define SDT_USE_VARIADIC 1
#include <sys/sdt.h>
int main()
{
STAP_PROBEV(context, event);
int a, b, c, d, e, f, g;
STAP_PROBEV(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()