Skip to content

Commit

Permalink
Don't insert counters when stat is disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
caizixian committed May 19, 2021
1 parent 86fdf49 commit d57f22c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
12 changes: 7 additions & 5 deletions src/scheduler/stat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,13 @@ impl WorkerLocalStat {
type_id: work_id,
type_name: work_name,
};
self.work_counters
.entry(work_id)
.or_insert_with(WorkerLocalStat::counter_set)
.iter_mut()
.for_each(|c| c.start());
if self.is_enabled() {
self.work_counters
.entry(work_id)
.or_insert_with(WorkerLocalStat::counter_set)
.iter_mut()
.for_each(|c| c.start());
}
stat
}

Expand Down
6 changes: 3 additions & 3 deletions src/scheduler/work_counter.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use std::time::SystemTime;

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub(super) struct WorkCounterBase {
pub(super) total: f64,
pub(super) min: f64,
Expand All @@ -17,7 +17,7 @@ impl<T: 'static + WorkCounter + Clone> WorkCounterClone for T {
}
}

pub(super) trait WorkCounter: WorkCounterClone {
pub(super) trait WorkCounter: WorkCounterClone + std::fmt::Debug {
// TODO: consolidate with crate::util::statistics::counter::Counter;
fn start(&mut self);
fn stop(&mut self);
Expand Down Expand Up @@ -63,7 +63,7 @@ impl WorkCounterBase {
}
}

#[derive(Copy, Clone)]
#[derive(Copy, Clone, Debug)]
pub(super) struct WorkDuration {
base: WorkCounterBase,
start_value: Option<SystemTime>,
Expand Down

0 comments on commit d57f22c

Please sign in to comment.