From e4053c69df4a1bafdefbf89aee0c5804c333c0fb Mon Sep 17 00:00:00 2001 From: Andreas Jonson Date: Wed, 13 Jul 2022 16:05:12 +0200 Subject: [PATCH] Change Cli parser from StructOpt to Clap --- crox/Cargo.toml | 2 +- crox/src/main.rs | 12 ++++++------ flamegraph/Cargo.toml | 2 +- flamegraph/src/main.rs | 4 ++-- mmedit/Cargo.toml | 2 +- mmedit/src/main.rs | 8 ++++---- mmview/Cargo.toml | 2 +- mmview/src/main.rs | 6 +++--- stack_collapse/Cargo.toml | 2 +- stack_collapse/src/main.rs | 4 ++-- summarize/Cargo.toml | 2 +- summarize/src/main.rs | 24 ++++++++++++------------ 12 files changed, 35 insertions(+), 35 deletions(-) diff --git a/crox/Cargo.toml b/crox/Cargo.toml index 3e1c961..094452e 100644 --- a/crox/Cargo.toml +++ b/crox/Cargo.toml @@ -10,4 +10,4 @@ analyzeme = { path = "../analyzeme" } rustc-hash = "1.0.1" serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" -structopt = "0.3" +clap = { version = "3.2", features = ["derive"] } diff --git a/crox/src/main.rs b/crox/src/main.rs index 8aa6eaa..83d179e 100644 --- a/crox/src/main.rs +++ b/crox/src/main.rs @@ -7,11 +7,11 @@ use std::time::{Duration, SystemTime, UNIX_EPOCH}; use analyzeme::{ProfilingData, Timestamp}; use measureme::file_header::FILE_EXTENSION; +use clap::Parser; use serde::ser::SerializeSeq; use serde::{Serialize, Serializer}; use serde_json::json; use std::cmp; -use structopt::StructOpt; fn as_micros(d: &Duration, s: S) -> Result { let v = (d.as_secs() * 1_000_000) + (d.subsec_nanos() as u64 / 1_000); @@ -43,18 +43,18 @@ struct Event { args: Option>, } -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] struct Opt { - #[structopt(required_unless = "dir")] + #[clap(required_unless = "dir")] file_prefix: Vec, /// all event trace files in dir will be merged to one chrome_profiler.json file - #[structopt(long = "dir")] + #[clap(long = "dir")] dir: Option, /// collapse threads without overlapping events - #[structopt(long = "collapse-threads")] + #[clap(long = "collapse-threads")] collapse_threads: bool, /// filter out events with shorter duration (in microseconds) - #[structopt(long = "minimum-duration")] + #[clap(long = "minimum-duration")] minimum_duration: Option, } diff --git a/flamegraph/Cargo.toml b/flamegraph/Cargo.toml index b58ffaa..fedcd55 100644 --- a/flamegraph/Cargo.toml +++ b/flamegraph/Cargo.toml @@ -8,5 +8,5 @@ license = "MIT OR Apache-2.0" [dependencies] measureme = { path = "../measureme" } analyzeme = { path = "../analyzeme" } -structopt = "0.3" +clap = { version = "3.2", features = ["derive"] } inferno = { version="0.9.1", default-features = false } diff --git a/flamegraph/src/main.rs b/flamegraph/src/main.rs index 9f3f23b..847a6ef 100644 --- a/flamegraph/src/main.rs +++ b/flamegraph/src/main.rs @@ -4,10 +4,10 @@ use std::io::BufWriter; use std::path::PathBuf; use analyzeme::{collapse_stacks, ProfilingData}; +use clap::Parser; use inferno::flamegraph::{from_lines, Options as FlamegraphOptions}; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] struct Opt { file_prefix: PathBuf, } diff --git a/mmedit/Cargo.toml b/mmedit/Cargo.toml index 77f1a56..e9af934 100644 --- a/mmedit/Cargo.toml +++ b/mmedit/Cargo.toml @@ -6,4 +6,4 @@ edition = "2018" [dependencies] measureme = { path = "../measureme" } decodeme = { path = "../decodeme" } -structopt = "0.3" +clap = { version = "3.2", features = ["derive"] } diff --git a/mmedit/src/main.rs b/mmedit/src/main.rs index 26dedca..2c1758d 100644 --- a/mmedit/src/main.rs +++ b/mmedit/src/main.rs @@ -2,17 +2,17 @@ use std::{convert::TryInto, error::Error, path::PathBuf}; use decodeme::{read_file_header, PageTag, FILE_HEADER_SIZE, FILE_MAGIC_TOP_LEVEL}; -use structopt::StructOpt; +use clap::Parser; -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] struct TruncateOpt { file: PathBuf, } -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] enum Opt { /// Truncate to a single page per tag - #[structopt(name = "truncate")] + #[clap(name = "truncate")] Truncate(TruncateOpt), } diff --git a/mmview/Cargo.toml b/mmview/Cargo.toml index c110e4d..f5f03f9 100644 --- a/mmview/Cargo.toml +++ b/mmview/Cargo.toml @@ -8,4 +8,4 @@ license = "MIT OR Apache-2.0" [dependencies] analyzeme = { path = "../analyzeme" } measureme = { path = "../measureme" } -structopt = "0.3" +clap = { version = "3.2", features = ["derive"] } diff --git a/mmview/src/main.rs b/mmview/src/main.rs index ec04535..1e2cfe4 100644 --- a/mmview/src/main.rs +++ b/mmview/src/main.rs @@ -1,15 +1,15 @@ use analyzeme::{Event, EventPayload, ProfilingData, Timestamp}; +use clap::Parser; use std::error::Error; use std::path::PathBuf; use std::time::{Duration, SystemTime}; -use structopt::StructOpt; -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] struct Opt { file_prefix: PathBuf, /// Filter to events which occured on the specified thread id - #[structopt(short = "t", long = "thread-id")] + #[clap(short = 't', long = "thread-id")] thread_id: Option, } diff --git a/stack_collapse/Cargo.toml b/stack_collapse/Cargo.toml index 72f7e02..1553fe8 100644 --- a/stack_collapse/Cargo.toml +++ b/stack_collapse/Cargo.toml @@ -8,4 +8,4 @@ license = "MIT OR Apache-2.0" [dependencies] measureme = { path = "../measureme" } analyzeme = { path = "../analyzeme" } -structopt = "0.3" +clap = { version = "3.2", features = ["derive"] } diff --git a/stack_collapse/src/main.rs b/stack_collapse/src/main.rs index 22384bb..86bcd1a 100644 --- a/stack_collapse/src/main.rs +++ b/stack_collapse/src/main.rs @@ -4,9 +4,9 @@ use std::io::{BufWriter, Write}; use std::path::PathBuf; use analyzeme::{collapse_stacks, ProfilingData}; -use structopt::StructOpt; +use clap::Parser; -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] struct Opt { file_prefix: PathBuf, } diff --git a/summarize/Cargo.toml b/summarize/Cargo.toml index ad42a67..6d5594d 100644 --- a/summarize/Cargo.toml +++ b/summarize/Cargo.toml @@ -12,4 +12,4 @@ prettytable-rs = "0.8" rustc-hash = "1.0.1" serde = { version = "1.0", features = [ "derive" ] } serde_json = "1.0" -structopt = "0.3" +clap = { version = "3.2", features = ["derive"] } diff --git a/summarize/src/main.rs b/summarize/src/main.rs index 435acdb..6427e7d 100644 --- a/summarize/src/main.rs +++ b/summarize/src/main.rs @@ -7,9 +7,9 @@ use std::fs::File; use std::io::{BufReader, BufWriter}; use std::{path::PathBuf, time::Duration}; +use clap::Parser; use prettytable::{Cell, Row, Table}; use serde::Serialize; -use structopt::StructOpt; mod aggregate; mod analysis; @@ -19,47 +19,47 @@ mod signed_duration; use query_data::Results; -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] struct AggregateOpt { files: Vec, } -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] struct DiffOpt { base: PathBuf, change: PathBuf, - #[structopt(short = "e", long = "exclude")] + #[clap(short = 'e', long = "exclude")] exclude: Vec, - #[structopt(long = "json")] + #[clap(long = "json")] json: bool, } -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] struct SummarizeOpt { file_prefix: PathBuf, /// Writes the analysis to a json file next to instead of stdout - #[structopt(long = "json")] + #[clap(long = "json")] json: bool, /// Filter the output to items whose self-time is greater than this value - #[structopt(short = "pa", long = "percent-above", default_value = "0.0")] + #[clap(short = 'p', long = "percent-above", default_value = "0.0")] percent_above: f64, } -#[derive(StructOpt, Debug)] +#[derive(Parser, Debug)] enum Opt { /// Processes a set of trace files with identical events and analyze variance - #[structopt(name = "aggregate")] + #[clap(name = "aggregate")] Aggregate(AggregateOpt), - #[structopt(name = "diff")] + #[clap(name = "diff")] Diff(DiffOpt), /// Processes trace files and produces a summary - #[structopt(name = "summarize")] + #[clap(name = "summarize")] Summarize(SummarizeOpt), }