Skip to content

Commit

Permalink
feat: produce both by size and by count flamegraphs
Browse files Browse the repository at this point in the history
  • Loading branch information
0xdeafbeef committed Oct 16, 2024
1 parent ccc35aa commit 6d6f0bd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
26 changes: 23 additions & 3 deletions jeprofl/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,29 @@ impl EventProcessor {
csv_writer.finish()?;

if let Some(path) = flame_graph {
let file = std::fs::File::create(&path)?;
let file = BufWriter::new(file);
self.write_flame_graph(file, order_by)?;
let path_without_extension = match path.file_stem() {
Some(stem) => path.with_file_name(stem),
None => path,
};

let result = path_without_extension.to_string_lossy();
let args = [
(
PathBuf::from(format!("{}-by-count.svg", result)),
OrderBy::Count,
),
(
PathBuf::from(format!("{}-by-traffic.svg", result)),
OrderBy::Traffic,
),
];

for (path, order_by) in args {
let file = std::fs::File::create(&path)?;
let file = BufWriter::new(file);
self.write_flame_graph(file, order_by)?;
log::info!("Flamegraph written to {:?}", path);
}
}

Ok(())
Expand Down
1 change: 1 addition & 0 deletions jeprofl/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct Opt {
#[clap(long("csv"))]
csv_path: Option<PathBuf>,

/// Writes a flamegraph to the path_by_size.svg and path_by_count.svg
#[clap(long("flame"))]
flame_graph: Option<PathBuf>,
}
Expand Down

0 comments on commit 6d6f0bd

Please # to comment.