0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-14 11:26:09 -05:00
bitcoin-bitcoin-core/src
merge-script 19f277711e
Merge bitcoin/bitcoin#26593: tracing: Only prepare tracepoint arguments when actually tracing
0de3e96e33 tracing: use bitcoind pid in bcc tracing examples (0xb10c)
411c6cfc6c tracing: only prepare tracepoint args if attached (0xb10c)
d524c1ec06 tracing: dedup TRACE macros & rename to TRACEPOINT (0xb10c)

Pull request description:

  Currently, if the tracepoints are compiled (e.g. in depends and release builds), we always prepare the tracepoint arguments regardless of the tracepoints being used or not. We made sure that the argument preparation is as cheap as possible, but we can almost completely eliminate any overhead for users not interested in the tracepoints (the vast majority), by gating the tracepoint argument preparation with an `if(something is attached to this tracepoint)`. To achieve this, we use the optional semaphore feature provided by SystemTap.

  The first commit simplifies and deduplicates our tracepoint macros from 13 TRACEx macros to a single TRACEPOINT macro. This makes them easier to use and also avoids more duplicate macro definitions in the second commit.

  The Linux tracing tools I'm aware of (bcc, bpftrace, libbpf, and systemtap) all support the semaphore gating feature. Thus, all existing tracepoints and their argument preparation is gated in the second commit. For details, please refer to the commit messages and the updated documentation in `doc/tracing.md`.

  Also adding unit tests that include all tracepoint macros to make sure there are no compiler problems with them (e.g. some varadiac extension not supported).

  Reviewers might want to check:
  - Do the tracepoints still work for you? Do the examples in `contrib/tracing/` run on your system (as bpftrace frequently breaks on every new version, please test master too if it should't work for you)? Do the CI interface tests still pass?
  - Is the new documentation clear?
  - The `TRACEPOINT_SEMAPHORE(event, context)` macros places global variables in our global namespace. Is this something we strictly want to avoid or maybe move to all `TRACEPOINT_SEMAPHORE`s to a separate .cpp file or even namespace? I like having the `TRACEPOINT_SEMAPHORE()` in same file as the `TRACEPOINT()`, but open for suggestion on alternative approaches.
  - Are newly added tracepoints in the unit tests visible when using `readelf -n build/src/test/test_bitcoin`? You can run the new unit tests with `./build/src/test/test_bitcoin --run_test=util_trace_tests* --log_level=all`.
  <details><summary>Two of the added unit tests demonstrate that we are only processing the tracepoint arguments when attached by having a test-failure condition in the tracepoint argument preparation. The following bpftrace script can be used to demonstrate that the tests do indeed fail when attached to the tracepoints.</summary>

  `fail_tests.bt`:

  ```c
  #!/usr/bin/env bpftrace

  usdt:./build/src/test/test_bitcoin:test:check_if_attached {
    printf("the 'check_if_attached' test should have failed\n");
  }

  usdt:./build/src/test/test_bitcoin:test:expensive_section {
    printf("the 'expensive_section' test should have failed\n");
  }
  ```

  Run the unit tests with `./build/src/test/test_bitcoin` and start `bpftrace fail_tests.bt -p $(pidof test_bitcoin)` in a separate terminal. The unit tests should fail with:

  ```
  Running 594 test cases...
  test/util_trace_tests.cpp(31): error: in "util_trace_tests/test_tracepoint_check_if_attached": check false has failed
  test/util_trace_tests.cpp(51): error: in "util_trace_tests/test_tracepoint_manual_tracepoint_active_check": check false has failed

  *** 2 failures are detected in the test module "Bitcoin Core Test Suite"
  ```

  </details>

  These links might provide more contextual information for reviewers:
  - [How SystemTap Userspace Probes Work by eklitzke](https://eklitzke.org/how-sytemtap-userspace-probes-work) (actually an example on Bitcoin Core; mentions that with semaphores "the overhead for an untraced process is effectively zero.")
  - [libbpf comment on USDT semaphore handling](1596a09b5d/src/usdt.c (L83-L92)) (can recommend the whole comment for background on how the tracepoints and tracing tools work together)
  - https://sourceware.org/systemtap/wiki/UserSpaceProbeImplementation#Semaphore_Handling

ACKs for top commit:
  willcl-ark:
    utACK 0de3e96e33
  laanwj:
    re-ACK 0de3e96e33
  jb55:
    utACK 0de3e96e33
  vasild:
    ACK 0de3e96e33

Tree-SHA512: 0e5e0dc5e0353beaf5c446e4be03d447e64228b1be71ee9972fde1d6fac3fac71a9d73c6ce4fa68975f87db2b2bf6eee2009921a2a145e24d83a475d007a559b
2024-11-11 10:33:28 +00:00
..
bench bench: add coverage for wallet migration process 2024-10-21 08:29:22 -03:00
common Merge bitcoin/bitcoin#31156: test: Don't enforce BIP94 on regtest unless specified by arg 2024-10-30 17:00:14 -04:00
compat netbase: refactor CreateSock() to accept sa_family_t 2024-03-01 13:13:07 -05:00
config
consensus Move BlockMerkleBranch back to merkle.{h,cpp} 2024-09-26 09:48:31 +02:00
crc32c Update crc32c subtree to latest upstream master 2024-02-27 18:28:19 +00:00
crypto scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
index refactor: Split up NodeContext shutdown_signal and shutdown_request 2024-10-01 09:10:54 +02:00
init scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
interfaces interfaces: remove now unused 'use_upnp' arg from 'mapPort' 2024-10-24 18:23:30 +02:00
ipc Add submitSolution to BlockTemplate interface 2024-09-26 10:04:45 +02:00
kernel Merge bitcoin/bitcoin#30592: Remove mempoolfullrbf 2024-11-08 13:51:29 -05:00
leveldb Update leveldb-subtree subtree to latest upstream 2024-06-13 13:17:57 +01:00
logging scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
minisketch Update minisketch subtree to latest master 2024-06-12 14:38:39 +01:00
node Merge bitcoin/bitcoin#30592: Remove mempoolfullrbf 2024-11-08 13:51:29 -05:00
policy fees: Log non-fatal errors as [warning], instead of info-level 2024-10-23 18:43:32 +02:00
primitives tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
qt Merge bitcoin/bitcoin#29686: Update manpage descriptions 2024-11-08 13:34:59 -05:00
rpc Merge bitcoin/bitcoin#30592: Remove mempoolfullrbf 2024-11-08 13:51:29 -05:00
script Fix unsigned integer overflows in interpreter 2024-10-01 10:45:44 +02:00
secp256k1 Update secp256k1 subtree to v0.6.0 2024-11-04 14:59:46 -05:00
support cleanse: Use SecureZeroMemory for mingw-w64 (release) builds 2024-07-24 09:57:49 +01:00
test Merge bitcoin/bitcoin#26593: tracing: Only prepare tracepoint arguments when actually tracing 2024-11-11 10:33:28 +00:00
univalue build: Remove Autotools-based build system 2024-08-30 21:31:39 +01:00
util Merge bitcoin/bitcoin#26593: tracing: Only prepare tracepoint arguments when actually tracing 2024-11-11 10:33:28 +00:00
wallet Merge bitcoin/bitcoin#26593: tracing: Only prepare tracepoint arguments when actually tracing 2024-11-11 10:33:28 +00:00
zmq cmake: Add FindZeroMQ module 2024-10-25 18:09:36 +01:00
.clang-format refactor: Print verbose serialize compiler error messages 2023-12-15 15:20:54 +01:00
.clang-tidy tidy: add clang-tidy modernize-use-starts-ends-with check 2024-09-14 20:33:32 +03:00
addrdb.cpp scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
addrdb.h Use serialization parameters for CAddress serialization 2023-09-05 10:13:25 +02:00
addresstype.cpp policy: Add OP_1 <0x4e73> as a standard output type 2024-07-30 14:06:58 -04:00
addresstype.h policy: Add OP_1 <0x4e73> as a standard output type 2024-07-30 14:06:58 -04:00
addrman.cpp scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
addrman.h addrman: change Select to support multiple networks 2024-09-10 12:58:54 -03:00
addrman_impl.h Merge bitcoin/bitcoin#30568: addrman: change internal id counting to int64_t 2024-09-20 12:55:22 -04:00
arith_uint256.cpp refactor: Remove unused and fragile string interface from arith_uint256 2023-11-21 17:37:25 +01:00
arith_uint256.h doc + test: Correct uint256 hex string endianness 2024-08-03 21:59:54 +02:00
attributes.h Introduce platform-agnostic ALWAYS_INLINE macro 2023-05-04 20:57:51 +01:00
banman.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
banman.h net_processing: remove Misbehavior score and increments 2024-05-30 08:35:18 -04:00
base58.cpp util: Move util/string.h functions to util namespace 2024-05-16 10:16:08 -05:00
base58.h
bech32.cpp fuzz: replace hardcoded numbers for bech32 limits 2024-08-06 11:03:31 +02:00
bech32.h fuzz: replace hardcoded numbers for bech32 limits 2024-08-06 11:03:31 +02:00
bip324.cpp net: merge V2Transport constructors, move key gen 2023-09-10 16:11:52 -04:00
bip324.h net: merge V2Transport constructors, move key gen 2023-09-10 16:11:52 -04:00
bitcoin-chainstate.cpp kernel: Move background load thread to node context 2024-09-13 16:10:31 +02:00
bitcoin-cli-res.rc scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
bitcoin-cli.cpp Merge bitcoin/bitcoin#29686: Update manpage descriptions 2024-11-08 13:34:59 -05:00
bitcoin-tx-res.rc scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
bitcoin-tx.cpp doc: add bitcoin-tx man description 2024-10-30 10:18:40 +00:00
bitcoin-util-res.rc scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
bitcoin-util.cpp doc: add bitcoin-util man description 2024-10-30 10:18:41 +00:00
bitcoin-wallet-res.rc scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
bitcoin-wallet.cpp doc: add bitcoin-wallet man description 2024-10-30 10:18:39 +00:00
bitcoind-res.rc scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
bitcoind.cpp doc: add bitcoind man description 2024-10-30 10:18:36 +00:00
blockencodings.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
blockencodings.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
blockfilter.cpp util: Move util/string.h functions to util namespace 2024-05-16 10:16:08 -05:00
blockfilter.h Remove unused includes from blockfilter.h 2023-08-17 18:28:15 +02:00
chain.cpp
chain.h doc: update NeedsRedownload() comment 2024-09-17 09:54:18 +02:00
chainparams.cpp test: Don't enforce BIP94 on regtest unless specified by arg 2024-10-28 11:38:38 -04:00
chainparams.h test: Throw error when -signetchallenge is non-hex 2023-05-25 19:24:05 +02:00
chainparamsbase.cpp Deduplicate list of chain strings in RPC help texts 2024-08-13 14:00:33 -03:00
chainparamsbase.h Deduplicate list of chain strings in RPC help texts 2024-08-13 14:00:33 -03:00
chainparamsseeds.h seeds: Regenerate mainnet seeds 2024-08-27 07:00:27 +02:00
checkqueue.h refactor: Make CCheckQueue non-copyable and non-movable explicitly 2023-10-03 10:52:17 +01:00
clientversion.cpp scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
clientversion.h scripted-diff: Clarify "user agent" variable name 2024-10-28 12:35:49 +00:00
cluster_linearize.h clusterlin: remove Cluster type 2024-10-07 13:49:36 -04:00
CMakeLists.txt build: Disable secp256k1 musig module 2024-11-05 15:08:49 -05:00
coins.cpp tracing: only prepare tracepoint args if attached 2024-10-28 14:27:47 +01:00
coins.h refactor: Rely on returned value of GetCoin instead of parameter 2024-09-18 20:03:47 +02:00
compressor.cpp Clean up things that include script/standard.h 2023-08-14 17:38:27 -04:00
compressor.h refactor: Rename CTransaction::nVersion to version 2024-06-07 13:55:23 -04:00
core_io.h refactor: Replace ParseHashStr with FromHex 2024-07-24 17:40:18 +02:00
core_memusage.h
core_read.cpp refactor: Replace ParseHashStr with FromHex 2024-07-24 17:40:18 +02:00
core_write.cpp refactor: Rename CTransaction::nVersion to version 2024-06-07 13:55:23 -04:00
cuckoocache.h validation: Don't error if maxsigcachesize exceeds uint32::max 2024-07-04 22:35:29 +02:00
dbwrapper.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
dbwrapper.h dbwrapper: Use DataStream for batch operations 2023-09-12 12:07:39 +02:00
deploymentinfo.cpp
deploymentinfo.h
deploymentstatus.cpp
deploymentstatus.h
dummywallet.cpp wallet, test: Be able to always swap BDB endianness 2024-05-16 15:03:13 -04:00
external_signer.cpp refactor: Remove Span operator==, Use std::ranges::equal 2024-08-13 07:44:31 +02:00
external_signer.h refactor: Move system from util to common library 2023-05-20 12:08:13 +02:00
flatfile.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
flatfile.h refactor: Add FlatFileSeq member variables in BlockManager 2024-07-24 09:39:35 +02:00
hash.cpp crypto, hash: replace custom rotl32 with std::rotl 2024-01-05 17:12:38 +01:00
hash.h Squashed 'src/secp256k1/' changes from 2f2ccc46954..0cdc758a563 2024-11-04 14:59:46 -05:00
headerssync.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
headerssync.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
httprpc.cpp Merge bitcoin/bitcoin#30401: fix: increase consistency of rpcauth parsing 2024-09-09 12:29:17 -04:00
httprpc.h
httpserver.cpp scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
httpserver.h Merge bitcoin/bitcoin#30406: refactor: modernize-use-equals-default 2024-07-11 19:08:46 +01:00
i2p.cpp Merge bitcoin/bitcoin#29833: i2p: fix and improve logs 2024-06-26 15:28:26 -04:00
i2p.h i2p: log errors properly according to their severity 2024-06-12 16:19:50 -03:00
indirectmap.h
init.cpp Merge bitcoin/bitcoin#30592: Remove mempoolfullrbf 2024-11-08 13:51:29 -05:00
init.h multiprocess: Add -ipcbind option to bitcoin-node 2024-09-06 09:08:10 -04:00
key.cpp refactor: remove un-tested early returns 2024-08-04 08:52:22 +02:00
key.h refactor: move SignSchnorr to KeyPair 2024-08-04 08:51:36 +02:00
key_io.cpp key: clear out secret data in DecodeExtKey 2024-10-27 15:38:54 +01:00
key_io.h Clean up things that include script/standard.h 2023-08-14 17:38:27 -04:00
logging.cpp log: Enforce trailing newline, Remove redundant m_started_new_line 2024-10-01 11:31:39 +02:00
logging.h log: Enforce trailing newline, Remove redundant m_started_new_line 2024-10-01 11:31:39 +02:00
mapport.cpp mapport: remove dead code in DispatchMapPort 2024-10-25 15:02:07 -04:00
mapport.h interfaces: remove now unused 'use_upnp' arg from 'mapPort' 2024-10-24 18:23:30 +02:00
memusage.h memusage: Add DynamicUsage for std::string 2024-11-04 18:46:40 +01:00
merkleblock.cpp [clang-tidy] Enable the misc-no-recursion check 2024-04-07 14:04:45 +01:00
merkleblock.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
net.cpp Merge bitcoin/bitcoin#26593: tracing: Only prepare tracepoint arguments when actually tracing 2024-11-11 10:33:28 +00:00
net.h net: Use actual memory size in receive buffer accounting 2024-11-04 18:46:40 +01:00
net_permissions.cpp util: move fees.h and error.h to common/messages.h 2024-05-16 10:16:08 -05:00
net_permissions.h Accept "in" and "out" flags to -whitelist to allow whitelisting manual connections 2024-02-28 10:05:56 -03:00
net_processing.cpp Merge bitcoin/bitcoin#26593: tracing: Only prepare tracepoint arguments when actually tracing 2024-11-11 10:33:28 +00:00
net_processing.h net: add GetOrphanTransactions() to PeerManager 2024-10-01 21:55:18 -04:00
net_types.cpp rpc: avoid copying into UniValue 2024-05-20 16:48:19 +00:00
net_types.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
netaddress.cpp refactor: Remove Span operator==, Use std::ranges::equal 2024-08-13 07:44:31 +02:00
netaddress.h random: get rid of GetRand by inlining 2024-07-01 12:39:53 -04:00
netbase.cpp scripted-diff: drop config/ subdir for bitcoin-config.h, rename to bitcoin-build-config.h 2024-10-10 12:22:12 +02:00
netbase.h net: add All() in ReachableNets 2024-09-10 11:20:40 -03:00
netgroup.cpp Merge bitcoin/bitcoin#27581: net: Continuous ASMap health check 2023-12-06 11:22:42 -05:00
netgroup.h net: Add continuous ASMap health check logging 2023-12-02 22:03:08 +01:00
netmessagemaker.h refactor: NetMsg::Make() without nVersion 2023-11-20 14:02:27 +01:00
noui.cpp node: Use log levels in noui_ThreadSafeMessageBox 2024-03-21 16:41:16 +01:00
noui.h
outputtype.cpp fix incorrect multisig redeem script size limit for segwit 2024-05-03 14:20:44 -03:00
outputtype.h fix incorrect multisig redeem script size limit for segwit 2024-05-03 14:20:44 -03:00
pow.cpp Make G_FUZZING constexpr, require -DBUILD_FOR_FUZZING=ON to execute a fuzz target 2024-10-31 13:51:37 +01:00
pow.h Add FUZZING_BUILD_MODE_UNSAFE_FOR_PRODUCTION in PoW check 2024-09-02 15:43:33 +01:00
prevector.h prevector: avoid GCC bogus warnings in insert method 2024-09-11 17:41:26 +02:00
protocol.cpp protocol: make message types constexpr 2024-02-28 18:03:23 +01:00
protocol.h Merge bitcoin/bitcoin#29421: net: make the list of known message types a compile time constant 2024-05-21 13:59:33 -04:00
psbt.cpp util: add TransactionError includes and namespace declarations 2024-05-16 10:16:08 -05:00
psbt.h Merge bitcoin/bitcoin#30406: refactor: modernize-use-equals-default 2024-07-11 19:08:46 +01:00
pubkey.cpp refactor: Hand-replace some ParseHex -> ""_hex 2024-08-28 19:11:59 +02:00
pubkey.h refactor: Make XOnlyPubKey tolerate constexpr std::arrays 2024-08-28 19:09:51 +02:00
random.cpp Merge bitcoin/bitcoin#31124: util: Remove RandAddSeedPerfmon 2024-10-24 18:08:12 -04:00
random.h util: Remove RandAddSeedPerfmon 2024-10-21 23:24:17 +02:00
randomenv.cpp util: Remove RandAddSeedPerfmon 2024-10-21 23:24:17 +02:00
randomenv.h
rest.cpp scripted-diff: Rename PACKAGE_* variables to CLIENT_* 2024-10-28 12:36:19 +00:00
rest.h
scheduler.cpp scripted-diff: Rename SingleThreadedSchedulerClient to SerialTaskRunner 2024-02-15 14:43:14 +01:00
scheduler.h kernel: Remove dependency on CScheduler 2024-02-16 17:12:52 +01:00
serialize.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
signet.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
signet.h
span.h refactor: Remove Span operator==, Use std::ranges::equal 2024-08-13 07:44:31 +02:00
streams.cpp streams: add DataStream::GetMemoryUsage 2024-11-04 18:46:40 +01:00
streams.h streams: add DataStream::GetMemoryUsage 2024-11-04 18:46:40 +01:00
sync.cpp util: avoid using thread_local variable that has a destructor 2024-05-16 18:16:46 +02:00
sync.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
threadsafety.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
tinyformat.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00
torcontrol.cpp scripted-diff: LogPrint -> LogDebug 2024-08-29 13:49:57 +02:00
torcontrol.h doc, refactor: Changing -torcontrol help to specify that a default port is used 2023-08-17 23:58:47 -05:00
txdb.cpp refactor: Rely on returned value of GetCoin instead of parameter 2024-09-18 20:03:47 +02:00
txdb.h refactor: Rely on returned value of GetCoin instead of parameter 2024-09-18 20:03:47 +02:00
txmempool.cpp tracing: only prepare tracepoint args if attached 2024-10-28 14:27:47 +01:00
txmempool.h refactor: Rely on returned value of GetCoin instead of parameter 2024-09-18 20:03:47 +02:00
txorphanage.cpp net: add GetOrphanTransactions() to PeerManager 2024-10-01 21:55:18 -04:00
txorphanage.h [fuzz] txdownloadman and txdownload_impl 2024-10-24 21:23:56 -04:00
txrequest.cpp Merge bitcoin/bitcoin#30194: refactor: use recommended type hiding on multi_index types 2024-08-07 20:00:28 +01:00
txrequest.h
uint256.cpp scripted-diff: Rename SetHex to SetHexDeprecated 2024-07-24 09:15:34 +02:00
uint256.h test: remove test-only uint256S 2024-09-06 17:36:18 +02:00
undo.h Include version.h in fewer places 2023-11-16 11:36:22 +10:00
validation.cpp Merge bitcoin/bitcoin#26593: tracing: Only prepare tracepoint arguments when actually tracing 2024-11-11 10:33:28 +00:00
validation.h Remove unused g_best_block 2024-09-17 09:27:45 +02:00
validationinterface.cpp refactor: include the proper header rather than forward-declaring RemovalReasonToString 2024-10-08 15:25:47 +00:00
validationinterface.h [refactor] change ActiveTipChange to use CBlockIndex ref instead of ptr 2024-07-25 11:01:22 +01:00
versionbits.cpp
versionbits.h
walletinitinterface.h tidy: modernize-use-equals-default 2024-07-08 11:12:01 +02:00