Skip to content

Commit

Permalink
Add CasmLevelInfo struct
Browse files Browse the repository at this point in the history
  • Loading branch information
ddoktorski committed Jun 6, 2024
1 parent 869f4c3 commit 7559a0f
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 13 deletions.
7 changes: 0 additions & 7 deletions crates/cairo-profiler/src/sierra_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,6 @@ impl SierraProgramArtifact {
| SierraProgramArtifact::ContractClass(program_artifact) => program_artifact,
}
}

pub fn was_run_with_header(&self) -> bool {
match self {
SierraProgramArtifact::VersionedProgram(_) => true,
SierraProgramArtifact::ContractClass(_) => false,
}
}
}

impl CompiledArtifactsPathMap {
Expand Down
4 changes: 2 additions & 2 deletions crates/cairo-profiler/src/trace_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,10 @@ fn collect_samples<'a>(
.get_sierra_casm_artifacts_for_path(&absolute_source_sierra_path);

let function_level_profiling_info = collect_function_level_profiling_info(
&cairo_execution_info.vm_trace,
&cairo_execution_info.casm_level_info.vm_trace,
compiled_artifacts.sierra.get_program_artifact(),
&compiled_artifacts.casm_debug_info,
compiled_artifacts.sierra.was_run_with_header(),
cairo_execution_info.casm_level_info.run_with_call_header,
&FunctionLevelConfig::from(profiler_config),
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub fn collect_function_level_profiling_info(
trace: &[TraceEntry],
program_artifact: &ProgramArtifact,
casm_debug_info: &CairoProgramDebugInfo,
was_run_with_header: bool,
run_with_call_header: bool,
function_level_config: &FunctionLevelConfig,
) -> FunctionLevelProfilingInfo {
let program = &program_artifact.program;
Expand All @@ -63,7 +63,7 @@ pub fn collect_function_level_profiling_info(
// The first instruction after that is the first instruction in the original CASM program.
// This logic only applies when a header was added to the CASM program, otherwise the
// `real_minimal_pc` is the default one which is 1.
let real_minimal_pc = if was_run_with_header {
let real_minimal_pc = if run_with_call_header {
trace.last().unwrap().pc + 1
} else {
1
Expand All @@ -84,7 +84,7 @@ pub fn collect_function_level_profiling_info(

for step in trace {
// Skip the header. This only makes sense when a header was added to CASM program.
if step.pc < real_minimal_pc && was_run_with_header {
if step.pc < real_minimal_pc && run_with_call_header {
header_steps += 1;
continue;
}
Expand Down
8 changes: 7 additions & 1 deletion crates/trace-data/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,15 @@ pub struct CallTrace {
/// Struct needed for function level profiling.
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CairoExecutionInfo {
pub vm_trace: Vec<TraceEntry>,
/// Path to a file with serialized `ContractClass` or `VersionedProgram`.
pub source_sierra_path: Utf8PathBuf,
pub casm_level_info: CasmLevelInfo,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CasmLevelInfo {
pub run_with_call_header: bool,
pub vm_trace: Vec<TraceEntry>,
}

/// Enum representing node of a trace of a call.
Expand Down

0 comments on commit 7559a0f

Please sign in to comment.