Skip to content

Commit 3198e1a

Browse files
committed
Auto merge of #26883 - retep998:download-more-ram, r=alexcrichton
Extension of #26691 r? @alexcrichton
2 parents 16f64c3 + da5ab99 commit 3198e1a

File tree

1 file changed

+40
-5
lines changed

1 file changed

+40
-5
lines changed

src/librustc/util/common.rs

+40-5
Original file line numberDiff line numberDiff line change
@@ -76,19 +76,54 @@ pub fn time<T, U, F>(do_it: bool, what: &str, u: U, f: F) -> T where
7676
}
7777

7878
// Memory reporting
79+
#[cfg(unix)]
7980
fn get_resident() -> Option<usize> {
80-
if cfg!(unix) {
81-
get_proc_self_statm_field(1)
82-
} else {
83-
None
84-
}
81+
get_proc_self_statm_field(1)
82+
}
83+
84+
#[cfg(windows)]
85+
fn get_resident() -> Option<usize> {
86+
get_working_set_size()
8587
}
8688

8789
// Like std::macros::try!, but for Option<>.
8890
macro_rules! option_try(
8991
($e:expr) => (match $e { Some(e) => e, None => return None })
9092
);
9193

94+
#[cfg(windows)]
95+
fn get_working_set_size() -> Option<usize> {
96+
use libc::{BOOL, DWORD, HANDLE, SIZE_T, GetCurrentProcess};
97+
use std::mem;
98+
#[repr(C)] #[allow(non_snake_case)]
99+
struct PROCESS_MEMORY_COUNTERS {
100+
cb: DWORD,
101+
PageFaultCount: DWORD,
102+
PeakWorkingSetSize: SIZE_T,
103+
WorkingSetSize: SIZE_T,
104+
QuotaPeakPagedPoolUsage: SIZE_T,
105+
QuotaPagedPoolUsage: SIZE_T,
106+
QuotaPeakNonPagedPoolUsage: SIZE_T,
107+
QuotaNonPagedPoolUsage: SIZE_T,
108+
PagefileUsage: SIZE_T,
109+
PeakPagefileUsage: SIZE_T,
110+
}
111+
type PPROCESS_MEMORY_COUNTERS = *mut PROCESS_MEMORY_COUNTERS;
112+
#[link(name = "psapi")]
113+
extern "system" {
114+
fn GetProcessMemoryInfo(Process: HANDLE,
115+
ppsmemCounters: PPROCESS_MEMORY_COUNTERS,
116+
cb: DWORD) -> BOOL;
117+
}
118+
let mut pmc: PROCESS_MEMORY_COUNTERS = unsafe { mem::zeroed() };
119+
pmc.cb = mem::size_of_val(&pmc) as DWORD;
120+
match unsafe { GetProcessMemoryInfo(GetCurrentProcess(), &mut pmc, pmc.cb) } {
121+
0 => None,
122+
_ => Some(pmc.WorkingSetSize as usize),
123+
}
124+
}
125+
126+
#[cfg_attr(windows, allow(dead_code))]
92127
fn get_proc_self_statm_field(field: usize) -> Option<usize> {
93128
use std::fs::File;
94129
use std::io::Read;

0 commit comments

Comments
 (0)