use super::{Driver, Shard};
use crate::rt::counters::Published;
impl Driver {
pub(super) fn backend(&self) -> crate::IoBackend {
match self {
Driver::Poll(_) => crate::proactor::POLLER,
#[cfg(ring)]
Driver::Ring(_) | Driver::Gone => crate::IoBackend::IoUring,
}
}
}
impl Shard {
#[cfg(test)]
pub(crate) fn publish_now(&self) {
self.count_again(self.since_drive());
self.publish();
}
#[cfg(all(completion, feature = "io-stats"))]
pub(super) fn time_io(&self) {
let Some(times) = self.shared.counters.io_times() else {
return;
};
match &self.driver {
#[cfg(ring)]
Driver::Ring(ring) => ring.time_with(std::sync::Arc::clone(times)),
#[cfg(ring)]
Driver::Gone => {}
#[cfg(readiness)]
Driver::Poll(_) => {}
#[cfg(port)]
Driver::Poll(_) => self.shared.port.time_with(std::sync::Arc::clone(times)),
}
}
pub(super) fn slept_for(&self, slept: std::time::Duration, tells_the_spin: bool) {
self.sleeps.set(self.sleeps.get() + 1);
self.slept.set(self.slept.get() + slept);
if tells_the_spin {
self.spin.parked_for(slept);
}
}
pub(super) fn publish(&self) {
let (ops_in_flight, cq_overflows) = match &self.driver {
#[cfg(ring)]
Driver::Ring(ring) => (ring.in_flight(), ring.overflows()),
#[cfg(ring)]
Driver::Gone => (0, 0),
#[cfg(readiness)]
Driver::Poll(_) => (0, 0),
#[cfg(port)]
Driver::Poll(_) => (self.shared.port.out(), 0),
};
self.shared.counters.publish(Published {
polls: self.polls.get(),
parks: self.sleeps.get(),
parked: self.slept.get(),
queue_depth: self.queued(),
remote_wakes: self.remote_wakes.get(),
timers: self.wheel.borrow().armed(),
buffer_bytes: self.pool.charged(),
buffer_exhausted: self.pool.exhausted(),
ops_in_flight,
cq_overflows,
});
}
}