diff --git a/crates/stats/src/lib.rs b/crates/stats/src/lib.rs index 22677e7..7561939 100644 --- a/crates/stats/src/lib.rs +++ b/crates/stats/src/lib.rs @@ -1,5 +1,6 @@ mod code; mod network; +mod perf; mod procs; mod storage; @@ -19,6 +20,7 @@ impl util::Cmd for Stats { network::Network::cmd()?, procs::Procs::cmd()?, storage::Storage::cmd()?, + perf::Perf::cmd()?, ]) .subcommand_required(true); @@ -31,6 +33,7 @@ impl util::Cmd for Stats { Some(("network", args)) => network::Network::exec(args), Some(("procs", args)) => procs::Procs::exec(args), Some(("storage", args)) => storage::Storage::exec(args), + Some(("perf", args)) => perf::Perf::exec(args), _ => Stats::run(), } } diff --git a/crates/stats/src/perf.rs b/crates/stats/src/perf.rs new file mode 100644 index 0000000..607706d --- /dev/null +++ b/crates/stats/src/perf.rs @@ -0,0 +1,29 @@ +pub struct Perf; + +impl Perf { + fn run() -> eyre::Result<()> { + if let Err(_) = util::shell::run_with_input_and_output(&["ytop", "--version"], "".into()) { + return Err(eyre::anyhow!( + "could not find ytop, please install or add to PATH" + )); + } + + util::shell::run(&["ytop"], None)?; + + Ok(()) + } +} + +impl util::Cmd for Perf { + fn cmd() -> eyre::Result { + let cmd = clap::Command::new("perf").subcommands(&[]); + + Ok(cmd) + } + + fn exec(args: &clap::ArgMatches) -> eyre::Result<()> { + match args.subcommand() { + _ => Perf::run(), + } + } +}