Struct cpu_time::ThreadTime
source · pub struct ThreadTime(_, _);
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 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for ThreadTime
impl Debug for ThreadTime
source§impl Hash for ThreadTime
impl Hash for ThreadTime
source§impl PartialEq<ThreadTime> for ThreadTime
impl PartialEq<ThreadTime> 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 ==
.