diff options
| author | Rida Dzhaafar <38199959+rdzhaafar@users.noreply.github.com> | 2022-06-22 15:24:54 +0300 |
|---|---|---|
| committer | Rida Dzhaafar <38199959+rdzhaafar@users.noreply.github.com> | 2022-06-22 15:24:54 +0300 |
| commit | c41630735c00187d54ae30ff0a7a98c1d689b831 (patch) | |
| tree | ab88dff474af96e1bd5045195360c036d175841a /compiler/rustc_data_structures/src/profiling.rs | |
| parent | 89a0783f1c8fef46b1c8de57dc611a1d753bf0d5 (diff) | |
| download | rust-c41630735c00187d54ae30ff0a7a98c1d689b831.tar.gz rust-c41630735c00187d54ae30ff0a7a98c1d689b831.zip | |
Fixed RSS reporting on macOS
Diffstat (limited to 'compiler/rustc_data_structures/src/profiling.rs')
| -rw-r--r-- | compiler/rustc_data_structures/src/profiling.rs | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs index 88ff33b4d09..d8b26f9840b 100644 --- a/compiler/rustc_data_structures/src/profiling.rs +++ b/compiler/rustc_data_structures/src/profiling.rs @@ -826,6 +826,24 @@ cfg_if! { } } } + } else if #[cfg(target_os = "macos")] { + pub fn get_resident_set_size() -> Option<usize> { + use libc::{c_int, c_void, getpid, proc_pidinfo, proc_taskinfo, PROC_PIDTASKINFO}; + use std::mem; + const PROC_TASKINFO_SIZE: c_int = mem::size_of::<proc_taskinfo>() as c_int; + + unsafe { + let mut info: proc_taskinfo = mem::zeroed(); + let info_ptr = &mut info as *mut proc_taskinfo as *mut c_void; + let pid = getpid() as c_int; + let ret = proc_pidinfo(pid, PROC_PIDTASKINFO, 0, info_ptr, PROC_TASKINFO_SIZE); + if ret == PROC_TASKINFO_SIZE { + Some(info.pti_resident_size as usize) + } else { + None + } + } + } } else if #[cfg(unix)] { pub fn get_resident_set_size() -> Option<usize> { let field = 1; |
