Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregate displayable function traces #67

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -171,8 +171,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. Pprof does it under the hood anyway, 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
Loading