pub struct ThreadTime(/* private fields */);Expand description
CPU Time Used by The Current Thread
This is an opaque type similar to std::time::Instant.
Use elapsed() or duration_since() to get meaningful time deltas.
This type is non-thread-shareable (!Sync, !Send) because otherwise it’s
to easy to mess up times from different threads. However, you can freely
send Duration’s returned by elapsed() and duration_since().
Implementations§
Source§impl ThreadTime
impl ThreadTime
Sourcepub fn now() -> Self
pub fn now() -> Self
Get current CPU time used by a process
§Panics
If CLOCK_THREAD_CPUTIME_ID is not supported by the kernel.
On Linux, it was added in version 2.6.12 (year 2005).
On OpenBSD & FreeBSD support was added in 2013.
On MacOS, clock_gettime was not supported until Sierra (2016).
Sourcepub fn try_elapsed(&self) -> Result<Duration>
pub fn try_elapsed(&self) -> Result<Duration>
Returns the amount of CPU time used by the current thread from the previous timestamp to now.
Sourcepub fn elapsed(&self) -> Duration
pub fn elapsed(&self) -> Duration
Returns the amount of CPU time used from the previous timestamp to now.
§Panics
If ThreadTime::now() panics.
Sourcepub fn duration_since(&self, timestamp: ThreadTime) -> Duration
pub fn duration_since(&self, timestamp: ThreadTime) -> Duration
Returns the amount of CPU time used by the current thread from the previous timestamp.
Sourcepub fn as_duration(&self) -> Duration
pub fn as_duration(&self) -> Duration
Returns the total amount of CPU time used from the program start.
Trait Implementations§
Source§impl Clone for ThreadTime
impl Clone for ThreadTime
Source§fn clone(&self) -> ThreadTime
fn clone(&self) -> ThreadTime
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 ThreadTime
Source§impl Debug for ThreadTime
impl Debug for ThreadTime
impl Eq for ThreadTime
Source§impl Hash for ThreadTime
impl Hash for ThreadTime
Source§impl PartialEq for ThreadTime
impl PartialEq for ThreadTime
Source§fn eq(&self, other: &ThreadTime) -> bool
fn eq(&self, other: &ThreadTime) -> bool
self and other values to be equal, and is used by ==.