Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Cli parser from StructOpt to Clap #199

Merged
merged 1 commit into from
Feb 9, 2023
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
2 changes: 1 addition & 1 deletion crox/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
12 changes: 6 additions & 6 deletions crox/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<S: Serializer>(d: &Duration, s: S) -> Result<S::Ok, S::Error> {
let v = (d.as_secs() * 1_000_000) + (d.subsec_nanos() as u64 / 1_000);
Expand Down Expand Up @@ -43,18 +43,18 @@ struct Event {
args: Option<FxHashMap<String, String>>,
}

#[derive(StructOpt, Debug)]
#[derive(Parser, Debug)]
struct Opt {
#[structopt(required_unless = "dir")]
#[clap(required_unless = "dir")]
file_prefix: Vec<PathBuf>,
/// all event trace files in dir will be merged to one chrome_profiler.json file
#[structopt(long = "dir")]
#[clap(long = "dir")]
dir: Option<PathBuf>,
/// 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<u128>,
}

Expand Down
2 changes: 1 addition & 1 deletion flamegraph/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
4 changes: 2 additions & 2 deletions flamegraph/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion mmedit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ edition = "2018"
[dependencies]
measureme = { path = "../measureme" }
decodeme = { path = "../decodeme" }
structopt = "0.3"
clap = { version = "3.2", features = ["derive"] }
8 changes: 4 additions & 4 deletions mmedit/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}

Expand Down
2 changes: 1 addition & 1 deletion mmview/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
6 changes: 3 additions & 3 deletions mmview/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<u32>,
}

Expand Down
2 changes: 1 addition & 1 deletion stack_collapse/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
4 changes: 2 additions & 2 deletions stack_collapse/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
2 changes: 1 addition & 1 deletion summarize/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
24 changes: 12 additions & 12 deletions summarize/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -19,47 +19,47 @@ mod signed_duration;

use query_data::Results;

#[derive(StructOpt, Debug)]
#[derive(Parser, Debug)]
struct AggregateOpt {
files: Vec<PathBuf>,
}

#[derive(StructOpt, Debug)]
#[derive(Parser, Debug)]
struct DiffOpt {
base: PathBuf,
change: PathBuf,

#[structopt(short = "e", long = "exclude")]
#[clap(short = 'e', long = "exclude")]
exclude: Vec<String>,

#[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 <file_prefix> 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")]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor change in the short flag as Clap do not support shorts that have multiple characters

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),
}

Expand Down