@@ -38,7 +38,8 @@ use rustc::session::{early_error, early_warn};
38
38
use rustc:: lint:: Lint ;
39
39
use rustc:: lint;
40
40
use rustc:: hir:: def_id:: LOCAL_CRATE ;
41
- use rustc:: util:: common:: { time, ErrorReported , install_panic_hook} ;
41
+ use rustc:: util:: common:: { ErrorReported , install_panic_hook, print_time_passes_entry} ;
42
+ use rustc:: util:: common:: { set_time_depth, time} ;
42
43
use rustc_metadata:: locator;
43
44
use rustc_metadata:: cstore:: CStore ;
44
45
use rustc_codegen_utils:: codegen_backend:: CodegenBackend ;
@@ -54,11 +55,12 @@ use std::default::Default;
54
55
use std:: env;
55
56
use std:: ffi:: OsString ;
56
57
use std:: io:: { self , Read , Write } ;
58
+ use std:: mem;
57
59
use std:: panic:: { self , catch_unwind} ;
58
60
use std:: path:: PathBuf ;
59
61
use std:: process:: { self , Command , Stdio } ;
60
62
use std:: str;
61
- use std:: mem ;
63
+ use std:: time :: Instant ;
62
64
63
65
use syntax:: ast;
64
66
use syntax:: source_map:: FileLoader ;
@@ -72,7 +74,7 @@ pub mod pretty;
72
74
/// Exit status code used for successful compilation and help output.
73
75
pub const EXIT_SUCCESS : i32 = 0 ;
74
76
75
- /// Exit status code used for compilation failures and invalid flags.
77
+ /// Exit status code used for compilation failures and invalid flags.
76
78
pub const EXIT_FAILURE : i32 = 1 ;
77
79
78
80
const BUG_REPORT_URL : & str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
@@ -118,6 +120,18 @@ pub struct DefaultCallbacks;
118
120
119
121
impl Callbacks for DefaultCallbacks { }
120
122
123
+ #[ derive( Default ) ]
124
+ pub struct TimePassesCallbacks {
125
+ time_passes : bool ,
126
+ }
127
+
128
+ impl Callbacks for TimePassesCallbacks {
129
+ fn config ( & mut self , config : & mut interface:: Config ) {
130
+ self . time_passes =
131
+ config. opts . debugging_opts . time_passes || config. opts . debugging_opts . time ;
132
+ }
133
+ }
134
+
121
135
// Parse args and run the compiler. This is the primary entry point for rustc.
122
136
// See comments on CompilerCalls below for details about the callbacks argument.
123
137
// The FileLoader provides a way to load files from sources other than the file system.
@@ -1169,18 +1183,24 @@ pub fn init_rustc_env_logger() {
1169
1183
}
1170
1184
1171
1185
pub fn main ( ) {
1186
+ let start = Instant :: now ( ) ;
1172
1187
init_rustc_env_logger ( ) ;
1188
+ let mut callbacks = TimePassesCallbacks :: default ( ) ;
1173
1189
let result = report_ices_to_stderr_if_any ( || {
1174
1190
let args = env:: args_os ( ) . enumerate ( )
1175
1191
. map ( |( i, arg) | arg. into_string ( ) . unwrap_or_else ( |arg| {
1176
1192
early_error ( ErrorOutputType :: default ( ) ,
1177
1193
& format ! ( "Argument {} is not valid Unicode: {:?}" , i, arg) )
1178
1194
} ) )
1179
1195
. collect :: < Vec < _ > > ( ) ;
1180
- run_compiler ( & args, & mut DefaultCallbacks , None , None )
1196
+ run_compiler ( & args, & mut callbacks , None , None )
1181
1197
} ) . and_then ( |result| result) ;
1182
- process :: exit ( match result {
1198
+ let exit_code = match result {
1183
1199
Ok ( _) => EXIT_SUCCESS ,
1184
1200
Err ( _) => EXIT_FAILURE ,
1185
- } ) ;
1201
+ } ;
1202
+ // The extra `\t` is necessary to align this label with the others.
1203
+ set_time_depth ( 0 ) ;
1204
+ print_time_passes_entry ( callbacks. time_passes , "\t total" , start. elapsed ( ) ) ;
1205
+ process:: exit ( exit_code) ;
1186
1206
}
0 commit comments