Skip to content

Commit 2600686

Browse files
Merge pull request #1138 from nnethercote/exact-include-exclude
Make `--include` and `--exclude` use exact matching.
2 parents 307bf1a + 6300a08 commit 2600686

File tree

2 files changed

+46
-26
lines changed

2 files changed

+46
-26
lines changed

collector/README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,13 @@ The following options alter the behaviour of the `bench_local` subcommand.
100100
supports postgres as a backend and the URL can be specified (beginning with
101101
`postgres://`), but this is unlikely to be useful for local collection.
102102
- `--exclude <EXCLUDE>`: this is used to run a subset of the benchmarks. The
103-
argument is a comma-separated list of strings. When this option is specified,
104-
a benchmark is excluded from the run if its name contains one or more of the
105-
given strings.
103+
argument is a comma-separated list of benchmark names. When this option is
104+
specified, a benchmark is excluded from the run if its name matches one or
105+
more of the given names.
106106
- `--include <INCLUDE>`: the inverse of `--exclude`. The argument is a
107-
comma-separated list of strings. When this option is specified, a benchmark
108-
is included in the run only if its name contains one or more of the given
109-
strings.
107+
comma-separated list of benchmark names. When this option is specified, a
108+
benchmark is included in the run only if its name matches one or more of the
109+
given names.
110110
- `--runs $RUNS`: the run kinds to be benchmarked. The possible choices are one
111111
or more (comma-separated) of `Full`, `IncrFull`, `IncrUnchanged`,
112112
`IncrPatched`, and `All`. The default is `All`. Note that `IncrFull` is

collector/src/main.rs

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -375,32 +375,52 @@ fn get_benchmarks(
375375
}
376376
paths.push((PathBuf::from("rustc"), String::from("rustc")));
377377

378-
'outer: for (path, name) in paths {
379-
if let Some(include) = include {
380-
if !include
381-
.split(',')
382-
.any(|to_include| name.contains(to_include))
383-
{
378+
let mut includes = include.map(|list| list.split(',').collect::<HashSet<_>>());
379+
let mut excludes = exclude.map(|list| list.split(',').collect::<HashSet<_>>());
380+
381+
for (path, name) in paths {
382+
let mut skip = false;
383+
if let Some(includes) = includes.as_mut() {
384+
if !includes.remove(name.as_str()) {
384385
debug!(
385-
"benchmark {} - doesn't match --include argument, skipping",
386+
"benchmark {} - not named by --include argument, skipping",
386387
name
387388
);
388-
continue 'outer;
389+
skip = true;
389390
}
390391
}
391392

392-
if let Some(exclude) = exclude {
393-
for exc in exclude.split(',') {
394-
if name.contains(exc) {
395-
debug!("benchmark {} - matches --exclude argument, skipping", name);
396-
continue 'outer;
397-
}
393+
if let Some(excludes) = excludes.as_mut() {
394+
if excludes.remove(name.as_str()) {
395+
debug!("benchmark {} - named by --exclude argument, skipping", name);
396+
skip = true;
398397
}
399398
}
399+
if skip {
400+
continue;
401+
}
400402

401403
debug!("benchmark `{}`- registered", name);
402404
benchmarks.push(Benchmark::new(name, path)?);
403405
}
406+
407+
if let Some(includes) = includes {
408+
if !includes.is_empty() {
409+
bail!(
410+
"Warning: one or more invalid --include entries: {:?}",
411+
includes
412+
);
413+
}
414+
}
415+
if let Some(excludes) = excludes {
416+
if !excludes.is_empty() {
417+
bail!(
418+
"Warning: one or more invalid --exclude entries: {:?}",
419+
excludes
420+
);
421+
}
422+
}
423+
404424
benchmarks.sort_by_key(|benchmark| benchmark.name.clone());
405425

406426
if benchmarks.is_empty() {
@@ -717,10 +737,10 @@ fn main_result() -> anyhow::Result<i32> {
717737
(@arg CARGO: --cargo +takes_value "The path to the local Cargo to use")
718738
(@arg DB: --db +takes_value "Database output file")
719739
(@arg EXCLUDE: --exclude +takes_value
720-
"Exclude all benchmarks matching anything in\n\
740+
"Exclude all benchmarks that are listed in\n\
721741
this comma-separated list of patterns")
722742
(@arg INCLUDE: --include +takes_value
723-
"Include only benchmarks matching something in\n\
743+
"Include only benchmarks that are listed in\n\
724744
this comma-separated list of patterns")
725745
(@arg RUNS: --runs +takes_value
726746
"One or more (comma-separated) of: 'Full',\n\
@@ -769,10 +789,10 @@ fn main_result() -> anyhow::Result<i32> {
769789
'Debug', 'Doc', 'Opt', 'All'")
770790
(@arg CARGO: --cargo +takes_value "The path to the local Cargo to use")
771791
(@arg EXCLUDE: --exclude +takes_value
772-
"Exclude all benchmarks matching anything in\n\
792+
"Exclude all benchmarks that are listed in\n\
773793
this comma-separated list of patterns")
774794
(@arg INCLUDE: --include +takes_value
775-
"Include only benchmarks matching something in\n\
795+
"Include only benchmarks that are listed in\n\
776796
this comma-separated list of patterns")
777797
(@arg OUT_DIR: --("out-dir") +takes_value "Output directory")
778798
(@arg RUNS: --runs +takes_value
@@ -798,10 +818,10 @@ fn main_result() -> anyhow::Result<i32> {
798818
'Debug', 'Doc', 'Opt', 'All'")
799819
(@arg CARGO: --cargo +takes_value "The path to the local Cargo to use")
800820
(@arg EXCLUDE: --exclude +takes_value
801-
"Exclude all benchmarks matching anything in\n\
821+
"Exclude all benchmarks that are listed in\n\
802822
this comma-separated list of patterns")
803823
(@arg INCLUDE: --include +takes_value
804-
"Include only benchmarks matching something in\n\
824+
"Include only benchmarks that are listed in\n\
805825
this comma-separated list of patterns")
806826
(@arg OUT_DIR: --("out-dir") +takes_value "Output directory")
807827
(@arg RUNS: --runs +takes_value

0 commit comments

Comments
 (0)