Skip to content

Commit 15bbfef

Browse files
committed
feat(divan_compat): add root frame and ipc with runner
1 parent 09f14e9 commit 15bbfef

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -657,6 +657,7 @@ impl<'a> BenchContext<'a> {
657657

658658
let bench_overheads = timer.bench_overheads();
659659

660+
let _guard = codspeed::fifo::BenchGuard::new_with_runner_fifo();
660661
while {
661662
// Conditions for when sampling is over:
662663
if elapsed_picos >= max_picos {
@@ -810,6 +811,7 @@ impl<'a> BenchContext<'a> {
810811
elapsed_picos = elapsed_picos.saturating_add(progress_picos);
811812
}
812813
}
814+
core::mem::drop(_guard);
813815

814816
// Reset flag for ignoring allocations.
815817
crate::alloc::IGNORE_ALLOC.set(false);

crates/divan_compat/divan_fork/src/divan.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,13 @@ mod codspeed {
428428
bench_context.samples.time_samples.iter().map(|s| s.duration.picos / 1_000).collect();
429429
let max_time_ns = bench_context.options.max_time.map(|t| t.as_nanos());
430430

431+
if let Err(error) = ::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
432+
pid: std::process::id(),
433+
uri: uri.clone(),
434+
}) {
435+
eprintln!("Failed to send benchmark URI to runner: {}", error);
436+
}
437+
431438
::codspeed::walltime::collect_raw_walltime_results(
432439
"divan",
433440
bench_name,

crates/divan_compat/divan_fork/src/thread_pool.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,9 +201,17 @@ impl<F> TaskShared<F> {
201201
where
202202
F: Fn(usize),
203203
{
204-
let task_fn = &(*task.cast::<TaskShared<F>>()).task_fn;
204+
#[inline(never)]
205+
unsafe fn __codspeed_root_frame__<F>(task: *const TaskShared<()>, thread: usize)
206+
where
207+
F: Fn(usize),
208+
{
209+
let task_fn = &(*task.cast::<TaskShared<F>>()).task_fn;
210+
211+
task_fn(thread);
212+
}
205213

206-
task_fn(thread);
214+
__codspeed_root_frame__::<F>(task, thread);
207215
}
208216

209217
Self {

0 commit comments

Comments
 (0)