Skip to content

Conversation

@Elvis339
Copy link
Contributor

@Elvis339 Elvis339 commented Dec 25, 2025

Why this should be merged

This patch is part of: ava-labs/firewood#1582

Adds profiling support to the C-Chain re-execution benchmark, enabling visibility into Rust FFI performance when using Firewood. When PROFILE=true, the binary is built with debug symbols and frame pointers, allowing profilers (pprof, perf, samply, Instruments) to resolve function names across the Go → CGO → Rust stack instead of showing opaque memory addresses.

How this works

When PROFILE=true is set:

  1. Go build flags disable optimizations (-N) and inlining (-l) to preserve stack traces
  2. DWARF debug info is kept uncompressed for profiler compatibility
  3. CGO flags enable frame pointers and debug symbols for Rust FFI visibility
  4. Binary is built to /tmp/vm_reexecute for post-run analysis

How this was tested

1. Baseline - build without profiling flags

# Build Go binary without profiling flags
go build -o /tmp/vm_reexecute \
  github.com/ava-labs/avalanchego/tests/reexecute/c

# Check for Rust debug info
dwarfdump --debug-info /tmp/vm_reexecute 2>/dev/null | grep -E "firewood::|storage::" | head -5

Output shows no Rust debug info

(no output)

2. Build WITH profiling flags:

# Sync Firewood at the required commit (includes profiling Nix package)
go run github.com/ava-labs/avalanchego/tests/fixture/polyrepo@6239973c9b \
  sync firewood@1dc00532d977c45d22cd5939cd5a692218c5ec94

# Build FFI with profiling (debug symbols + frame pointers)
cd firewood/ffi && rm -rf result && nix build .#profile
cd ../..

CGO_CFLAGS="-fno-omit-frame-pointer -g" \
go build -o /tmp/vm_reexecute \
  -gcflags="all=-N -l" \
  -ldflags="-compressdwarf=false" \
  github.com/ava-labs/avalanchego/tests/reexecute/c

# Check for Rust debug info
dwarfdump --debug-info /tmp/vm_reexecute 2>/dev/null | grep -E "firewood::|storage::" | head -10

Output shows resolved Rust type/function names:

DW_AT_type  (0x00af9e0b "core::result::Result<core::option::Option<firewood_storage::hashtype::trie_hash::TrieHash>, firewood::v2::api::Error>")
DW_AT_name  ("impl FnOnce() -> Result<firewood::db::Proposal<'db>, api::Error>")
DW_AT_type  (0x00af6bb2 "core::option::Option<firewood_storage::hashtype::trie_hash::TrieHash>")
DW_AT_type  (0x00b08ede "firewood::db::Proposal")
DW_AT_type  (0x00afa078 "core::result::Result<firewood_ffi::proposal::CreateProposalResult, firewood::v2::api::Error>")

This enables profilers to display human-readable Rust call stacks instead of raw memory addresses.

If empty output run:

cd firewood/ffi && nix-collect-garbage && \ 
    rm -rf /tmp/vm_reexecute && \
    nix build .#profile && \
    CGO_CFLAGS="-fno-omit-frame-pointer -g" \
    go build -o /tmp/vm_reexecute \
        -gcflags="all=-N -l" \
       -ldflags="-compressdwarf=false" \
       github.com/ava-labs/avalanchego/tests/reexecute/c

Need to be documented in RELEASES.md?

No

@Elvis339 Elvis339 self-assigned this Dec 25, 2025
@Elvis339 Elvis339 added the testing This primarily focuses on testing label Dec 25, 2025
${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}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Requires merging #4790

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

testing This primarily focuses on testing

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants