Skip to content

Instantly share code, notes, and snippets.

@0xB10C
Created August 17, 2021 21:35
Show Gist options
  • Save 0xB10C/7f9010d44f1d97fbf1c83ec7f98155fd to your computer and use it in GitHub Desktop.
Save 0xB10C/7f9010d44f1d97fbf1c83ec7f98155fd to your computer and use it in GitHub Desktop.
bpftrace script to benchmark the `CChainState::ConnectBlock` function of Bitcoin Core. Outputs CSV.
#!/usr/bin/env bpftrace
/*
USAGE:
bpftrace perf-block-connect.bt <end-height>
This script requires a 'bitcoind' binary compiled with eBPF support and the
'validation:block_connected' tracepoint. By default, it's assumed that 'bitcoind' is
located in './src/bitcoind'. This can be modified in the script below.
*/
BEGIN
{
@has_started = 0;
@cum_conn_time = (uint64) 0;
printf("\n\nheight,conn_time(µs),cum_conn_time(µs),duration(ms)\n");
}
/*
Attaches to the 'validation:block_connected' tracepoint and prints
CSV formatted performance metrics for each block.
*/
usdt:./src/bitcoind:validation:block_connected
{
if (@has_started == 0) {
@has_started = 1;
@start = nsecs;
}
$height = arg1;
$transactions = arg2;
$inputs = arg3;
$sigops = arg4;
$conn_time = (uint64) arg5;
@cum_conn_time = @cum_conn_time + $conn_time;
$curr = nsecs;
printf("%d,%d,%d,%d\n", $height, $conn_time, @cum_conn_time, ($curr - @start) / 1000000);
if ($1 > 0 && $height >= $1) {
exit();
}
}
END
{
clear(@has_started);
clear(@cum_conn_time);
clear(@start);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment