@@ -156,9 +156,11 @@ fn main() {
156156 }
157157
158158 let start = Instant :: now ( ) ;
159- let status = {
159+ let ( child , status) = {
160160 let errmsg = format ! ( "\n Failed to run:\n {:?}\n -------------" , cmd) ;
161- cmd. status ( ) . expect ( & errmsg)
161+ let mut child = cmd. spawn ( ) . expect ( & errmsg) ;
162+ let status = child. wait ( ) . expect ( & errmsg) ;
163+ ( child, status)
162164 } ;
163165
164166 if env:: var_os ( "RUSTC_PRINT_STEP_TIMINGS" ) . is_some ( )
@@ -169,8 +171,19 @@ fn main() {
169171 let is_test = args. iter ( ) . any ( |a| a == "--test" ) ;
170172 // If the user requested resource usage data, then
171173 // include that in addition to the timing output.
172- let rusage_data =
173- env:: var_os ( "RUSTC_PRINT_STEP_RUSAGE" ) . and_then ( |_| format_rusage_data ( ) ) ;
174+ let rusage_data = env:: var_os ( "RUSTC_PRINT_STEP_RUSAGE" ) . and_then ( |_| {
175+ #[ cfg( windows) ]
176+ {
177+ use std:: os:: windows:: io:: AsRawHandle ;
178+ let handle = child. as_raw_handle ( ) ;
179+ format_rusage_data ( handle)
180+ }
181+ #[ cfg( not( windows) ) ]
182+ {
183+ let _child = child;
184+ format_rusage_data ( )
185+ }
186+ } ) ;
174187 eprintln ! (
175188 "[RUSTC-TIMING] {} test:{} {}.{:03}{}{}" ,
176189 crate_name,
@@ -207,13 +220,62 @@ fn main() {
207220 }
208221}
209222
210- #[ cfg( not( unix) ) ]
223+ #[ cfg( all ( not( unix) , not ( windows ) ) ) ]
211224/// getrusage is not available on non-unix platforms. So for now, we do not
212225/// bother trying to make a shim for it.
213226fn format_rusage_data ( ) -> Option < String > {
214227 None
215228}
216229
230+ #[ cfg( windows) ]
231+ fn format_rusage_data ( handle : std:: os:: windows:: raw:: HANDLE ) -> Option < String > {
232+ macro_rules! try_bool {
233+ ( $e: expr) => {
234+ if $e != 1 {
235+ return None ;
236+ }
237+ } ;
238+ }
239+ 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 (
244+ handle,
245+ & mut _filetime,
246+ & mut _filetime,
247+ & mut kernel_filetime,
248+ & mut user_filetime,
249+ ) ) ;
250+ let mut memory_counters = winapi:: um:: psapi:: PROCESS_MEMORY_COUNTERS_EX :: default ( ) ;
251+ try_bool ! ( winapi:: um:: psapi:: GetProcessMemoryInfo (
252+ handle as _,
253+ & 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
262+ ) ) ;
263+ let maxrss = memory_counters. PeakWorkingSetSize / 1024 ;
264+ Some ( format ! (
265+ "user: {USER_SEC}.{USER_USEC:03} \
266+ sys: {SYS_SEC}.{SYS_USEC:03} \
267+ max rss (kb): {MAXRSS} \
268+ 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+ }
277+ }
278+
217279#[ cfg( unix) ]
218280/// Tries to build a string with human readable data for several of the rusage
219281/// fields. Note that we are focusing mainly on data that we believe to be
0 commit comments