2018-12-06 19:17:36 +00:00
|
|
|
use crate::command_prelude::*;
|
2018-04-14 08:47:58 +00:00
|
|
|
use cargo::ops::{self, TestOptions};
|
2018-03-06 21:01:03 +00:00
|
|
|
|
2022-09-20 18:28:34 +00:00
|
|
|
pub fn cli() -> Command {
|
2018-03-06 21:01:03 +00:00
|
|
|
subcommand("bench")
|
|
|
|
.about("Execute all benchmarks of a local package")
|
2021-12-06 03:01:47 +00:00
|
|
|
.arg_quiet()
|
2018-03-06 21:01:03 +00:00
|
|
|
.arg(
|
2022-01-06 02:00:18 +00:00
|
|
|
Arg::new("BENCHNAME")
|
2022-09-20 18:19:46 +00:00
|
|
|
.action(ArgAction::Set)
|
2018-03-14 15:17:44 +00:00
|
|
|
.help("If specified, only run benches containing this string in their names"),
|
2018-03-06 21:01:03 +00:00
|
|
|
)
|
|
|
|
.arg(
|
2022-01-06 02:00:18 +00:00
|
|
|
Arg::new("args")
|
2018-03-14 15:17:44 +00:00
|
|
|
.help("Arguments for the bench binary")
|
2022-09-28 18:32:27 +00:00
|
|
|
.num_args(0..)
|
|
|
|
.trailing_var_arg(true),
|
2018-03-06 21:01:03 +00:00
|
|
|
)
|
2018-03-07 08:22:46 +00:00
|
|
|
.arg_targets_all(
|
2018-03-06 21:01:03 +00:00
|
|
|
"Benchmark only this package's library",
|
|
|
|
"Benchmark only the specified binary",
|
|
|
|
"Benchmark all binaries",
|
|
|
|
"Benchmark only the specified example",
|
|
|
|
"Benchmark all examples",
|
|
|
|
"Benchmark only the specified test target",
|
|
|
|
"Benchmark all tests",
|
|
|
|
"Benchmark only the specified bench target",
|
|
|
|
"Benchmark all benches",
|
2018-09-17 02:41:57 +00:00
|
|
|
"Benchmark all targets",
|
2018-03-06 21:01:03 +00:00
|
|
|
)
|
2022-06-08 20:16:51 +00:00
|
|
|
.arg(flag("no-run", "Compile, but don't run benchmarks"))
|
2018-03-16 14:35:13 +00:00
|
|
|
.arg_package_spec(
|
2018-03-06 21:01:03 +00:00
|
|
|
"Package to run benchmarks for",
|
|
|
|
"Benchmark all packages in the workspace",
|
|
|
|
"Exclude packages from the benchmark",
|
|
|
|
)
|
|
|
|
.arg_jobs()
|
2021-07-13 22:22:09 +00:00
|
|
|
.arg_profile("Build artifacts with the specified profile")
|
2018-03-06 21:01:03 +00:00
|
|
|
.arg_features()
|
2018-03-07 07:57:51 +00:00
|
|
|
.arg_target_triple("Build for the target triple")
|
2018-04-16 23:50:30 +00:00
|
|
|
.arg_target_dir()
|
2018-03-06 21:01:03 +00:00
|
|
|
.arg_manifest_path()
|
2020-03-24 21:31:28 +00:00
|
|
|
.arg_ignore_rust_version()
|
2018-03-06 21:01:03 +00:00
|
|
|
.arg_message_format()
|
2022-06-08 20:16:51 +00:00
|
|
|
.arg(flag(
|
2018-03-14 15:17:44 +00:00
|
|
|
"no-fail-fast",
|
|
|
|
"Run all benchmarks regardless of failure",
|
|
|
|
))
|
2020-03-08 22:12:18 +00:00
|
|
|
.arg_unit_graph()
|
2022-01-02 02:47:04 +00:00
|
|
|
.arg_timings()
|
2020-07-06 01:15:07 +00:00
|
|
|
.after_help("Run `cargo help bench` for more detailed information.\n")
|
2018-03-06 21:01:03 +00:00
|
|
|
}
|
2018-03-12 21:06:04 +00:00
|
|
|
|
2022-01-04 17:04:50 +00:00
|
|
|
pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult {
|
2018-03-12 21:06:04 +00:00
|
|
|
let ws = args.workspace(config)?;
|
2019-06-20 16:43:33 +00:00
|
|
|
let mut compile_opts = args.compile_options(
|
|
|
|
config,
|
|
|
|
CompileMode::Bench,
|
|
|
|
Some(&ws),
|
2021-07-13 22:22:09 +00:00
|
|
|
ProfileChecking::Custom,
|
2019-06-20 16:43:33 +00:00
|
|
|
)?;
|
2018-12-29 14:13:58 +00:00
|
|
|
|
2019-12-27 03:59:19 +00:00
|
|
|
compile_opts.build_config.requested_profile =
|
2021-07-13 22:22:09 +00:00
|
|
|
args.get_profile_name(config, "bench", ProfileChecking::Custom)?;
|
2018-03-12 21:06:04 +00:00
|
|
|
|
|
|
|
let ops = TestOptions {
|
2022-06-08 20:16:51 +00:00
|
|
|
no_run: args.flag("no-run"),
|
|
|
|
no_fail_fast: args.flag("no-fail-fast"),
|
2018-03-12 21:06:04 +00:00
|
|
|
compile_opts,
|
|
|
|
};
|
|
|
|
|
2022-06-08 20:16:51 +00:00
|
|
|
let bench_args = args.get_one::<String>("BENCHNAME").into_iter();
|
|
|
|
let bench_args = bench_args.chain(args.get_many::<String>("args").unwrap_or_default());
|
|
|
|
let bench_args = bench_args.map(String::as_str).collect::<Vec<_>>();
|
2018-03-12 21:06:04 +00:00
|
|
|
|
2022-08-28 00:45:11 +00:00
|
|
|
ops::run_benches(&ws, &ops, &bench_args)
|
2018-03-12 21:06:04 +00:00
|
|
|
}
|