Add a "total" measurement to -Ztime-passes.

This is useful for getting the total compilation time at the end.
To do this, the patch changes `print_time_passes_entry` to not increment
the depth, which means that `print_time_passes_entry_internal` is no
longer needed.
This commit is contained in:
Nicholas Nethercote 2019-06-25 13:52:07 +10:00
parent 90419d36bd
commit 87b103d4a9
4 changed files with 32 additions and 21 deletions

View File

@ -170,7 +170,7 @@ pub fn time_ext<T, F>(do_it: bool, sess: Option<&Session>, what: &str, f: F) ->
}
}
print_time_passes_entry_internal(what, dur);
print_time_passes_entry(true, what, dur);
TIME_DEPTH.with(|slot| slot.set(old));
@ -182,18 +182,6 @@ pub fn print_time_passes_entry(do_it: bool, what: &str, dur: Duration) {
return
}
let old = TIME_DEPTH.with(|slot| {
let r = slot.get();
slot.set(r + 1);
r
});
print_time_passes_entry_internal(what, dur);
TIME_DEPTH.with(|slot| slot.set(old));
}
fn print_time_passes_entry_internal(what: &str, dur: Duration) {
let indentation = TIME_DEPTH.with(|slot| slot.get());
let mem_string = match get_resident() {

View File

@ -1554,7 +1554,7 @@ fn start_executing_work<B: ExtraBackendMethods>(
let total_llvm_time = Instant::now().duration_since(llvm_start_time);
// This is the top-level timing for all of LLVM, set the time-depth
// to zero.
set_time_depth(0);
set_time_depth(1);
print_time_passes_entry(cgcx.time_passes,
"LLVM passes",
total_llvm_time);

View File

@ -25,7 +25,7 @@ use rustc::ty::{self, Ty, TyCtxt, Instance};
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, VariantIdx, HasTyCtxt};
use rustc::ty::query::Providers;
use rustc::middle::cstore::{self, LinkagePreference};
use rustc::util::common::{time, print_time_passes_entry};
use rustc::util::common::{time, print_time_passes_entry, set_time_depth, time_depth};
use rustc::session::config::{self, EntryFnType, Lto};
use rustc::session::Session;
use rustc::util::nodemap::FxHashMap;
@ -639,9 +639,12 @@ pub fn codegen_crate<B: ExtraBackendMethods>(
// Since the main thread is sometimes blocked during codegen, we keep track
// -Ztime-passes output manually.
let time_depth = time_depth();
set_time_depth(time_depth + 1);
print_time_passes_entry(tcx.sess.time_passes(),
"codegen to LLVM IR",
total_codegen_time);
set_time_depth(time_depth);
::rustc_incremental::assert_module_sources::assert_module_sources(tcx);

View File

@ -38,7 +38,8 @@ use rustc::session::{early_error, early_warn};
use rustc::lint::Lint;
use rustc::lint;
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::util::common::{time, ErrorReported, install_panic_hook};
use rustc::util::common::{ErrorReported, install_panic_hook, print_time_passes_entry};
use rustc::util::common::{set_time_depth, time};
use rustc_metadata::locator;
use rustc_metadata::cstore::CStore;
use rustc_codegen_utils::codegen_backend::CodegenBackend;
@ -54,11 +55,12 @@ use std::default::Default;
use std::env;
use std::ffi::OsString;
use std::io::{self, Read, Write};
use std::mem;
use std::panic::{self, catch_unwind};
use std::path::PathBuf;
use std::process::{self, Command, Stdio};
use std::str;
use std::mem;
use std::time::Instant;
use syntax::ast;
use syntax::source_map::FileLoader;
@ -72,7 +74,7 @@ pub mod pretty;
/// Exit status code used for successful compilation and help output.
pub const EXIT_SUCCESS: i32 = 0;
/// Exit status code used for compilation failures and invalid flags.
/// Exit status code used for compilation failures and invalid flags.
pub const EXIT_FAILURE: i32 = 1;
const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.\
@ -118,6 +120,18 @@ pub struct DefaultCallbacks;
impl Callbacks for DefaultCallbacks {}
#[derive(Default)]
pub struct TimePassesCallbacks {
time_passes: bool,
}
impl Callbacks for TimePassesCallbacks {
fn config(&mut self, config: &mut interface::Config) {
self.time_passes =
config.opts.debugging_opts.time_passes || config.opts.debugging_opts.time;
}
}
// Parse args and run the compiler. This is the primary entry point for rustc.
// See comments on CompilerCalls below for details about the callbacks argument.
// The FileLoader provides a way to load files from sources other than the file system.
@ -1169,7 +1183,9 @@ pub fn init_rustc_env_logger() {
}
pub fn main() {
let start = Instant::now();
init_rustc_env_logger();
let mut callbacks = TimePassesCallbacks::default();
let result = report_ices_to_stderr_if_any(|| {
let args = env::args_os().enumerate()
.map(|(i, arg)| arg.into_string().unwrap_or_else(|arg| {
@ -1177,10 +1193,14 @@ pub fn main() {
&format!("Argument {} is not valid Unicode: {:?}", i, arg))
}))
.collect::<Vec<_>>();
run_compiler(&args, &mut DefaultCallbacks, None, None)
run_compiler(&args, &mut callbacks, None, None)
}).and_then(|result| result);
process::exit(match result {
let exit_code = match result {
Ok(_) => EXIT_SUCCESS,
Err(_) => EXIT_FAILURE,
});
};
// The extra `\t` is necessary to align this label with the others.
set_time_depth(0);
print_time_passes_entry(callbacks.time_passes, "\ttotal", start.elapsed());
process::exit(exit_code);
}