Skip to content

Commit e733f8b

Browse files
committed
feat(divan_compat): use bench markers
1 parent 0ba2272 commit e733f8b

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ mod args;
2929
mod defer;
3030
mod options;
3131

32+
use ::codspeed::instrument_hooks::InstrumentHooks;
3233
use defer::{DeferSlot, DeferStore};
3334

3435
pub use self::{
@@ -657,8 +658,7 @@ impl<'a> BenchContext<'a> {
657658

658659
let bench_overheads = timer.bench_overheads();
659660

660-
#[cfg(unix)]
661-
let _guard = codspeed::fifo::BenchGuard::new_with_runner_fifo();
661+
let _ = InstrumentHooks::instance().start_benchmark();
662662
while {
663663
// Conditions for when sampling is over:
664664
if elapsed_picos >= max_picos {
@@ -812,8 +812,7 @@ impl<'a> BenchContext<'a> {
812812
elapsed_picos = elapsed_picos.saturating_add(progress_picos);
813813
}
814814
}
815-
#[cfg(unix)]
816-
core::mem::drop(_guard);
815+
let _ = InstrumentHooks::instance().stop_benchmark();
817816

818817
// Reset flag for ignoring allocations.
819818
crate::alloc::IGNORE_ALLOC.set(false);
@@ -899,6 +898,7 @@ impl<'a> BenchContext<'a> {
899898
let sample_start: UntaggedTimestamp;
900899
let sample_end: UntaggedTimestamp;
901900

901+
let instrument_hooks = InstrumentHooks::instance();
902902
if size_of::<I>() == 0 && (size_of::<O>() == 0 || !mem::needs_drop::<O>()) {
903903
// Use a range instead of `defer_store` to make the benchmarking
904904
// loop cheaper.
@@ -914,6 +914,8 @@ impl<'a> BenchContext<'a> {
914914
}
915915

916916
sync_threads(true);
917+
918+
let start_time = InstrumentHooks::current_timestamp();
917919
sample_start = UntaggedTimestamp::start(timer_kind);
918920

919921
// Sample loop:
@@ -926,6 +928,9 @@ impl<'a> BenchContext<'a> {
926928
}
927929

928930
sample_end = UntaggedTimestamp::end(timer_kind);
931+
let end_time = InstrumentHooks::current_timestamp();
932+
instrument_hooks.add_benchmark_timestamps(start_time, end_time);
933+
929934
sync_threads(false);
930935
save_alloc_info();
931936

@@ -967,6 +972,7 @@ impl<'a> BenchContext<'a> {
967972
let defer_slots_iter = defer_slots_slice.iter();
968973

969974
sync_threads(true);
975+
let start_time = InstrumentHooks::current_timestamp();
970976
sample_start = UntaggedTimestamp::start(timer_kind);
971977

972978
// Sample loop:
@@ -981,6 +987,8 @@ impl<'a> BenchContext<'a> {
981987
}
982988

983989
sample_end = UntaggedTimestamp::end(timer_kind);
990+
let end_time = InstrumentHooks::current_timestamp();
991+
instrument_hooks.add_benchmark_timestamps(start_time, end_time);
984992
sync_threads(false);
985993
save_alloc_info();
986994

@@ -1020,6 +1028,7 @@ impl<'a> BenchContext<'a> {
10201028
let defer_inputs_iter = defer_inputs_slice.iter();
10211029

10221030
sync_threads(true);
1031+
let start_time = InstrumentHooks::current_timestamp();
10231032
sample_start = UntaggedTimestamp::start(timer_kind);
10241033

10251034
// Sample loop:
@@ -1030,6 +1039,8 @@ impl<'a> BenchContext<'a> {
10301039
}
10311040

10321041
sample_end = UntaggedTimestamp::end(timer_kind);
1042+
let end_time = InstrumentHooks::current_timestamp();
1043+
instrument_hooks.add_benchmark_timestamps(start_time, end_time);
10331044
sync_threads(false);
10341045
save_alloc_info();
10351046

crates/divan_compat/divan_fork/src/divan.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -430,19 +430,13 @@ mod codspeed {
430430
bench_context.samples.time_samples.iter().map(|s| s.duration.picos / 1_000).collect();
431431
let max_time_ns = bench_context.options.max_time.map(|t| t.as_nanos());
432432

433-
#[cfg(unix)]
433+
if let Err(error) =
434+
::codspeed::instrument_hooks::InstrumentHooks::instance().set_executed_benchmark(&uri)
434435
{
435-
if let Err(error) =
436-
::codspeed::fifo::send_cmd(codspeed::fifo::Command::CurrentBenchmark {
437-
pid: std::process::id(),
438-
uri: uri.clone(),
439-
})
436+
if ::codspeed::utils::running_with_codspeed_runner()
437+
&& ::codspeed::utils::is_perf_enabled()
440438
{
441-
if codspeed::utils::running_with_codspeed_runner()
442-
&& codspeed::utils::is_perf_enabled()
443-
{
444-
eprintln!("Failed to send benchmark URI to runner: {error:?}");
445-
}
439+
eprintln!("Failed to set executed benchmark URI: {error:?}");
446440
}
447441
}
448442

0 commit comments

Comments
 (0)