Skip to content

Commit 400fa0d

Browse files
tustvoldmcheshkov
authored andcommitted
Always increment timer on record (apache#2298)
Can drop this after rebase on commit baa2a36 "Always increment timer on record (apache#2298)", first released in 8.0.0
1 parent 0ef85f4 commit 400fa0d

File tree

1 file changed

+11
-2
lines changed
  • datafusion/core/src/physical_plan/metrics

1 file changed

+11
-2
lines changed

datafusion/core/src/physical_plan/metrics/value.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,14 +176,23 @@ impl Time {
176176
}
177177

178178
/// Add duration of time to self
179+
///
180+
/// Note: this will always increment the recorded time by at least 1 nanosecond
181+
/// to distinguish between the scenario of no values recorded, in which
182+
/// case the value will be 0, and no measurable amount of time having passed,
183+
/// in which case the value will be small but not 0.
184+
///
185+
/// This is based on the assumption that the timing logic in most cases is likely
186+
/// to take at least a nanosecond, and so this is reasonable mechanism to avoid
187+
/// ambiguity, especially on systems with low-resolution monotonic clocks
179188
pub fn add_duration(&self, duration: Duration) {
180189
let more_nanos = duration.as_nanos() as usize;
181-
self.nanos.fetch_add(more_nanos, Ordering::Relaxed);
190+
self.nanos.fetch_add(more_nanos.max(1), Ordering::Relaxed);
182191
}
183192

184193
/// Add the number of nanoseconds of other `Time` to self
185194
pub fn add(&self, other: &Time) {
186-
self.nanos.fetch_add(other.value(), Ordering::Relaxed);
195+
self.add_duration(Duration::from_nanos(other.value() as u64))
187196
}
188197

189198
/// return a scoped guard that adds the amount of time elapsed

0 commit comments

Comments
 (0)