Skip to content

Commit

Permalink
feat(profiling-replayer): add the ability to print stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
morrisonlevi committed Feb 5, 2025
1 parent a2bd795 commit ac39e61
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions profiling-replayer/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ fn main() -> anyhow::Result<()> {
.help("collect memory statistics")
.required(false),
)
.arg(
Arg::new("print-samples")
.long("print-samples")
.help("verbose printing of the stacks")
.required(false)
.num_args(0),
)
.arg(
Arg::new("output")
.short('o')
Expand All @@ -131,6 +138,7 @@ fn main() -> anyhow::Result<()> {

let input = matches.get_one::<String>("input").unwrap();
let output = matches.get_one::<String>("output");
let print_stacks = matches.get_one("print-samples");
let collect_memory_stats = matches.get_flag("mem");
let mut sysinfo = if collect_memory_stats {
Some(Sysinfo::new())
Expand Down Expand Up @@ -174,6 +182,18 @@ fn main() -> anyhow::Result<()> {
println!("Max stack depth is {max}.");
}

if let Some(true) = print_stacks {
for (_tstamp, sample) in replayer.samples.iter() {
sample.locations.iter().rev().for_each(|location| {
let fname = location.function.name;
let lineno = location.line;
let filename = location.function.filename;
println!("{fname}:{lineno} ({filename})");
});
println!();
}
}

// When benchmarking, don't count the copying of the stacks, do that before.
let samples = std::mem::take(&mut replayer.samples);

Expand Down

0 comments on commit ac39e61

Please sign in to comment.