mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-21 14:34:49 +01:00
tracing: log_p2p_connections.bt example
A bpftrace script that logs information from the net:*_connection tracepoints. I've tested this script with bpftrace version 0.14.1 and v0.20.2.
This commit is contained in:
parent
caa5486574
commit
b19b526758
2 changed files with 72 additions and 0 deletions
|
@ -335,4 +335,25 @@ $ python3 contrib/tracing/mempool_monitor.py $(pidof bitcoind)
|
|||
│ 13:10:32Z added c78e87be86c828137a6e7e00a177c03b52202ce4c39029b99904c2a094b9da87 with feerate 11.00 sat/vB (1562 sat, 142 vbytes) │
|
||||
│ │
|
||||
└──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘
|
||||
|
||||
### log_p2p_connections.bt
|
||||
|
||||
A `bpftrace` script to log information about opened, closed, misbehaving, and
|
||||
evicted P2P connections. Uses the `net:*_connection` tracepoints.
|
||||
|
||||
```bash
|
||||
$ bpftrace contrib/tracing/log_p2p_connections.bt
|
||||
```
|
||||
|
||||
This should produce an output similar to the following.
|
||||
|
||||
```bash
|
||||
Attaching 6 probes...
|
||||
Logging opened, closed, misbehaving, and evicted P2P connections
|
||||
OUTBOUND conn to 127.0.0.1:15287: id=0, type=block-relay-only, network=0, total_out=1
|
||||
INBOUND conn from 127.0.0.1:45324: id=1, type=inbound, network=0, total_in=1
|
||||
MISBEHAVING conn id=1, score_before=0, score_increase=20, message='getdata message size = 50001', threshold_exceeded=false
|
||||
CLOSED conn to 127.0.0.1:15287: id=0, type=block-relay-only, network=0, established=1231006505
|
||||
EVICTED conn to 127.0.0.1:45324: id=1, type=inbound, network=0, established=1612312312
|
||||
...
|
||||
```
|
||||
|
|
51
contrib/tracing/log_p2p_connections.bt
Executable file
51
contrib/tracing/log_p2p_connections.bt
Executable file
|
@ -0,0 +1,51 @@
|
|||
#!/usr/bin/env bpftrace
|
||||
|
||||
BEGIN
|
||||
{
|
||||
printf("Logging opened, closed, misbehaving, and evicted P2P connections\n")
|
||||
}
|
||||
|
||||
usdt:./build/src/bitcoind:net:inbound_connection
|
||||
{
|
||||
$id = (int64) arg0;
|
||||
$addr = str(arg1);
|
||||
$conn_type = str(arg2);
|
||||
$network = (int32) arg3;
|
||||
$existing = (uint64) arg4;
|
||||
printf("INBOUND conn from %s: id=%ld, type=%s, network=%d, total=%d\n", $addr, $id, $conn_type, $network, $existing);
|
||||
}
|
||||
|
||||
usdt:./build/src/bitcoind:net:outbound_connection
|
||||
{
|
||||
$id = (int64) arg0;
|
||||
$addr = str(arg1);
|
||||
$conn_type = str(arg2);
|
||||
$network = (int32) arg3;
|
||||
$existing = (uint64) arg4;
|
||||
printf("OUTBOUND conn to %s: id=%ld, type=%s, network=%d, total=%d\n", $addr, $id, $conn_type, $network, $existing);
|
||||
}
|
||||
|
||||
usdt:./build/src/bitcoind:net:closed_connection
|
||||
{
|
||||
$id = (int64) arg0;
|
||||
$addr = str(arg1);
|
||||
$conn_type = str(arg2);
|
||||
$network = (int32) arg3;
|
||||
printf("CLOSED conn to %s: id=%ld, type=%s, network=%d, established=%ld\n", $addr, $id, $conn_type, $network, arg4);
|
||||
}
|
||||
|
||||
usdt:./build/src/bitcoind:net:evicted_inbound_connection
|
||||
{
|
||||
$id = (int64) arg0;
|
||||
$addr = str(arg1);
|
||||
$conn_type = str(arg2);
|
||||
$network = (int32) arg3;
|
||||
printf("EVICTED conn to %s: id=%ld, type=%s, network=%d, established=%ld\n", $addr, $id, $conn_type, $network, arg4);
|
||||
}
|
||||
|
||||
usdt:./build/src/bitcoind:net:misbehaving_connection
|
||||
{
|
||||
$id = (int64) arg0;
|
||||
$message = str(arg1);
|
||||
printf("MISBEHAVING conn id=%ld, message='%s'\n", $id, $message);
|
||||
}
|
Loading…
Add table
Reference in a new issue