Bitcoin Core
28.99.0
P2P Digital Currency
src
util
trace.h
Go to the documentation of this file.
1
// Copyright (c) 2020-2021 The Bitcoin Core developers
2
// Distributed under the MIT software license, see the accompanying
3
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
4
5
#ifndef BITCOIN_UTIL_TRACE_H
6
#define BITCOIN_UTIL_TRACE_H
7
8
#include <bitcoin-build-config.h>
// IWYU pragma: keep
9
10
#ifdef ENABLE_TRACING
11
12
// Setting SDT_USE_VARIADIC lets systemtap (sys/sdt.h) know that we want to use
13
// the optional variadic macros to define tracepoints.
14
#define SDT_USE_VARIADIC 1
15
16
// Setting _SDT_HAS_SEMAPHORES let's systemtap (sys/sdt.h) know that we want to
17
// use the optional semaphore feature for our tracepoints. This feature allows
18
// us to check if something is attached to a tracepoint. We only want to prepare
19
// some potentially expensive tracepoint arguments, if the tracepoint is being
20
// used. Here, an expensive argument preparation could, for example, be
21
// calculating a hash or serialization of a data structure.
22
#define _SDT_HAS_SEMAPHORES 1
23
24
// Used to define a counting semaphore for a tracepoint. This semaphore is
25
// automatically incremented by tracing frameworks (bpftrace, bcc, libbpf, ...)
26
// upon attaching to the tracepoint and decremented when detaching. This needs
27
// to be a global variable. It's placed in the '.probes' ELF section.
28
#define TRACEPOINT_SEMAPHORE(context, event) \
29
unsigned short context##_##event##_semaphore __attribute__((section(".probes"
)))
30
31
#include <sys/sdt.h>
32
33
// Returns true if something is attached to the tracepoint.
34
#define TRACEPOINT_ACTIVE(context, event) (context##_##event##_semaphore > 0)
35
36
// A USDT tracepoint with one to twelve arguments. It's checked that the
37
// tracepoint is active before preparing its arguments.
38
#define TRACEPOINT(context, event, ...) \
39
do { \
40
if (TRACEPOINT_ACTIVE(context, event)) { \
41
STAP_PROBEV(context, event __VA_OPT__(, ) __VA_ARGS__); \
42
} \
43
} while(0)
44
45
#else
46
47
#define TRACEPOINT_SEMAPHORE(context, event)
48
#define TRACEPOINT_ACTIVE(context, event) false
49
#define TRACEPOINT(context, ...)
50
51
#endif
// ENABLE_TRACING
52
53
54
#endif
// BITCOIN_UTIL_TRACE_H
Generated on Tue Dec 17 2024 20:00:14 for Bitcoin Core by
1.9.4