File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
datafusion/core/src/physical_plan/metrics Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -176,14 +176,23 @@ impl Time {
176
176
}
177
177
178
178
/// 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
179
188
pub fn add_duration ( & self , duration : Duration ) {
180
189
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 ) ;
182
191
}
183
192
184
193
/// Add the number of nanoseconds of other `Time` to self
185
194
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 ) )
187
196
}
188
197
189
198
/// return a scoped guard that adds the amount of time elapsed
You can’t perform that action at this time.
0 commit comments