MCPcopy Index your code
hub / github.com/RustPython/RustPython / from_timeval

Function from_timeval

crates/vm/src/stdlib/time.rs:1339–1346  ·  view source on GitHub ↗
(tv: libc::timeval, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

1337 pub(super) fn get_process_time(vm: &VirtualMachine) -> PyResult<Duration> {
1338 use nix::sys::resource::{UsageWho, getrusage};
1339 fn from_timeval(tv: libc::timeval, vm: &VirtualMachine) -> PyResult<i64> {
1340 (|tv: libc::timeval| {
1341 let t = tv.tv_sec.checked_mul(SEC_TO_NS)?;
1342 let u = (tv.tv_usec as i64).checked_mul(US_TO_NS)?;
1343 t.checked_add(u)
1344 })(tv)
1345 .ok_or_else(|| vm.new_overflow_error("timestamp too large to convert to i64"))
1346 }
1347 let ru = getrusage(UsageWho::RUSAGE_SELF).map_err(|e| e.into_pyexception(vm))?;
1348 let utime = from_timeval(ru.user_time().into(), vm)?;
1349 let stime = from_timeval(ru.system_time().into(), vm)?;

Callers 1

get_process_timeFunction · 0.85

Calls 1

ok_or_elseMethod · 0.80

Tested by

no test coverage detected