tracing: use bitcoind pid in bcc tracing examples

BCC needs the PID of a bitcoind process to attach to the tracepoints
(instead of the binary path used before) when the tracepoints have a
semaphore.

For reference, we already use the PID in our tracepoint interface
tests. See 220a5a2841.
This commit is contained in:
0xb10c 2022-12-20 12:51:13 +01:00
parent 411c6cfc6c
commit 0de3e96e33
No known key found for this signature in database
GPG key ID: E2FFD5B1D88CA97D
5 changed files with 38 additions and 29 deletions

View file

@ -82,7 +82,7 @@ about the connection. Peers can be selected individually to view recent P2P
messages. messages.
``` ```
$ python3 contrib/tracing/p2p_monitor.py ./build/src/bitcoind $ python3 contrib/tracing/p2p_monitor.py $(pidof bitcoind)
``` ```
Lists selectable peers and traffic and connection information. Lists selectable peers and traffic and connection information.
@ -150,7 +150,7 @@ lost. BCC prints: `Possibly lost 2 samples` on lost messages.
``` ```
$ python3 contrib/tracing/log_raw_p2p_msgs.py ./build/src/bitcoind $ python3 contrib/tracing/log_raw_p2p_msgs.py $(pidof bitcoind)
``` ```
``` ```
@ -241,7 +241,7 @@ A BCC Python script to log the UTXO cache flushes. Based on the
`utxocache:flush` tracepoint. `utxocache:flush` tracepoint.
```bash ```bash
$ python3 contrib/tracing/log_utxocache_flush.py ./build/src/bitcoind $ python3 contrib/tracing/log_utxocache_flush.py $(pidof bitcoind)
``` ```
``` ```
@ -300,7 +300,7 @@ comprising a timestamp along with all event data available via the event's
tracepoint. tracepoint.
```console ```console
$ python3 contrib/tracing/mempool_monitor.py ./build/src/bitcoind $ python3 contrib/tracing/mempool_monitor.py $(pidof bitcoind)
``` ```
``` ```

View file

@ -132,8 +132,9 @@ def print_message(event, inbound):
) )
def main(bitcoind_path): def main(pid):
bitcoind_with_usdts = USDT(path=str(bitcoind_path)) print(f"Hooking into bitcoind with pid {pid}")
bitcoind_with_usdts = USDT(pid=int(pid))
# attaching the trace functions defined in the BPF program to the tracepoints # attaching the trace functions defined in the BPF program to the tracepoints
bitcoind_with_usdts.enable_probe( bitcoind_with_usdts.enable_probe(
@ -176,8 +177,8 @@ def main(bitcoind_path):
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 2: if len(sys.argv) != 2:
print("USAGE:", sys.argv[0], "path/to/bitcoind") print("USAGE:", sys.argv[0], "<pid of bitcoind>")
exit() exit()
path = sys.argv[1] pid = sys.argv[1]
main(path) main(pid)

View file

@ -70,8 +70,9 @@ def print_event(event):
)) ))
def main(bitcoind_path): def main(pid):
bitcoind_with_usdts = USDT(path=str(bitcoind_path)) print(f"Hooking into bitcoind with pid {pid}")
bitcoind_with_usdts = USDT(pid=int(pid))
# attaching the trace functions defined in the BPF program # attaching the trace functions defined in the BPF program
# to the tracepoints # to the tracepoints
@ -99,9 +100,9 @@ def main(bitcoind_path):
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 2: if len(sys.argv) != 2:
print("USAGE: ", sys.argv[0], "path/to/bitcoind") print("USAGE: ", sys.argv[0], "<pid of bitcoind>")
exit(1) exit(1)
path = sys.argv[1] pid = sys.argv[1]
main(path) main(pid)

View file

@ -114,8 +114,9 @@ int trace_replaced(struct pt_regs *ctx) {
""" """
def main(bitcoind_path): def main(pid):
bitcoind_with_usdts = USDT(path=str(bitcoind_path)) print(f"Hooking into bitcoind with pid {pid}")
bitcoind_with_usdts = USDT(pid=int(pid))
# attaching the trace functions defined in the BPF program # attaching the trace functions defined in the BPF program
# to the tracepoints # to the tracepoints
@ -365,8 +366,8 @@ class Dashboard:
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 2: if len(sys.argv) < 2:
print("USAGE: ", sys.argv[0], "path/to/bitcoind") print("USAGE: ", sys.argv[0], "<pid of bitcoind>")
exit(1) exit(1)
path = sys.argv[1] pid = sys.argv[1]
main(path) main(pid)

View file

@ -14,8 +14,9 @@
# outbound P2P messages. The eBPF program submits the P2P messages to # outbound P2P messages. The eBPF program submits the P2P messages to
# this script via a BPF ring buffer. # this script via a BPF ring buffer.
import sys
import curses import curses
import os
import sys
from curses import wrapper, panel from curses import wrapper, panel
from bcc import BPF, USDT from bcc import BPF, USDT
@ -115,10 +116,10 @@ class Peer:
self.total_outbound_msgs += 1 self.total_outbound_msgs += 1
def main(bitcoind_path): def main(pid):
peers = dict() peers = dict()
print(f"Hooking into bitcoind with pid {pid}")
bitcoind_with_usdts = USDT(path=str(bitcoind_path)) bitcoind_with_usdts = USDT(pid=int(pid))
# attaching the trace functions defined in the BPF program to the tracepoints # attaching the trace functions defined in the BPF program to the tracepoints
bitcoind_with_usdts.enable_probe( bitcoind_with_usdts.enable_probe(
@ -245,9 +246,14 @@ def render(screen, peers, cur_list_pos, scroll, ROWS_AVALIABLE_FOR_LIST, info_pa
(msg.msg_type, msg.size), curses.A_NORMAL) (msg.msg_type, msg.size), curses.A_NORMAL)
def running_as_root():
return os.getuid() == 0
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) < 2: if len(sys.argv) != 2:
print("USAGE:", sys.argv[0], "path/to/bitcoind") print("USAGE:", sys.argv[0], "<pid of bitcoind>")
exit() exit()
path = sys.argv[1] if not running_as_root():
main(path) print("You might not have the privileges required to hook into the tracepoints!")
pid = sys.argv[1]
main(pid)