about summary refs log tree commit diff
path: root/compiler/rustc_data_structures/src/profiling.rs
diff options
context:
space:
mode:
authorAndy Russell <arussell123@gmail.com>2023-01-15 13:43:15 -0500
committerAndy Russell <arussell123@gmail.com>2023-03-20 13:19:35 -0400
commitbb7c373fdf6c7c3fb8e204dcc178d870644fcc4b (patch)
tree32094fdb49a0bb37a86af2e10f3189c9070cf513 /compiler/rustc_data_structures/src/profiling.rs
parent13b7aa4d7faafbed78d195c27f6868f6bd90c2f8 (diff)
downloadrust-bb7c373fdf6c7c3fb8e204dcc178d870644fcc4b.tar.gz
rust-bb7c373fdf6c7c3fb8e204dcc178d870644fcc4b.zip
migrate compiler, bootstrap, and compiletest to windows-rs
Diffstat (limited to 'compiler/rustc_data_structures/src/profiling.rs')
-rw-r--r--compiler/rustc_data_structures/src/profiling.rs33
1 files changed, 19 insertions, 14 deletions
diff --git a/compiler/rustc_data_structures/src/profiling.rs b/compiler/rustc_data_structures/src/profiling.rs
index 44331683694..3d9c7f6eae2 100644
--- a/compiler/rustc_data_structures/src/profiling.rs
+++ b/compiler/rustc_data_structures/src/profiling.rs
@@ -796,21 +796,26 @@ fn get_thread_id() -> u32 {
 cfg_if! {
     if #[cfg(windows)] {
         pub fn get_resident_set_size() -> Option<usize> {
-            use std::mem::{self, MaybeUninit};
-            use winapi::shared::minwindef::DWORD;
-            use winapi::um::processthreadsapi::GetCurrentProcess;
-            use winapi::um::psapi::{GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS};
-
-            let mut pmc = MaybeUninit::<PROCESS_MEMORY_COUNTERS>::uninit();
-            match unsafe {
-                GetProcessMemoryInfo(GetCurrentProcess(), pmc.as_mut_ptr(), mem::size_of_val(&pmc) as DWORD)
-            } {
-                0 => None,
-                _ => {
-                    let pmc = unsafe { pmc.assume_init() };
-                    Some(pmc.WorkingSetSize as usize)
-                }
+            use std::mem;
+
+            use windows::{
+                Win32::System::ProcessStatus::{K32GetProcessMemoryInfo, PROCESS_MEMORY_COUNTERS},
+                Win32::System::Threading::GetCurrentProcess,
+            };
+
+            let mut pmc = PROCESS_MEMORY_COUNTERS::default();
+            let pmc_size = mem::size_of_val(&pmc);
+            unsafe {
+                K32GetProcessMemoryInfo(
+                    GetCurrentProcess(),
+                    &mut pmc,
+                    pmc_size as u32,
+                )
             }
+            .ok()
+            .ok()?;
+
+            Some(pmc.WorkingSetSize)
         }
     } else if #[cfg(target_os = "macos")] {
         pub fn get_resident_set_size() -> Option<usize> {