Customize reports with a Frame Post Processor
masterThe frame_post_processor allows you to modify raw statistic data before the report is generated. This is useful for grouping symbols, renaming threads (e.g., using Regex to simplify thread names), or demangling specific symbols. You pass a closure that accepts and modifies &mut pprof::Frames to the guard.frames_post_processor() method.
fn frames_post_processor() -> impl Fn(&mut pprof::Frames) {
let thread_rename = [
(Regex::new(r"^grpc-server-\d*$").unwrap(), "grpc-server"),
// ... other mappings
];
move |frames| {
for (regex, name) in thread_rename.iter() {
if regex.is_match(&frames.thread_name) {
frames.thread_name = name.to_string();
}
}
}
}
if let Ok(report) = guard.frames_post_processor(frames_post_processor()).report().build() {
let file = File::create("flamegraph.svg").unwrap();
report.flamegraph(file).unwrap();
}