@@ -229,51 +229,65 @@ fn format_rusage_data() -> Option<String> {
229229
230230#[ cfg( windows) ]
231231fn format_rusage_data ( handle : std:: os:: windows:: raw:: HANDLE ) -> Option < String > {
232+ use winapi:: um:: { processthreadsapi, psapi, timezoneapi} ;
232233 macro_rules! try_bool {
233234 ( $e: expr) => {
234235 if $e != 1 {
235236 return None ;
236237 }
237238 } ;
238239 }
240+
241+ let mut user_filetime = Default :: default ( ) ;
242+ let mut user_time = Default :: default ( ) ;
243+ let mut kernel_filetime = Default :: default ( ) ;
244+ let mut kernel_time = Default :: default ( ) ;
245+ let mut memory_counters = psapi:: PROCESS_MEMORY_COUNTERS :: default ( ) ;
246+
239247 unsafe {
240- let mut _filetime = winapi:: shared:: minwindef:: FILETIME :: default ( ) ;
241- let mut user_filetime = winapi:: shared:: minwindef:: FILETIME :: default ( ) ;
242- let mut kernel_filetime = winapi:: shared:: minwindef:: FILETIME :: default ( ) ;
243- try_bool ! ( winapi:: um:: processthreadsapi:: GetProcessTimes (
248+ try_bool ! ( processthreadsapi:: GetProcessTimes (
244249 handle,
245- & mut _filetime ,
246- & mut _filetime ,
250+ & mut Default :: default ( ) ,
251+ & mut Default :: default ( ) ,
247252 & mut kernel_filetime,
248253 & mut user_filetime,
249254 ) ) ;
250- let mut memory_counters = winapi:: um:: psapi:: PROCESS_MEMORY_COUNTERS_EX :: default ( ) ;
251- try_bool ! ( winapi:: um:: psapi:: GetProcessMemoryInfo (
255+ try_bool ! ( timezoneapi:: FileTimeToSystemTime ( & user_filetime, & mut user_time) ) ;
256+ try_bool ! ( timezoneapi:: FileTimeToSystemTime ( & kernel_filetime, & mut kernel_time) ) ;
257+
258+ // Unlike on Linux with RUSAGE_CHILDREN, this will only return memory information for the process
259+ // with the given handle and none of that process's children.
260+ try_bool ! ( psapi:: GetProcessMemoryInfo (
252261 handle as _,
253262 & mut memory_counters as * mut _ as _,
254- std:: mem:: size_of:: <winapi:: um:: psapi:: PROCESS_MEMORY_COUNTERS_EX >( ) as u32 ,
255- ) ) ;
256- let mut user_time = winapi:: um:: minwinbase:: SYSTEMTIME :: default ( ) ;
257- try_bool ! ( winapi:: um:: timezoneapi:: FileTimeToSystemTime ( & user_filetime, & mut user_time) ) ;
258- let mut kernel_time = winapi:: um:: minwinbase:: SYSTEMTIME :: default ( ) ;
259- try_bool ! ( winapi:: um:: timezoneapi:: FileTimeToSystemTime (
260- & kernel_filetime,
261- & mut kernel_time
263+ std:: mem:: size_of:: <psapi:: PROCESS_MEMORY_COUNTERS_EX >( ) as u32 ,
262264 ) ) ;
263- let maxrss = memory_counters. PeakWorkingSetSize / 1024 ;
264- Some ( format ! (
265- "user: {USER_SEC}.{USER_USEC:03} \
265+ }
266+
267+ // Guide on interpreting these numbers:
268+ // https://docs.microsoft.com/en-us/windows/win32/psapi/process-memory-usage-information
269+ let peak_working_set = memory_counters. PeakWorkingSetSize / 1024 ;
270+ let peak_page_file = memory_counters. PeakPagefileUsage / 1024 ;
271+ let peak_paged_pool = memory_counters. QuotaPeakPagedPoolUsage / 1024 ;
272+ let peak_nonpaged_pool = memory_counters. QuotaPeakNonPagedPoolUsage / 1024 ;
273+ Some ( format ! (
274+ "user: {USER_SEC}.{USER_USEC:03} \
266275 sys: {SYS_SEC}.{SYS_USEC:03} \
267- max rss (kb): {MAXRSS} \
276+ peak working set (kb): {PEAK_WORKING_SET} \
277+ peak page file usage (kb): {PEAK_PAGE_FILE} \
278+ peak paged pool usage (kb): {PEAK_PAGED_POOL} \
279+ peak non-paged pool usage (kb): {PEAK_NONPAGED_POOL} \
268280 page faults: {PAGE_FAULTS}",
269- USER_SEC = user_time. wSecond + ( user_time. wMinute * 60 ) ,
270- USER_USEC = user_time. wMilliseconds,
271- SYS_SEC = kernel_time. wSecond + ( kernel_time. wMinute * 60 ) ,
272- SYS_USEC = kernel_time. wMilliseconds,
273- MAXRSS = maxrss,
274- PAGE_FAULTS = memory_counters. PageFaultCount ,
275- ) )
276- }
281+ USER_SEC = user_time. wSecond + ( user_time. wMinute * 60 ) ,
282+ USER_USEC = user_time. wMilliseconds,
283+ SYS_SEC = kernel_time. wSecond + ( kernel_time. wMinute * 60 ) ,
284+ SYS_USEC = kernel_time. wMilliseconds,
285+ PEAK_WORKING_SET = peak_working_set,
286+ PEAK_PAGE_FILE = peak_page_file,
287+ PEAK_PAGED_POOL = peak_paged_pool,
288+ PEAK_NONPAGED_POOL = peak_nonpaged_pool,
289+ PAGE_FAULTS = memory_counters. PageFaultCount ,
290+ ) )
277291}
278292
279293#[ cfg( unix) ]
0 commit comments