brush_core/sys/unix/
resource.rs1use crate::error;
4
5pub fn get_self_user_and_system_time()
8-> Result<(std::time::Duration, std::time::Duration), error::Error> {
9 let usage = nix::sys::resource::getrusage(nix::sys::resource::UsageWho::RUSAGE_SELF)?;
10 Ok((
11 convert_rusage_time(usage.user_time()),
12 convert_rusage_time(usage.system_time()),
13 ))
14}
15
16pub fn get_children_user_and_system_time()
19-> Result<(std::time::Duration, std::time::Duration), error::Error> {
20 let usage = nix::sys::resource::getrusage(nix::sys::resource::UsageWho::RUSAGE_CHILDREN)?;
21 Ok((
22 convert_rusage_time(usage.user_time()),
23 convert_rusage_time(usage.system_time()),
24 ))
25}
26
27const fn convert_rusage_time(time: nix::sys::time::TimeVal) -> std::time::Duration {
28 #[allow(clippy::cast_sign_loss)]
29 #[allow(clippy::cast_possible_truncation)]
30 std::time::Duration::new(time.tv_sec() as u64, time.tv_usec() as u32 * 1000)
31}