22
33use rustc_data_structures:: sync:: Lock ;
44
5- use std:: cell:: Cell ;
65use std:: fmt:: Debug ;
76use std:: time:: { Duration , Instant } ;
87
9- use crate :: session:: Session ;
108use syntax:: symbol:: { sym, Symbol } ;
119
1210#[ cfg( test) ]
@@ -17,85 +15,6 @@ pub const FN_OUTPUT_NAME: Symbol = sym::Output;
1715
1816pub use errors:: ErrorReported ;
1917
20- thread_local ! ( static TIME_DEPTH : Cell <usize > = Cell :: new( 0 ) ) ;
21-
22- #[ allow( nonstandard_style) ]
23- #[ derive( Clone , Debug , PartialEq , Eq ) ]
24- pub struct QueryMsg {
25- pub query : & ' static str ,
26- pub msg : Option < String > ,
27- }
28-
29- /// Read the current depth of `time()` calls. This is used to
30- /// encourage indentation across threads.
31- pub fn time_depth ( ) -> usize {
32- TIME_DEPTH . with ( |slot| slot. get ( ) )
33- }
34-
35- /// Sets the current depth of `time()` calls. The idea is to call
36- /// `set_time_depth()` with the result from `time_depth()` in the
37- /// parent thread.
38- pub fn set_time_depth ( depth : usize ) {
39- TIME_DEPTH . with ( |slot| slot. set ( depth) ) ;
40- }
41-
42- pub fn time < T , F > ( sess : & Session , what : & str , f : F ) -> T
43- where
44- F : FnOnce ( ) -> T ,
45- {
46- time_ext ( sess. time_passes ( ) , what, f)
47- }
48-
49- pub fn time_ext < T , F > ( do_it : bool , what : & str , f : F ) -> T
50- where
51- F : FnOnce ( ) -> T ,
52- {
53- if !do_it {
54- return f ( ) ;
55- }
56-
57- let old = TIME_DEPTH . with ( |slot| {
58- let r = slot. get ( ) ;
59- slot. set ( r + 1 ) ;
60- r
61- } ) ;
62-
63- let start = Instant :: now ( ) ;
64- let rv = f ( ) ;
65- let dur = start. elapsed ( ) ;
66-
67- print_time_passes_entry ( true , what, dur) ;
68-
69- TIME_DEPTH . with ( |slot| slot. set ( old) ) ;
70-
71- rv
72- }
73-
74- pub fn print_time_passes_entry ( do_it : bool , what : & str , dur : Duration ) {
75- if !do_it {
76- return ;
77- }
78-
79- let indentation = TIME_DEPTH . with ( |slot| slot. get ( ) ) ;
80-
81- let mem_string = match get_resident ( ) {
82- Some ( n) => {
83- let mb = n as f64 / 1_000_000.0 ;
84- format ! ( "; rss: {}MB" , mb. round( ) as usize )
85- }
86- None => String :: new ( ) ,
87- } ;
88- println ! (
89- "{}time: {}{}\t {}" ,
90- " " . repeat( indentation) ,
91- duration_to_secs_str( dur) ,
92- mem_string,
93- what
94- ) ;
95- }
96-
97- pub use rustc_session:: utils:: duration_to_secs_str;
98-
9918pub fn to_readable_str ( mut val : usize ) -> String {
10019 let mut groups = vec ! [ ] ;
10120 loop {
@@ -128,58 +47,6 @@ where
12847 rv
12948}
13049
131- // Memory reporting
132- #[ cfg( unix) ]
133- fn get_resident ( ) -> Option < usize > {
134- use std:: fs;
135-
136- let field = 1 ;
137- let contents = fs:: read ( "/proc/self/statm" ) . ok ( ) ?;
138- let contents = String :: from_utf8 ( contents) . ok ( ) ?;
139- let s = contents. split_whitespace ( ) . nth ( field) ?;
140- let npages = s. parse :: < usize > ( ) . ok ( ) ?;
141- Some ( npages * 4096 )
142- }
143-
144- #[ cfg( windows) ]
145- fn get_resident ( ) -> Option < usize > {
146- type BOOL = i32 ;
147- type DWORD = u32 ;
148- type HANDLE = * mut u8 ;
149- use libc:: size_t;
150- use std:: mem;
151- #[ repr( C ) ]
152- #[ allow( non_snake_case) ]
153- struct PROCESS_MEMORY_COUNTERS {
154- cb : DWORD ,
155- PageFaultCount : DWORD ,
156- PeakWorkingSetSize : size_t ,
157- WorkingSetSize : size_t ,
158- QuotaPeakPagedPoolUsage : size_t ,
159- QuotaPagedPoolUsage : size_t ,
160- QuotaPeakNonPagedPoolUsage : size_t ,
161- QuotaNonPagedPoolUsage : size_t ,
162- PagefileUsage : size_t ,
163- PeakPagefileUsage : size_t ,
164- }
165- type PPROCESS_MEMORY_COUNTERS = * mut PROCESS_MEMORY_COUNTERS ;
166- #[ link( name = "psapi" ) ]
167- extern "system" {
168- fn GetCurrentProcess ( ) -> HANDLE ;
169- fn GetProcessMemoryInfo (
170- Process : HANDLE ,
171- ppsmemCounters : PPROCESS_MEMORY_COUNTERS ,
172- cb : DWORD ,
173- ) -> BOOL ;
174- }
175- let mut pmc: PROCESS_MEMORY_COUNTERS = unsafe { mem:: zeroed ( ) } ;
176- pmc. cb = mem:: size_of_val ( & pmc) as DWORD ;
177- match unsafe { GetProcessMemoryInfo ( GetCurrentProcess ( ) , & mut pmc, pmc. cb ) } {
178- 0 => None ,
179- _ => Some ( pmc. WorkingSetSize as usize ) ,
180- }
181- }
182-
18350pub fn indent < R , F > ( op : F ) -> R
18451where
18552 R : Debug ,
0 commit comments