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..4ab4d30e4679 100755 --- a/scripts/benchmark_cchain_range.sh +++ b/scripts/benchmark_cchain_range.sh @@ -14,13 +14,22 @@ 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}" +RUN_ARGS=() +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 + RUN_ARGS+=('-gcflags=all=-N -l' '-ldflags=-compressdwarf=false') +fi -go run github.com/ava-labs/avalanchego/tests/reexecute/c \ +# -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}"} \ @@ -32,3 +41,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}