From 0320a41bdd9c8c02571ec150269eefeeecb8032a Mon Sep 17 00:00:00 2001 From: "Elvis S." Date: Thu, 25 Dec 2025 16:28:52 +0400 Subject: [PATCH 1/2] feat(reexecution): add optional profiling support to benchmarking script --- Taskfile.yml | 1 + scripts/benchmark_cchain_range.sh | 27 ++++++++++++++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Taskfile.yml b/Taskfile.yml index 6bf9314b8aad..c4697b3475c5 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -229,6 +229,7 @@ tasks: # - METRICS_SERVER_PORT (monitoring config) # - METRICS_SERVER_ENABLED (runtime monitoring decision) # - METRICS_COLLECTOR_ENABLED (runtime monitoring decision) + # - PROFILE (runtime profiling decision, see benchmark_cchain_range.sh for details) # - PROMETHEUS_URL, PROMETHEUS_USERNAME, PROMETHEUS_PASSWORD (monitoring config) # - GH_REPO, GH_WORKFLOW, GH_RUN_ID, etc. (GitHub context) diff --git a/scripts/benchmark_cchain_range.sh b/scripts/benchmark_cchain_range.sh index 379aca3172c6..09600773e914 100755 --- a/scripts/benchmark_cchain_range.sh +++ b/scripts/benchmark_cchain_range.sh @@ -14,13 +14,29 @@ set -euo pipefail # METRICS_SERVER_ENABLED (optional): If set, enables the metrics server. # METRICS_SERVER_PORT (optional): If set, determines the port the metrics server will listen to. # METRICS_COLLECTOR_ENABLED (optional): If set, enables the metrics collector. +# PROFILE (optional, bool): If set, build with debug symbols and enable pprof. -: "${BLOCK_DIR:?BLOCK_DIR must be set}" -: "${CURRENT_STATE_DIR:?CURRENT_STATE_DIR must be set}" -: "${START_BLOCK:?START_BLOCK must be set}" -: "${END_BLOCK:?END_BLOCK must be set}" +BINARY="$(mktemp -d)/vm_reexecute" -go run github.com/ava-labs/avalanchego/tests/reexecute/c \ +if [[ "${PROFILE:-}" == "true" ]]; then + # Build with debug symbols for profiling (pprof, perf, samply, Instruments). + # -gcflags="all=-N -l": + # -N: Disable optimizations so variable values are preserved in debugger + # -l: Disable inlining so all function calls appear in stack traces + # -ldflags="-compressdwarf=false": + # Keep DWARF debug info uncompressed so profilers can read symbols + # CGO_CFLAGS="-fno-omit-frame-pointer -g": + # -fno-omit-frame-pointer: Preserve frame pointers for stack unwinding (required for profilers to walk the call stack) + # -g: Include debug symbols in C/FFI code (Rust FFI visibility) + CGO_CFLAGS="-fno-omit-frame-pointer -g" \ + CGO_LDFLAGS="-g" \ + go build -o "${BINARY}" -gcflags="all=-N -l" -ldflags="-compressdwarf=false" \ + github.com/ava-labs/avalanchego/tests/reexecute/c +else + go build -o "${BINARY}" github.com/ava-labs/avalanchego/tests/reexecute/c +fi + +"${BINARY}" \ --block-dir="${BLOCK_DIR}" \ --current-state-dir="${CURRENT_STATE_DIR}" \ ${RUNNER_TYPE:+--runner="${RUNNER_TYPE}"} \ @@ -32,3 +48,4 @@ go run github.com/ava-labs/avalanchego/tests/reexecute/c \ ${METRICS_SERVER_ENABLED:+--metrics-server-enabled="${METRICS_SERVER_ENABLED}"} \ ${METRICS_SERVER_PORT:+--metrics-server-port="${METRICS_SERVER_PORT}"} \ ${METRICS_COLLECTOR_ENABLED:+--metrics-collector-enabled="${METRICS_COLLECTOR_ENABLED}"} +# ${PROFILE:+--pprof} From 00229f34856cb2a2d979307ade33299f1625916a Mon Sep 17 00:00:00 2001 From: "Elvis S." Date: Thu, 25 Dec 2025 18:38:40 +0400 Subject: [PATCH 2/2] refactor(benchmarking): simplify profiling logic in c-chain benchmarking script --- scripts/benchmark_cchain_range.sh | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/scripts/benchmark_cchain_range.sh b/scripts/benchmark_cchain_range.sh index 09600773e914..4ab4d30e4679 100755 --- a/scripts/benchmark_cchain_range.sh +++ b/scripts/benchmark_cchain_range.sh @@ -16,8 +16,7 @@ set -euo pipefail # METRICS_COLLECTOR_ENABLED (optional): If set, enables the metrics collector. # PROFILE (optional, bool): If set, build with debug symbols and enable pprof. -BINARY="$(mktemp -d)/vm_reexecute" - +RUN_ARGS=() if [[ "${PROFILE:-}" == "true" ]]; then # Build with debug symbols for profiling (pprof, perf, samply, Instruments). # -gcflags="all=-N -l": @@ -25,18 +24,12 @@ if [[ "${PROFILE:-}" == "true" ]]; then # -l: Disable inlining so all function calls appear in stack traces # -ldflags="-compressdwarf=false": # Keep DWARF debug info uncompressed so profilers can read symbols - # CGO_CFLAGS="-fno-omit-frame-pointer -g": - # -fno-omit-frame-pointer: Preserve frame pointers for stack unwinding (required for profilers to walk the call stack) - # -g: Include debug symbols in C/FFI code (Rust FFI visibility) - CGO_CFLAGS="-fno-omit-frame-pointer -g" \ - CGO_LDFLAGS="-g" \ - go build -o "${BINARY}" -gcflags="all=-N -l" -ldflags="-compressdwarf=false" \ - github.com/ava-labs/avalanchego/tests/reexecute/c -else - go build -o "${BINARY}" github.com/ava-labs/avalanchego/tests/reexecute/c + RUN_ARGS+=('-gcflags=all=-N -l' '-ldflags=-compressdwarf=false') fi -"${BINARY}" \ +# -fno-omit-frame-pointer: Preserve frame pointers for stack unwinding (required for profilers to walk the call stack) +# -g: Include debug symbols in C/FFI code (Rust FFI visibility) +CGO_CFLAGS="-fno-omit-frame-pointer -g" go run "${RUN_ARGS[@]}" github.com/ava-labs/avalanchego/tests/reexecute/c \ --block-dir="${BLOCK_DIR}" \ --current-state-dir="${CURRENT_STATE_DIR}" \ ${RUNNER_TYPE:+--runner="${RUNNER_TYPE}"} \