From d71604c7a148eecb520fcef7fe50fdfc7da72eea Mon Sep 17 00:00:00 2001 From: Piotr Magiera Date: Wed, 22 May 2024 19:03:20 +0200 Subject: [PATCH] minor fix --- .../src/trace_reader/function_trace_builder.rs | 18 ++++++++++++++++-- .../src/trace_reader/functions.rs | 3 ++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/crates/cairo-profiler/src/trace_reader/function_trace_builder.rs b/crates/cairo-profiler/src/trace_reader/function_trace_builder.rs index c9cdee7..d1fc266 100644 --- a/crates/cairo-profiler/src/trace_reader/function_trace_builder.rs +++ b/crates/cairo-profiler/src/trace_reader/function_trace_builder.rs @@ -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 { @@ -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, } } diff --git a/crates/cairo-profiler/src/trace_reader/functions.rs b/crates/cairo-profiler/src/trace_reader/functions.rs index 8ade520..60d82e9 100644 --- a/crates/cairo-profiler/src/trace_reader/functions.rs +++ b/crates/cairo-profiler/src/trace_reader/functions.rs @@ -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 { @@ -36,6 +36,7 @@ impl FunctionName { } } +#[derive(Debug, PartialEq)] pub struct FunctionStackTrace { pub stack_trace: Vec, pub steps: Steps,