Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/benaubin/os_clock
Work with Operating System clocks from Rust. Get CPU time of another thread, monotonic time, system time - all the time.
https://github.com/benaubin/os_clock
Last synced: 17 days ago
JSON representation
Work with Operating System clocks from Rust. Get CPU time of another thread, monotonic time, system time - all the time.
- Host: GitHub
- URL: https://github.com/benaubin/os_clock
- Owner: benaubin
- License: mit
- Created: 2020-09-10T16:51:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2020-09-11T03:06:35.000Z (over 4 years ago)
- Last Synced: 2024-04-24T19:48:25.943Z (8 months ago)
- Language: Rust
- Homepage: https://docs.rs/os_clock
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# os_clock
Access various operating system clocks (such as per-thread CPU Time, system clock, monotomic, etc) on Unix-family systems.
```rust
use os_clock::{self, Clock};let clock = cpu_clock_for_current_thread();
clock.get_time();
```Notably, a clock for the CPU time of one thread can be accessed from another thread:
```rust
let clock = cpu_clock_for_current_thread().unwrap();loop {
if clock.get_time().unwrap() > Duration::from_millis(5) {
break;
}
}std::thread::spawn(move || {
assert!(clock.get_time().unwrap() > Duration::from_millis(5));let self_clock = cpu_clock_for_current_thread().unwrap();
assert!(self_clock.get_time().unwrap() < Duration::from_millis(1));
})
.join()
.unwrap();
```## Compatibility
Works on recent iOS, Mac, as well as Unix-family systems with a `pthread.h` that defines `pthread_getcpuclockid` (most modern Linux).