aboutsummaryrefslogtreecommitdiff
path: root/src/net.cpp
diff options
context:
space:
mode:
author0xb10c <b10c@b10c.me>2023-11-23 16:51:36 +0100
committer0xb10c <b10c@b10c.me>2024-10-28 14:27:47 +0100
commit411c6cfc6c2e488e407f057b646730e63806ed8a (patch)
treeb02360d4fdcd5362a808d41dc8012699c47dcc12 /src/net.cpp
parentd524c1ec06643208c189089089e84f6e1cd0abad (diff)
tracing: only prepare tracepoint args if attached
Before this commit, we would always prepare tracepoint arguments regardless of the tracepoint being used or not. While we already made sure not to include expensive arguments in our tracepoints, this commit introduces gating to make sure the arguments are only prepared if the tracepoints are actually used. This is a win-win improvement to our tracing framework. For users not interested in tracing, the overhead is reduced to a cheap 'greater than 0' compare. As the semaphore-gating technique used here is available in bpftrace, bcc, and libbpf, users interested in tracing don't have to change their tracing scripts while profiting from potential future tracepoints passing slightly more expensive arguments. An example are mempool tracepoints that pass serialized transactions. We've avoided the serialization in the past as it was too expensive. Under the hood, the semaphore-gating works by placing a 2-byte semaphore in the '.probes' ELF section. The address of the semaphore is contained in the ELF note providing the tracepoint information (`readelf -n ./src/bitcoind | grep NT_STAPSDT`). Tracing toolkits like bpftrace, bcc, and libbpf increase the semaphore at the address upon attaching to the tracepoint. We only prepare the arguments and reach the tracepoint if the semaphore is greater than zero. The semaphore is decreased when detaching from the tracepoint. This also extends the "Adding a new tracepoint" documentation to include information about the semaphores and updated step-by-step instructions on how to add a new tracepoint.
Diffstat (limited to 'src/net.cpp')
-rw-r--r--src/net.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/net.cpp b/src/net.cpp
index 15cf1fe80c..0a643c48c5 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -53,6 +53,8 @@
#include <optional>
#include <unordered_map>
+TRACEPOINT_SEMAPHORE(net, outbound_message);
+
/** Maximum number of block-relay-only anchor connections */
static constexpr size_t MAX_BLOCK_RELAY_ONLY_ANCHORS = 2;
static_assert (MAX_BLOCK_RELAY_ONLY_ANCHORS <= static_cast<size_t>(MAX_BLOCK_RELAY_ONLY_CONNECTIONS), "MAX_BLOCK_RELAY_ONLY_ANCHORS must not exceed MAX_BLOCK_RELAY_ONLY_CONNECTIONS.");