pub struct ActiveClock {
pub banked_secs: u64,
pub since: Option<i64>,
}Expand description
A stopwatch that runs only while the thing it measures is actually working.
Wall-clock age and working time are different questions, and the difference
is the whole point of this type: a run paused overnight is twelve hours old
and spent eleven of them doing nothing. Age comes from started_at; this is
what a reader means by “how long has this taken”.
Kept as banked seconds plus the start of the span in progress, rather than a single total, so a reader that polls between writes still sees the number climb instead of stepping once per heartbeat.
Fields§
§banked_secs: u64Seconds banked from spans that have already ended.
since: Option<i64>When the span in progress began, or None while the clock is stopped.
Implementations§
Source§impl ActiveClock
impl ActiveClock
Sourcepub fn observe(&mut self, now: i64, running: bool)
pub fn observe(&mut self, now: i64, running: bool)
Start or stop the clock to match running, banking the span that ends.
Idempotent: called every persist tick with the same answer, it does nothing, so only genuine transitions move the accounting.
Sourcepub fn settle(&mut self, as_of: i64)
pub fn settle(&mut self, as_of: i64)
Close the span in progress at as_of, banking it.
For a clock read back from disk: whatever the run was doing stopped when the daemon holding it did, which is the last moment the record was written - not now. Without this, a run reloaded after the daemon was down for a day comes back claiming a day’s work.
Sourcepub fn total_secs(&self, now: i64) -> u64
pub fn total_secs(&self, now: i64) -> u64
Working seconds at now, counting the span in progress.
Trait Implementations§
Source§impl Clone for ActiveClock
impl Clone for ActiveClock
Source§fn clone(&self) -> ActiveClock
fn clone(&self) -> ActiveClock
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl Copy for ActiveClock
Source§impl Debug for ActiveClock
impl Debug for ActiveClock
Source§impl Default for ActiveClock
impl Default for ActiveClock
Source§fn default() -> ActiveClock
fn default() -> ActiveClock
Source§impl<'de> Deserialize<'de> for ActiveClock
impl<'de> Deserialize<'de> for ActiveClock
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for ActiveClock
Source§impl PartialEq for ActiveClock
impl PartialEq for ActiveClock
Source§impl Serialize for ActiveClock
impl Serialize for ActiveClock
impl StructuralPartialEq for ActiveClock
Auto Trait Implementations§
impl Freeze for ActiveClock
impl RefUnwindSafe for ActiveClock
impl Send for ActiveClock
impl Sync for ActiveClock
impl Unpin for ActiveClock
impl UnsafeUnpin for ActiveClock
impl UnwindSafe for ActiveClock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.