From 65aaeb4e5940ec757179e6155470b655f06dbe91 Mon Sep 17 00:00:00 2001 From: "hippolyte.barraud" Date: Wed, 1 Dec 2021 03:04:46 +0100 Subject: [PATCH] reset executor and task queue stats when retrieved like IO stats Not strictly necessary right now but consistency with the IO stats is desirable --- glommio/src/executor/mod.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/glommio/src/executor/mod.rs b/glommio/src/executor/mod.rs index 3f2f40190..c7b2159bd 100644 --- a/glommio/src/executor/mod.rs +++ b/glommio/src/executor/mod.rs @@ -226,7 +226,7 @@ fn bind_to_cpu_set(cpus: impl IntoIterator) -> Result<()> { // Stats should be copied Infrequently, and if you have enough stats to fill a // Kb with data from a single source, maybe you should rethink your life // choices. -#[derive(Debug, Copy, Clone)] +#[derive(Debug, Copy, Clone, Default)] /// Allows information about the current state of this executor to be consumed /// by applications. pub struct ExecutorStats { @@ -324,6 +324,18 @@ impl TaskQueueStats { pub fn queue_selected(&self) -> u64 { self.queue_selected } + + pub(crate) fn take(&mut self) -> Self { + std::mem::replace( + self, + Self { + index: self.index, + reciprocal_shares: self.reciprocal_shares, + queue_selected: Default::default(), + runtime: Default::default(), + }, + ) + } } #[derive(Debug)] @@ -1993,7 +2005,7 @@ impl ExecutorProxy { /// [`Result`]: https://doc.rust-lang.org/std/result/enum.Result.html pub fn task_queue_stats(&self, handle: TaskQueueHandle) -> Result { LOCAL_EX.with(|local_ex| match local_ex.get_queue(&handle) { - Some(x) => Ok(x.borrow().stats), + Some(x) => Ok(x.borrow_mut().stats.take()), None => Err(GlommioError::queue_not_found(handle.index)), }) } @@ -2036,7 +2048,11 @@ impl ExecutorProxy { { LOCAL_EX.with(|local_ex| { let tq = local_ex.queues.borrow(); - output.extend(tq.available_executors.values().map(|x| x.borrow().stats)); + output.extend( + tq.available_executors + .values() + .map(|x| x.borrow_mut().stats.take()), + ); output }) } @@ -2062,7 +2078,7 @@ impl ExecutorProxy { /// /// [`ExecutorStats`]: struct.ExecutorStats.html pub fn executor_stats(&self) -> ExecutorStats { - LOCAL_EX.with(|local_ex| local_ex.queues.borrow().stats) + LOCAL_EX.with(|local_ex| std::mem::take(&mut local_ex.queues.borrow_mut().stats)) } /// Returns an [`IoStats`] struct with information about IO performed by