(vm: &VirtualMachine)
| 1905 | #[cfg(all(any(unix, windows), not(target_os = "redox")))] |
| 1906 | #[pyfunction] |
| 1907 | fn times(vm: &VirtualMachine) -> PyResult { |
| 1908 | #[cfg(windows)] |
| 1909 | { |
| 1910 | use core::mem::MaybeUninit; |
| 1911 | use windows_sys::Win32::{Foundation::FILETIME, System::Threading}; |
| 1912 | |
| 1913 | let mut _create = MaybeUninit::<FILETIME>::uninit(); |
| 1914 | let mut _exit = MaybeUninit::<FILETIME>::uninit(); |
| 1915 | let mut kernel = MaybeUninit::<FILETIME>::uninit(); |
| 1916 | let mut user = MaybeUninit::<FILETIME>::uninit(); |
| 1917 | |
| 1918 | unsafe { |
| 1919 | let h_proc = Threading::GetCurrentProcess(); |
| 1920 | Threading::GetProcessTimes( |
| 1921 | h_proc, |
| 1922 | _create.as_mut_ptr(), |
| 1923 | _exit.as_mut_ptr(), |
| 1924 | kernel.as_mut_ptr(), |
| 1925 | user.as_mut_ptr(), |
| 1926 | ); |
| 1927 | } |
| 1928 | |
| 1929 | let kernel = unsafe { kernel.assume_init() }; |
| 1930 | let user = unsafe { user.assume_init() }; |
| 1931 | |
| 1932 | let times_result = TimesResultData { |
| 1933 | user: user.dwHighDateTime as f64 * 429.4967296 + user.dwLowDateTime as f64 * 1e-7, |
| 1934 | system: kernel.dwHighDateTime as f64 * 429.4967296 |
| 1935 | + kernel.dwLowDateTime as f64 * 1e-7, |
| 1936 | children_user: 0.0, |
| 1937 | children_system: 0.0, |
| 1938 | elapsed: 0.0, |
| 1939 | }; |
| 1940 | |
| 1941 | Ok(times_result.to_pyobject(vm)) |
| 1942 | } |
| 1943 | #[cfg(unix)] |
| 1944 | { |
| 1945 | let mut t = libc::tms { |
| 1946 | tms_utime: 0, |
| 1947 | tms_stime: 0, |
| 1948 | tms_cutime: 0, |
| 1949 | tms_cstime: 0, |
| 1950 | }; |
| 1951 | |
| 1952 | let tick_for_second = unsafe { libc::sysconf(libc::_SC_CLK_TCK) } as f64; |
| 1953 | let c = unsafe { libc::times(&mut t as *mut _) }; |
| 1954 | |
| 1955 | // XXX: The signedness of `clock_t` varies from platform to platform. |
| 1956 | if c == (-1i8) as libc::clock_t { |
| 1957 | return Err(vm.new_os_error("Fail to get times".to_string())); |
| 1958 | } |
| 1959 | |
| 1960 | let times_result = TimesResultData { |
| 1961 | user: t.tms_utime as f64 / tick_for_second, |
| 1962 | system: t.tms_stime as f64 / tick_for_second, |
| 1963 | children_user: t.tms_cutime as f64 / tick_for_second, |
| 1964 | children_system: t.tms_cstime as f64 / tick_for_second, |
no test coverage detected