add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor#1613
Open
avi-starkware wants to merge 2 commits into
Open
add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor#1613avi-starkware wants to merge 2 commits into
avi-starkware wants to merge 2 commits into
Conversation
|
✅ Code is now correctly formatted. |
98ed085 to
64c12b3
Compare
474462f to
13381fa
Compare
64c12b3 to
7e5fcd7
Compare
13381fa to
b5e8d6b
Compare
…cutor
Exposes the libfunc-profiling primitives that downstream consumers (e.g.
the blockifier in starkware-libs/sequencer) currently maintain locally.
Profile collection is callback-driven so the per-call key (tx hash, etc.)
stays out of cairo-native.
- 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).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Two correctness fixes to run_with_libfunc_profile, both inherited from the source branch (lambdaclass/sequencer:libfunc_profiling_support): 1. Race condition. The trace_id global symbol that drives sample routing is process-wide; concurrent calls non-atomically write to the same address, and the second caller's ProfilerGuard clobbers the first's saved old_trace_id. Add a process-wide PROFILE_LOCK (Mutex<()>) and hold it for the entire call. Lock poisoning is recovered — the protected state is the symbol itself, and inner_into() is safe to reuse. 2. Error paths. find_symbol_ptr().unwrap() panicked when the .so was compiled without libfunc-profiling instrumentation; the LIBFUNC_PROFILE slot inserted earlier was leaked. Reorder: look up the symbol first, convert None to Error::UnexpectedValue, then insert the slot. The trailing drain now only invokes on_profile when the inner run succeeded — a partial profile from an aborted run isn't meaningful. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
b5e8d6b to
94bc246
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.Replaces #1599 / #1609.
Changes
metadata::profiler::Profileis nowpub(was a private type alias).AotContractExecutor::run_with_libfunc_profile<H, F>(gated onwith-libfunc-profiling, in new filesrc/executor/libfunc_profile.rs) wrapsrun: allocates a unique trace ID, points the executor'scairo_native__profiler__profile_idsymbol at it, drains the resultingProfileafterrunreturns, and hands it to a caller-suppliedFnOnce(Profile). AProfilerGuardrestores the previous trace ID and drops theLIBFUNC_PROFILEslot 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::rundispatches the new variant viarun_with_libfunc_profilewith a no-op profile callback.ContractExecutor::run_with_profile<H, F>is the profile-capturing counterpart ofrun; for non-AotWithProgramvariants it falls through torun(callback never fires).Stack
ContractExecutor(supersedes add ContractExecutor dispatch enum (Aot + Emu) #1598 / add ContractExecutor dispatch enum (Aot + Emu) #1608)run_with_libfunc_profile+AotWithProgram(supersedes add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor #1599 / add run_with_libfunc_profile + AotWithProgram variant for ContractExecutor #1609)Test plan
cargo check(default features) cleancargo check --features with-libfunc-profilingcleancargo check --features sierra-emu,with-libfunc-profilingcleancargo check --workspace --all-featuresclean