Skip to content
Merged
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
1 change: 1 addition & 0 deletions src/bin/cargo-flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,7 @@ fn find_unique_target(kind: &[&str], pkg: Option<&str>) -> anyhow::Result<Binary

fn main() -> anyhow::Result<()> {
let Opts::Flamegraph(mut opt) = Opts::from_args();
opt.graph.check()?;

let kind = if opt.bin.is_none()
&& opt.bench.is_none()
Expand Down
11 changes: 6 additions & 5 deletions src/bin/flamegraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,10 @@ fn main() -> anyhow::Result<()> {

if let Some(shell) = opt.completions {
return match opt.trailing_arguments.is_empty() {
true => Ok(Opt::clap().gen_completions_to(
"flamegraph",
shell,
&mut std::io::stdout().lock(),
)),
true => {
Opt::clap().gen_completions_to("flamegraph", shell, &mut std::io::stdout().lock());
Ok(())
}
false => {
return Err(anyhow!(
"command arguments cannot be used with --completions <completions>"
Expand All @@ -40,6 +39,8 @@ fn main() -> anyhow::Result<()> {
};
}

opt.graph.check()?;

let workload = match (opt.pid, opt.trailing_arguments.is_empty()) {
(Some(p), true) => Workload::Pid(p),
(None, false) => Workload::Command(opt.trailing_arguments.clone()),
Expand Down
21 changes: 17 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use inferno::collapse::dtrace::{Folder, Options as CollapseOptions};
#[cfg(unix)]
use signal_hook::consts::{SIGINT, SIGTERM};

use anyhow::Context;
use anyhow::{anyhow, Context};
use inferno::{
collapse::Collapse,
flamegraph::color::Palette,
Expand Down Expand Up @@ -316,7 +316,7 @@ pub struct Options {
frequency: Option<u32>,

/// Custom command for invoking perf/dtrace
#[structopt(short = "c", long = "cmd", conflicts_with = "freq")]
#[structopt(short = "c", long = "cmd")]
custom_cmd: Option<String>,

#[structopt(flatten)]
Expand All @@ -327,18 +327,31 @@ pub struct Options {
script_no_inline: bool,
}

impl Options {
pub fn check(&self) -> anyhow::Result<()> {
// Manually checking conflict because structopts `conflicts_with` leads
// to a panic in completion generation for zsh at the moment (see #158)
match self.frequency.is_some() && self.custom_cmd.is_some() {
true => Err(anyhow!(
"Cannot pass both a custom command and a frequency."
)),
false => Ok(()),
}
}
}

#[derive(Debug, structopt::StructOpt)]
pub struct FlamegraphOptions {
/// Colors are selected such that the color of a function does not change between runs
#[structopt(long = "deterministic", conflicts_with = "hash")]
#[structopt(long = "deterministic")]
pub deterministic: bool,

/// Plot the flame graph up-side-down
#[structopt(short = "i", long = "inverted")]
pub inverted: bool,

/// Generate stack-reversed flame graph
#[structopt(long = "reverse", conflicts_with = "no-sort")]
#[structopt(long = "reverse")]
pub reverse: bool,

/// Set embedded notes in SVG
Expand Down