0
0
Fork 0
mirror of https://github.com/bitcoin/bitcoin.git synced 2025-02-01 09:35:52 -05:00

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.
```
$ 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.
@ -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.
```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.
```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):
bitcoind_with_usdts = USDT(path=str(bitcoind_path))
def main(pid):
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
bitcoind_with_usdts.enable_probe(
@ -176,8 +177,8 @@ def main(bitcoind_path):
if __name__ == "__main__":
if len(sys.argv) < 2:
print("USAGE:", sys.argv[0], "path/to/bitcoind")
if len(sys.argv) != 2:
print("USAGE:", sys.argv[0], "<pid of bitcoind>")
exit()
path = sys.argv[1]
main(path)
pid = sys.argv[1]
main(pid)

View file

@ -70,8 +70,9 @@ def print_event(event):
))
def main(bitcoind_path):
bitcoind_with_usdts = USDT(path=str(bitcoind_path))
def main(pid):
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
@ -99,9 +100,9 @@ def main(bitcoind_path):
if __name__ == "__main__":
if len(sys.argv) < 2:
print("USAGE: ", sys.argv[0], "path/to/bitcoind")
if len(sys.argv) != 2:
print("USAGE: ", sys.argv[0], "<pid of bitcoind>")
exit(1)
path = sys.argv[1]
main(path)
pid = sys.argv[1]
main(pid)

View file

@ -114,8 +114,9 @@ int trace_replaced(struct pt_regs *ctx) {
"""
def main(bitcoind_path):
bitcoind_with_usdts = USDT(path=str(bitcoind_path))
def main(pid):
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
@ -365,8 +366,8 @@ class Dashboard:
if __name__ == "__main__":
if len(sys.argv) < 2:
print("USAGE: ", sys.argv[0], "path/to/bitcoind")
print("USAGE: ", sys.argv[0], "<pid of bitcoind>")
exit(1)
path = sys.argv[1]
main(path)
pid = sys.argv[1]
main(pid)

View file

@ -14,8 +14,9 @@
# outbound P2P messages. The eBPF program submits the P2P messages to
# this script via a BPF ring buffer.
import sys
import curses
import os
import sys
from curses import wrapper, panel
from bcc import BPF, USDT
@ -115,10 +116,10 @@ class Peer:
self.total_outbound_msgs += 1
def main(bitcoind_path):
def main(pid):
peers = dict()
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
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)
def running_as_root():
return os.getuid() == 0
if __name__ == "__main__":
if len(sys.argv) < 2:
print("USAGE:", sys.argv[0], "path/to/bitcoind")
if len(sys.argv) != 2:
print("USAGE:", sys.argv[0], "<pid of bitcoind>")
exit()
path = sys.argv[1]
main(path)
if not running_as_root():
print("You might not have the privileges required to hook into the tracepoints!")
pid = sys.argv[1]
main(pid)