-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save sierra test code separately for profiler (#2065)
## Introduced changes - Test artifacts file usually had 2 structs in it: `CompiledTestCrateRaw` for `src/` and `CompiledTestCrateRaw` for `tests/`, each with a separate sierra program. This made profiler unable to determine which sierra it should use for function level profiling (only path to the artifact file was passed to profiler). Now we save the relevant sierra program to another file and pass a path to the trace. This way profiler knows what sierra it should use. It also makes profiler less coupled with snforge (it doesn't have to know forge test artifact format) ## Checklist - [x] Linked relevant issue - [x] Updated relevant documentation - [x] Added relevant tests - [x] Performed self-review of the code - [x] Added changes to `CHANGELOG.md`
- Loading branch information
1 parent
da1b422
commit 709ad03
Showing
19 changed files
with
233 additions
and
95 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains 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
This file contains 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
This file contains 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
56 changes: 56 additions & 0 deletions
56
crates/forge-runner/src/build_trace_data/test_sierra_program_path.rs
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
use crate::compiled_runnable::CrateLocation; | ||
use anyhow::Context; | ||
use anyhow::Result; | ||
use cairo_lang_sierra::program::VersionedProgram; | ||
use camino::{Utf8Path, Utf8PathBuf}; | ||
use fs4::FileExt; | ||
use std::fs; | ||
use std::fs::File; | ||
use std::io::BufWriter; | ||
|
||
pub const VERSIONED_PROGRAMS_DIR: &str = ".snfoundry_versioned_programs"; | ||
|
||
/// A path to a file with deserialized [`VersionedProgram`] that comes | ||
/// from compiled test crate. Needed to provide path to source sierra in | ||
/// [`trace_data::CairoExecutionInfo`]. | ||
#[derive(Clone)] | ||
pub struct VersionedProgramPath(Utf8PathBuf); | ||
|
||
impl VersionedProgramPath { | ||
pub fn save_versioned_program( | ||
versioned_program: &VersionedProgram, | ||
crate_location: CrateLocation, | ||
tests_programs_dir: &Utf8Path, | ||
package_name: &str, | ||
) -> Result<Self> { | ||
// unique filename since pair (package_name, crate_location) is always unique | ||
let test_sierra_program_path = | ||
tests_programs_dir.join(format!("{package_name}_{crate_location:?}.sierra.json",)); | ||
|
||
fs::create_dir_all(test_sierra_program_path.parent().unwrap()) | ||
.context("Failed to create directory for tests sierra programs")?; | ||
let output_file = File::options() | ||
.create(true) | ||
.write(true) | ||
.truncate(true) | ||
.open(&test_sierra_program_path)?; | ||
|
||
output_file.lock_exclusive().with_context(|| { | ||
format!("Couldn't lock the output file = {test_sierra_program_path}") | ||
})?; | ||
let file = BufWriter::new(&output_file); | ||
serde_json::to_writer(file, &versioned_program) | ||
.context("Failed to serialize VersionedProgram")?; | ||
output_file.unlock().with_context(|| { | ||
format!("Couldn't lock the output file = {test_sierra_program_path}") | ||
})?; | ||
|
||
Ok(Self(test_sierra_program_path)) | ||
} | ||
} | ||
|
||
impl From<VersionedProgramPath> for Utf8PathBuf { | ||
fn from(value: VersionedProgramPath) -> Self { | ||
value.0 | ||
} | ||
} |
This file contains 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
This file contains 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
Oops, something went wrong.