From a088685500adce68bdda1555001a93af38b6415d Mon Sep 17 00:00:00 2001 From: ede1998 Date: Sat, 16 Oct 2021 13:03:50 +0200 Subject: [PATCH 1/3] remove conflicts_with for non-existant options --- src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index b9a1fb2..0c509c7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -330,7 +330,7 @@ pub struct Options { #[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 @@ -338,7 +338,7 @@ pub struct FlamegraphOptions { 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 From a504cbf0b9248cb68f5353d873c0036f1645ca17 Mon Sep 17 00:00:00 2001 From: ede1998 Date: Sat, 16 Oct 2021 13:16:45 +0200 Subject: [PATCH 2/3] remove conflicts_with annotation and check manually to prevent zsh completion generation panic --- src/bin/cargo-flamegraph.rs | 1 + src/bin/flamegraph.rs | 2 ++ src/lib.rs | 17 +++++++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/bin/cargo-flamegraph.rs b/src/bin/cargo-flamegraph.rs index d6ac10a..f3d8e9e 100644 --- a/src/bin/cargo-flamegraph.rs +++ b/src/bin/cargo-flamegraph.rs @@ -314,6 +314,7 @@ fn find_unique_target(kind: &[&str], pkg: Option<&str>) -> anyhow::Result anyhow::Result<()> { let Opts::Flamegraph(mut opt) = Opts::from_args(); + opt.graph.check()?; let kind = if opt.bin.is_none() && opt.bench.is_none() diff --git a/src/bin/flamegraph.rs b/src/bin/flamegraph.rs index 2cd4fe5..f630ec7 100644 --- a/src/bin/flamegraph.rs +++ b/src/bin/flamegraph.rs @@ -40,6 +40,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()), diff --git a/src/lib.rs b/src/lib.rs index 0c509c7..bedda65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, @@ -316,7 +316,7 @@ pub struct Options { frequency: Option, /// Custom command for invoking perf/dtrace - #[structopt(short = "c", long = "cmd", conflicts_with = "freq")] + #[structopt(short = "c", long = "cmd")] custom_cmd: Option, #[structopt(flatten)] @@ -327,6 +327,19 @@ 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 From b46329acd6793a90a73c9a1e804cdc8450b17df3 Mon Sep 17 00:00:00 2001 From: ede1998 Date: Sat, 16 Oct 2021 13:18:18 +0200 Subject: [PATCH 3/3] fix clippy warning --- src/bin/flamegraph.rs | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/bin/flamegraph.rs b/src/bin/flamegraph.rs index f630ec7..77731e4 100644 --- a/src/bin/flamegraph.rs +++ b/src/bin/flamegraph.rs @@ -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 "