Skip to content

Commit

Permalink
Added --output_file option
Browse files Browse the repository at this point in the history
- added #cfg[test] block for main.rs
  • Loading branch information
gmarler committed Mar 20, 2024
1 parent 10a542b commit 393ecd0
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ chrono = "*"
inferno = "*"
primal = "0.3"

[dev-dependencies]
assert_cmd = { version = "2" }
expect-test = { version = "1.4" }

[build-dependencies]
bindgen = "*"
Expand Down
23 changes: 18 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ struct Cli {
value_parser = sample_freq_in_range,
)]
sample_freq: u16,
/// Output file for Flame Graph in SVG format
#[arg(short, long, default_value = "flame.svg")]
output_file: PathBuf,
}

fn main() -> Result<(), Box<dyn Error>> {
Expand Down Expand Up @@ -128,15 +131,25 @@ fn main() -> Result<(), Box<dyn Error>> {

let mut options: flamegraph::Options<'_> = flamegraph::Options::default();
let data = folded.as_bytes();
let flame_path = "flame.svg";
let flame_path = args.output_file;
let f = File::create(flame_path).unwrap();
flamegraph::from_reader(&mut options, data, f).unwrap();

Ok(())
}

#[test]
fn verify_cli() {
use clap::CommandFactory;
Cli::command().debug_assert()
#[cfg(test)]
mod tests {
use super::*;
use assert_cmd::Command;
use expect_test::expect;

#[test]
fn verify_cli() {
use clap::CommandFactory;
Cli::command().debug_assert()
}

#[test]
fn duration_arg() {}
}

0 comments on commit 393ecd0

Please sign in to comment.