Skip to content

Commit

Permalink
minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
piotmag769 committed May 22, 2024
1 parent 2fb5db0 commit d71604c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
18 changes: 16 additions & 2 deletions crates/cairo-profiler/src/trace_reader/function_trace_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub struct ProfilingInfo {
pub header_steps: Steps,
}

#[derive(Clone, Copy, Eq, PartialEq)]
#[derive(Clone, Copy, Eq, PartialEq, Debug)]
pub struct Steps(pub usize);

impl AddAssign for Steps {
Expand Down Expand Up @@ -174,8 +174,22 @@ pub fn collect_profiling_info(
})
.collect_vec();

// Some real function traces may be converted to the same displayable traces e.g.
// [func, func[expr36], func[expr36]] and [func, func[expr36]] both are converted to [func].
// We aggregate them, adding their steps. It doesn't make a difference to pprof, but it may
// help us when adding integration tests.
let deduplicated_functions_stack_traces = displayable_functions_stack_traces
.into_iter()
.fold(HashMap::new(), |mut acc, stack_trace| {
*acc.entry(stack_trace.stack_trace).or_insert(Steps(0)) += stack_trace.steps;
acc
})
.into_iter()
.map(|(stack_trace, steps)| FunctionStackTrace { stack_trace, steps })
.collect();

ProfilingInfo {
functions_stack_traces: displayable_functions_stack_traces,
functions_stack_traces: deduplicated_functions_stack_traces,
header_steps,
}
}
Expand Down
3 changes: 2 additions & 1 deletion crates/cairo-profiler/src/trace_reader/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ lazy_static! {
.expect("Failed to create regex normalising mononorphised generic functions names");
}

#[derive(Clone, Hash, Eq, PartialEq)]
#[derive(Clone, Hash, Eq, PartialEq, Debug)]
pub struct FunctionName(pub String);

impl From<&EntryPointId> for FunctionName {
Expand All @@ -36,6 +36,7 @@ impl FunctionName {
}
}

#[derive(Debug, PartialEq)]
pub struct FunctionStackTrace {
pub stack_trace: Vec<FunctionName>,
pub steps: Steps,
Expand Down

0 comments on commit d71604c

Please sign in to comment.