Skip to content

Commit 20a466f

Browse files
committed
feat(divan_fork): add the codspeed walltime collection point
1 parent c433244 commit 20a466f

File tree

4 files changed

+33
-1
lines changed

4 files changed

+33
-1
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/divan_compat/divan_fork/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ cfg-if = "1"
2020
clap = { version = "4", default-features = false, features = ["std", "env"] }
2121
condtype = "1.3"
2222
regex = { package = "regex-lite", version = "0.1", default-features = false, features = ["std", "string"] }
23+
codspeed = { path = "../../codspeed", version = "=2.8.0-alpha.0" }
2324

2425
[target.'cfg(unix)'.dependencies]
2526
libc = "0.2.148"

crates/divan_compat/divan_fork/src/bench/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ pub(crate) struct BenchContext<'a> {
529529
pub thread_count: NonZeroUsize,
530530

531531
/// Recorded samples.
532-
samples: SampleCollection,
532+
pub samples: SampleCollection,
533533

534534
/// Per-iteration counters grouped by sample.
535535
counters: CounterCollection,

crates/divan_compat/divan_fork/src/divan.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,36 @@ impl Divan {
310310

311311
if should_compute_stats {
312312
let stats = bench_context.compute_stats();
313+
{
314+
let name = bench_entry.display_name().to_string();
315+
let file = bench_entry.meta().location.file;
316+
let mut module_path = bench_entry
317+
.meta()
318+
.module_path_components()
319+
.skip(1)
320+
.collect::<Vec<_>>()
321+
.join("::");
322+
if !module_path.is_empty() {
323+
module_path.push_str("::");
324+
}
325+
let uri = format!("{file}::{module_path}{name}");
326+
let iter_per_round = bench_context.samples.sample_size;
327+
let times_ns: Vec<_> = bench_context
328+
.samples
329+
.time_samples
330+
.iter()
331+
.map(|s| s.duration.picos / 1_000)
332+
.collect();
333+
let max_time_ns = options.max_time.map(|t| t.as_nanos());
334+
::codspeed::walltime::collect_raw_walltime_results(
335+
"divan",
336+
name,
337+
uri,
338+
iter_per_round,
339+
max_time_ns,
340+
times_ns,
341+
);
342+
};
313343
tree_painter.borrow_mut().finish_leaf(
314344
is_last_thread_count,
315345
&stats,

0 commit comments

Comments
 (0)