diff --git a/crates/metal2vulkan-runtime/src/queue_share.rs b/crates/metal2vulkan-runtime/src/queue_share.rs index 370b6328d..e9d20a7ce 100644 --- a/crates/metal2vulkan-runtime/src/queue_share.rs +++ b/crates/metal2vulkan-runtime/src/queue_share.rs @@ -349,6 +349,10 @@ pub(crate) struct QueueSwitch { /// (`tests/teardown_threads.rs`). #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] pub(crate) held: crate::freed_memory::held::Held, + /// The crate's device tests' timings of the check's last two steps, in nanoseconds: the + /// release of its Vulkan objects, and the drop of its shares of the device's parts. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + last_steps: [AtomicU64; 2], } impl QueueSwitch { @@ -368,6 +372,8 @@ impl QueueSwitch { stop_waited: AtomicU64::new(0), #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] held: Default::default(), + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + last_steps: Default::default(), } } @@ -448,6 +454,22 @@ impl QueueSwitch { } } + /// Record that the check's last step `step` (0 its objects' release, 1 its shares' drop) ran + /// from `from` until now. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn timed_step(&self, step: usize, from: Instant) { + let nanos = u64::try_from(from.elapsed().as_nanos()).unwrap_or(u64::MAX); + self.last_steps[step].store(nanos.max(1), Ordering::Release); + } + + /// How long the check's last two steps took ([`timed_step`](Self::timed_step)). + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + pub(crate) fn last_steps(&self) -> [Duration; 2] { + (self.last_steps) + .each_ref() + .map(|t| Duration::from_nanos(t.load(Ordering::Acquire))) + } + /// Let the tests' hold of the check go once the device's teardown began, or once it was let /// go already. #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] diff --git a/crates/metal2vulkan-runtime/src/queue_switch_check.rs b/crates/metal2vulkan-runtime/src/queue_switch_check.rs index 3c4e285e7..07e61e7a8 100644 --- a/crates/metal2vulkan-runtime/src/queue_switch_check.rs +++ b/crates/metal2vulkan-runtime/src/queue_switch_check.rs @@ -109,7 +109,11 @@ pub(crate) fn start(device: &Device) -> bool { let switch = Arc::clone(&parts.switch); run(&parts); // Its shares go before the teardown that waits for it goes on. + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + let dropping = Instant::now(); drop(parts); + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + switch.timed_step(1, dropping); switch.ended(); }); if spawned.is_err() { @@ -230,7 +234,11 @@ fn measure(parts: &Parts, pair: (usize, usize)) -> Result, Er Ok(_) => Ok(None), Err(error) => Err(error), }; + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + let releasing = Instant::now(); objects.release(parts); + #[cfg(all(test, any(m2v_gpu, m2v_cpu_icd)))] + parts.switch.timed_step(0, releasing); gaps } diff --git a/crates/metal2vulkan-runtime/src/tests/teardown_threads.rs b/crates/metal2vulkan-runtime/src/tests/teardown_threads.rs index c09536ebd..d93480349 100644 --- a/crates/metal2vulkan-runtime/src/tests/teardown_threads.rs +++ b/crates/metal2vulkan-runtime/src/tests/teardown_threads.rs @@ -612,7 +612,11 @@ fn a_running_queue_switch_check_leaves_the_device_to_the_program_s_thread() { let waited = switch .stop_waited() .expect("the teardown waited for the running check"); - println!("the last drop took {dropped:?}, of which the wait for the check {waited:?}"); + let [release, shares] = switch.last_steps(); + println!( + "the last drop took {dropped:?}, of which the wait for the check {waited:?} (its objects' \ + release {release:?}, its shares' drop {shares:?})" + ); assert!( waited < RELEASE, "the teardown waited {waited:?} for the check"