Skip to content

Commit 3d7a2a3

Browse files
feat: use the same uri scheme for walltime and intrumented
1 parent ff6f4b3 commit 3d7a2a3

File tree

5 files changed

+37
-13
lines changed

5 files changed

+37
-13
lines changed

crates/divan_compat/divan_fork/src/divan.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,9 @@ impl Divan {
311311
if should_compute_stats {
312312
let stats = bench_context.compute_stats();
313313
{
314+
// WARNING: Keep in sync with `codspeed-divan-compat::uri::generate`
315+
// Not worth doing the work of actually using the same code since this fork
316+
// is temporary
314317
let name = bench_entry.display_name().to_string();
315318
let file = bench_entry.meta().location.file;
316319
let mut module_path = bench_entry
@@ -588,9 +591,7 @@ impl Divan {
588591
///
589592
/// ```
590593
/// # use divan::Divan;
591-
/// let divan = Divan::default()
592-
/// .skip_regex("(add|sub)")
593-
/// .skip_regex("collections.*default");
594+
/// let divan = Divan::default().skip_regex("(add|sub)").skip_regex("collections.*default");
594595
/// ```
595596
///
596597
/// # Panics
@@ -620,9 +621,8 @@ impl Divan {
620621
///
621622
/// ```
622623
/// # use divan::Divan;
623-
/// let divan = Divan::default()
624-
/// .skip_exact("arithmetic::add")
625-
/// .skip_exact("collections::vec::default");
624+
/// let divan =
625+
/// Divan::default().skip_exact("arithmetic::add").skip_exact("collections::vec::default");
626626
/// ```
627627
#[must_use]
628628
pub fn skip_exact(mut self, filter: impl Into<String>) -> Self {

crates/divan_compat/src/compat/entry.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,13 @@ pub struct EntryMeta {
5656
pub bench_options: Option<LazyLock<BenchOptions>>,
5757
}
5858

59+
impl EntryMeta {
60+
#[inline]
61+
pub(crate) fn module_path_components<'a>(&self) -> impl Iterator<Item = &'a str> {
62+
self.module_path.split("::")
63+
}
64+
}
65+
5966
/// Where an entry is located.
6067
#[derive(Clone, Copy, Default, PartialEq, Eq, PartialOrd, Ord)]
6168
#[allow(missing_docs)]

crates/divan_compat/src/compat/mod.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ mod util;
1515

1616
pub use bench::*;
1717

18+
use crate::uri;
19+
1820
pub fn main() {
1921
// Outlined steps of original divan::main and their equivalent in codspeed instrumented mode
2022
// 1. Get registered entries
@@ -31,13 +33,7 @@ pub fn main() {
3133

3234
// 4. Scan the tree and execute benchmarks
3335
for entry in bench_entries.iter() {
34-
let entry_uri = format!(
35-
"{}:{}::{}::{}",
36-
entry.meta.location.file,
37-
entry.meta.location.line,
38-
entry.meta.module_path,
39-
entry.meta.display_name,
40-
);
36+
let entry_uri = uri::generate(entry.meta.display_name, &entry.meta);
4137

4238
if let Some(options) = &entry.meta.bench_options.as_ref() {
4339
if let Some(true) = options.ignore {

crates/divan_compat/src/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
pub use codspeed::codspeed_uri;
22

3+
mod uri;
4+
35
#[cfg(not(codspeed))]
46
mod compat_divan {
57
pub use divan::*;

crates/divan_compat/src/uri.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
use crate::__private::EntryMeta;
2+
3+
pub(crate) fn generate(
4+
bench_display_name: impl std::fmt::Display,
5+
bench_meta: &EntryMeta,
6+
) -> String {
7+
let file = bench_meta.location.file;
8+
let mut module_path = bench_meta
9+
.module_path_components()
10+
.skip(1)
11+
.collect::<Vec<_>>()
12+
.join("::");
13+
if !module_path.is_empty() {
14+
module_path.push_str("::");
15+
}
16+
let uri = format!("{file}::{module_path}{bench_display_name}");
17+
18+
uri
19+
}

0 commit comments

Comments
 (0)