Skip to content

add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor#1609

Open
avi-starkware wants to merge 1 commit into
avi/cairo_native/contract-executorfrom
avi/cairo_native/libfunc-profiling
Open

add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor#1609
avi-starkware wants to merge 1 commit into
avi/cairo_native/contract-executorfrom
avi/cairo_native/libfunc-profiling

Conversation

@avi-starkware
Copy link
Copy Markdown
Collaborator

Supersedes #1599 — reopened from starkware-libs/cairo_native so the stack can be expressed via base branches. Stacked on #1608. No code changes.

Summary

Exposes the libfunc-profiling primitives that downstream consumers (e.g. the blockifier in starkware-libs/sequencer) currently maintain locally. The profile-collection pattern is callback-driven so the per-call key (tx hash, etc.) stays out of cairo-native.

Important

Stacked on #1607 and #1608. Merge those first; this PR's diff will narrow once they land.

Changes

  • metadata::profiler::Profile is now pub (was a private type alias).
  • AotContractExecutor::run_with_libfunc_profile<H, F> (gated on with-libfunc-profiling, in new file src/executor/libfunc_profile.rs) wraps run: allocates a unique trace ID, points the executor's cairo_native__profiler__profile_id symbol at it, drains the resulting Profile after run returns, and hands it to a caller-supplied FnOnce(Profile). A ProfilerGuard restores the previous trace ID and drops the LIBFUNC_PROFILE slot on both the success and unwind paths.
  • ContractExecutor::AotWithProgram(AotWithProgram { executor, program }) is a new variant that bundles an AOT executor with the Sierra program it was built from. From<AotWithProgram> is provided.
  • ContractExecutor::run dispatches the new variant via run_with_libfunc_profile with a no-op profile callback.
  • ContractExecutor::run_with_profile<H, F> is the profile-capturing counterpart of run; for non-AotWithProgram variants it falls through to run (callback never fires).

Test plan

  • CI passes with default features
  • CI passes with --features with-libfunc-profiling
  • CI passes with --features sierra-emu,with-libfunc-profiling

Context

Companion sequencer PR that adopts these APIs and drops the locally-maintained profiling code: starkware-libs/sequencer#13880.

…cutor

Exposes the libfunc-profiling primitives that downstream consumers (e.g. the
blockifier in starkware-libs/sequencer) currently maintain locally. Makes the
profile-collection pattern callback-driven so the per-call key (tx hash, etc.)
stays out of cairo-native.

- `Profile` (HashMap<ConcreteLibfuncId, LibfuncProfileData>) is now public.
- `AotContractExecutor::run_with_libfunc_profile<H, F>` (gated on
  `with-libfunc-profiling`) wraps `run`: allocates a unique trace ID, points
  the executor's `cairo_native__profiler__profile_id` symbol at it, drains
  the resulting `Profile` after `run` returns, and hands it to a caller-
  supplied `FnOnce(Profile)`. A `ProfilerGuard` restores the previous trace
  ID and drops the LIBFUNC_PROFILE slot on both the success and unwind paths.
- `ContractExecutor::AotWithProgram(AotWithProgram { executor, program })`
  is a new variant that bundles an AOT executor with the Sierra program it
  was built from. `From<AotWithProgram>` is provided.
- `ContractExecutor::run` dispatches the new variant via
  `run_with_libfunc_profile` with a no-op profile callback.
- `ContractExecutor::run_with_profile<H, F>` is the profile-capturing
  counterpart of `run`; for non-`AotWithProgram` variants it falls through
  to `run` (callback never fires).
@github-actions
Copy link
Copy Markdown

❌ Code is not formatted! Please run cargo format and push the changes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant