Skip to content

Commit

Permalink
reset executor and task queue stats when retrieved like IO stats
Browse files Browse the repository at this point in the history
Not strictly necessary right now but consistency with the IO stats is
desirable
  • Loading branch information
HippoBaro committed Dec 1, 2021
1 parent fd7f3fc commit 65aaeb4
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions glommio/src/executor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ fn bind_to_cpu_set(cpus: impl IntoIterator<Item = usize>) -> 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 {
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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<TaskQueueStats> {
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)),
})
}
Expand Down Expand Up @@ -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
})
}
Expand All @@ -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
Expand Down

0 comments on commit 65aaeb4

Please sign in to comment.