diff --git a/contrib/tracing/README.md b/contrib/tracing/README.md --- a/contrib/tracing/README.md +++ b/contrib/tracing/README.md @@ -176,17 +176,12 @@ function takes longer than the threshold, information about the block, is printed. For more details, see the header comment in the script. -By default, `bpftrace` limits strings to 64 bytes due to the limited stack size -in the kernel VM. Block hashes as zero-terminated hex strings are 65 bytes which -exceed the string limit. The string size limit can be set to 65 bytes with the -environment variable `BPFTRACE_STRLEN`. - The following command can be used to benchmark, for example, `ConnectBlock()` between height 20000 and 38000 on Testnet while logging all blocks that take longer than 25ms to connect. ``` -$ BPFTRACE_STRLEN=65 bpftrace contrib/tracing/connectblock_benchmark.bt 20000 38000 25 +$ bpftrace contrib/tracing/connectblock_benchmark.bt 20000 38000 25 ``` In a different terminal, starting Bitcoin ABC in Testnet mode and with diff --git a/contrib/tracing/connectblock_benchmark.bt b/contrib/tracing/connectblock_benchmark.bt --- a/contrib/tracing/connectblock_benchmark.bt +++ b/contrib/tracing/connectblock_benchmark.bt @@ -4,11 +4,8 @@ USAGE: - BPFTRACE_STRLEN=65 bpftrace contrib/tracing/connectblock_benchmark.bt + bpftrace contrib/tracing/connectblock_benchmark.bt - - The environment variable BPFTRACE_STRLEN needs to be set to 65 chars as - strings are limited to 64 chars by default. Hex strings with Bitcoin block - hashes are 64 hex chars + 1 null-termination char. - sets the height at which the benchmark should start. Setting the start height to 0 starts the benchmark immediately, even before the first block is connected. @@ -23,7 +20,7 @@ EXAMPLES: - BPFTRACE_STRLEN=65 bpftrace contrib/tracing/connectblock_benchmark.bt 300000 680000 1000 + bpftrace contrib/tracing/connectblock_benchmark.bt 300000 680000 1000 When run together 'bitcoind -reindex', this benchmarks the time it takes to connect the blocks between height 300.000 and 680.000 (inclusive) and prints @@ -31,7 +28,7 @@ histogram with block connection times when the benchmark is finished. - BPFTRACE_STRLEN=65 bpftrace contrib/tracing/connectblock_benchmark.bt 0 0 500 + bpftrace contrib/tracing/connectblock_benchmark.bt 0 0 500 When running together 'bitcoind', all newly connected blocks that take longer than 500ms to connect are logged. A histogram with block @@ -75,7 +72,7 @@ $height = arg1; $transactions = arg2; $inputs = arg3; - $sigops = arg4; + $sigchecks = arg4; $duration = (uint64) arg5; @height = $height; @@ -83,7 +80,7 @@ @blocks = @blocks + 1; @transactions = @transactions + $transactions; @inputs = @inputs + $inputs; - @sigops = @sigops + $sigops; + @sigchecks = @sigchecks + $sigchecks; @durations = hist($duration / 1000); @@ -107,29 +104,38 @@ */ usdt:./src/bitcoind:validation:block_connected / (uint64) arg5 / 1000> $3 / { - $hash_str = str(arg0); + $hash = arg0; $height = (int32) arg1; $transactions = (uint64) arg2; $inputs = (int32) arg3; - $sigops = (int64) arg4; + $sigchecks = (int64) arg4; $duration = (int64) arg5; - printf("Block %d (%s) %4d tx %5d ins %5d sigops took %4d ms\n", $height, $hash_str, $transactions, $inputs, $sigops, (uint64) $duration / 1000); + + printf("Block %d (", $height); + /* Prints each byte of the block hash as hex in big-endian (the block-explorer format) */ + $p = $hash + 31; + unroll(32) { + $b = *(uint8*)$p; + printf("%02x", $b); + $p -= 1; + } + printf(") %4d tx %5d ins %5d sigchk took %4d ms\n", $transactions, $inputs, $sigchecks, (uint64) $duration / 1000); } /* - Prints stats about the blocks, transactions, inputs, and sigops processed in - the last second (if any). + Prints stats about the blocks, transactions, inputs, and sigchecks processed + in the last second (if any). */ interval:s:1 { if (@blocks > 0) { - printf("BENCH %4d blk/s %6d tx/s %7d inputs/s %8d sigops/s (height %d)\n", @blocks, @transactions, @inputs, @sigops, @height); + printf("BENCH %4d blk/s %6d tx/s %7d inputs/s %8d sigchk/s (height %d)\n", @blocks, @transactions, @inputs, @sigchecks, @height); zero(@blocks); zero(@transactions); zero(@inputs); - zero(@sigops); + zero(@sigchecks); } } @@ -142,7 +148,7 @@ clear(@blocks); clear(@transactions); clear(@inputs); - clear(@sigops); + clear(@sigchecks); clear(@height); clear(@start); clear(@end); diff --git a/doc/tracing.md b/doc/tracing.md --- a/doc/tracing.md +++ b/doc/tracing.md @@ -101,19 +101,12 @@ to benchmark block connections together with `-reindex`. Arguments passed: -1. Block Header Hash as `pointer to C-style String` (64 characters) +1. Block Header Hash as `pointer to unsigned chars` (i.e. 32 bytes in little-endian) 2. Block Height as `int32` 3. Transactions in the Block as `uint64` 4. Inputs spend in the Block as `int32` 5. SigChecks in the Block (excluding coinbase) as `uint64` 6. Time it took to connect the Block in microseconds (µs) as `uint64` -7. Block Header Hash as `pointer to unsigned chars` (i.e. 32 bytes in little-endian) - -Note: The 7th argument can't be accessed by bpftrace and is purposefully chosen -to be the block header hash as bytes. See [bpftrace argument limit] for more -details. - -[bpftrace argument limit]: #bpftrace-argument-limit ## Adding tracepoints to Bitcoin ABC diff --git a/src/config/bitcoin-config.h.cmake.in b/src/config/bitcoin-config.h.cmake.in --- a/src/config/bitcoin-config.h.cmake.in +++ b/src/config/bitcoin-config.h.cmake.in @@ -101,6 +101,6 @@ #cmakedefine HAVE___INT128 1 -#cmakedefine ENABLE_TRACING 0 +#cmakedefine ENABLE_TRACING 1 #endif // BITCOIN_BITCOIN_CONFIG_H diff --git a/src/util/trace.h b/src/util/trace.h --- a/src/util/trace.h +++ b/src/util/trace.h @@ -5,6 +5,8 @@ #ifndef BITCOIN_UTIL_TRACE_H #define BITCOIN_UTIL_TRACE_H +#include + #ifdef ENABLE_TRACING #include diff --git a/src/validation.cpp b/src/validation.cpp --- a/src/validation.cpp +++ b/src/validation.cpp @@ -2174,10 +2174,10 @@ MILLI * (nTime5 - nTime4), nTimeIndex * MICRO, nTimeIndex * MILLI / nBlocksTotal); - TRACE7(validation, block_connected, block.GetHash().ToString().c_str(), - pindex->nHeight, block.vtx.size(), nInputs, nSigChecksRet, + TRACE6(validation, block_connected, block.GetHash().data(), pindex->nHeight, + block.vtx.size(), nInputs, nSigChecksRet, // in microseconds (µs) - GetTimeMicros() - nTimeStart, block.GetHash().data()); + GetTimeMicros() - nTimeStart); return true; }