Skip to content
Open
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
99 changes: 87 additions & 12 deletions lib/bencher_adapter/src/adapters/rust/gungraun.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,31 @@ fn single_benchmark<'a>()
|(benchmark_name, measures)| {
// trim here to avoid loose `\r` chars at the end of the string because of the
// `not_benchmark_name_end` parser. It's maybe not a bad idea anyways.
let benchmark_name = benchmark_name.trim().parse().ok()?;
let trimmed = benchmark_name.trim();

// As of v0.18.0, the possible values and cases to handle for the first line(s) are
//
// `file::group::func`, No id (which is fine, the module path is unique in this case)
// `file::group::func :description`, No/Empty id
// `file::group::func (rest`, No id, the description in this case starts with a `(`
// `file::group::func id`, No description, (also fine)
// `file::group::func id:`, This was a possibility but not in recent releases
// `file::group::func id:description`, The standard case
let (module_path, rest) = trimmed.split_once(' ').unwrap_or((trimmed, ""));
let id_end = rest
.chars()
.position(|c| !(c.is_ascii_alphanumeric() || c == '_'))
.or(Some(rest.len()))
.and_then(|c| (c > 0).then_some(c));

let benchmark_name = if let Some(id_end) = id_end {
// The `None` case should not happen and would be a hard error
trimmed.get(0..module_path.len() + 1 + id_end)?
} else {
module_path
};

let benchmark_name = benchmark_name.parse().ok()?;
let measures = measures.into_iter().flatten().collect();

Some((benchmark_name, measures))
Expand Down Expand Up @@ -514,7 +538,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci short:10",
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci short",
);
}

Expand All @@ -531,7 +555,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci long:30",
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci long",
);
}
}
Expand Down Expand Up @@ -593,7 +617,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci short:10",
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci short",
);
}

Expand All @@ -603,7 +627,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci long:30",
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci long",
);
}
}
Expand Down Expand Up @@ -1011,7 +1035,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench::multiple_lines id:string with two\nlines",
"rust_iai_callgrind::bench::multiple_lines id_0",
);
}

Expand All @@ -1030,7 +1054,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench::multiple_lines id:string with multiple\nlines\nand one more",
"rust_iai_callgrind::bench::multiple_lines id_1",
);
}
}
Expand Down Expand Up @@ -1060,7 +1084,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench::multiple_lines id:first with one line",
"rust_iai_callgrind::bench::multiple_lines id_0",
);
}

Expand All @@ -1079,7 +1103,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench::multiple_lines id:two\nlines",
"rust_iai_callgrind::bench::multiple_lines id_1",
);
}

Expand All @@ -1098,11 +1122,62 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
&results,
"rust_iai_callgrind::bench::multiple_lines id:last with one line",
"rust_iai_callgrind::bench::multiple_lines id_2",
);
}
}

#[test]
fn name_with_valid_benchmark_ids() {
use gungraun::*;

let results =
convert_file_path::<AdapterRustGungraun>("./tool_output/rust/gungraun/valid_ids.txt");

let mut expected = HashMap::new();
expected.extend([(Instructions::SLUG_STR, 1734.0)]);

assert_eq!(results.inner.len(), 9);

compare_benchmark(&expected, &results, "rust_gungraun::some_group::no_id");
compare_benchmark(
&expected,
&results,
"rust_gungraun::some_group::no_id_but_description_0",
);
compare_benchmark(
&expected,
&results,
"rust_gungraun::some_group::no_id_but_description_1",
);
compare_benchmark(
&expected,
&results,
"rust_gungraun::some_group::no_id_multiline_description",
);
compare_benchmark(&expected, &results, "rust_gungraun::some_group::just_id id");
compare_benchmark(
&expected,
&results,
"rust_gungraun::some_group::id_with_alnum id_123_xyz",
);
compare_benchmark(
&expected,
&results,
"rust_gungraun::some_group::id_with_empty_description id_0",
);
compare_benchmark(
&expected,
&results,
"rust_gungraun::some_group::id_with_description id_with_description",
);
compare_benchmark(
&expected,
&results,
"rust_gungraun::some_group::id_with_description id_space_after_color",
);
}

#[derive(Default)]
pub struct OptionalMetrics {
pub global_bus_events: bool,
Expand Down Expand Up @@ -1147,7 +1222,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
results,
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci short:10",
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci short",
);
}

Expand Down Expand Up @@ -1183,7 +1258,7 @@ pub(crate) mod test_rust_gungraun {
compare_benchmark(
&expected,
results,
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci long:30",
"rust_iai_callgrind::bench_fibonacci_group::bench_fibonacci long",
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

rust_iai_callgrind::bench::multiple_lines id:string with two
rust_iai_callgrind::bench::multiple_lines id_0:string with two
lines
Instructions: 1|N/A (*********)
L1 Hits: 2|N/A (*********)
L2 Hits: 3|N/A (*********)
RAM Hits: 4|N/A (*********)
Total read+write: 5|N/A (*********)
Estimated Cycles: 6|N/A (*********)
rust_iai_callgrind::bench::multiple_lines id:string with multiple
rust_iai_callgrind::bench::multiple_lines id_1:string with multiple
lines
and one more
Instructions: 7|N/A (*********)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

rust_iai_callgrind::bench::multiple_lines id:first with one line
rust_iai_callgrind::bench::multiple_lines id_0:first with one line
Instructions: 1|N/A (*********)
L1 Hits: 2|N/A (*********)
L2 Hits: 3|N/A (*********)
RAM Hits: 4|N/A (*********)
Total read+write: 5|N/A (*********)
Estimated Cycles: 6|N/A (*********)
rust_iai_callgrind::bench::multiple_lines id:two
rust_iai_callgrind::bench::multiple_lines id_1:two
lines
Instructions: 7|N/A (*********)
L1 Hits: 8|N/A (*********)
L2 Hits: 9|N/A (*********)
RAM Hits: 10|N/A (*********)
Total read+write: 11|N/A (*********)
Estimated Cycles: 12|N/A (*********)
rust_iai_callgrind::bench::multiple_lines id:last with one line
rust_iai_callgrind::bench::multiple_lines id_2:last with one line
Instructions: 13|N/A (*********)
L1 Hits: 14|N/A (*********)
L2 Hits: 15|N/A (*********)
Expand Down
24 changes: 24 additions & 0 deletions lib/bencher_adapter/tool_output/rust/gungraun/valid_ids.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

rust_gungraun::some_group::no_id
Instructions: 1734|N/A (*********)
rust_gungraun::some_group::no_id_but_description_0 :some description
Instructions: 1734|N/A (*********)
rust_gungraun::some_group::no_id_but_description_1 () -> echo
Instructions: 1734|N/A (*********)
rust_gungraun::some_group::no_id_multiline_description :multiline
description
Instructions: 1734|N/A (*********)
rust_gungraun::some_group::just_id id
Instructions: 1734|N/A (*********)
rust_gungraun::some_group::id_with_alnum id_123_xyz
Instructions: 1734|N/A (*********)
rust_gungraun::some_group::id_with_empty_description id_0:
Instructions: 1734|N/A (*********)
rust_gungraun::some_group::id_with_description id_with_description:some description
Instructions: 1734|N/A (*********)
rust_gungraun::some_group::id_with_description id_space_after_color: some description
Instructions: 1734|N/A (*********)
Loading