Skip to content

Commit 305e022

Browse files
committed
Auto merge of #45063 - michaelwoerister:bring-back-incremental-info, r=nikomatsakis
incr.comp.: Bring back output of -Zincremental-info. This got kind lost during the transition to red/green. I also switched back from `eprintln!()` to `println!()` since the former never actually produced any output. I suspect this has to do with `libterm` somehow monopolizing `stderr`. r? @nikomatsakis
2 parents d21c023 + b81c858 commit 305e022

File tree

7 files changed

+90
-25
lines changed

7 files changed

+90
-25
lines changed

src/bootstrap/bin/rustc.rs

-4
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,6 @@ fn main() {
129129
// Pass down incremental directory, if any.
130130
if let Ok(dir) = env::var("RUSTC_INCREMENTAL") {
131131
cmd.arg(format!("-Zincremental={}", dir));
132-
133-
if verbose > 0 {
134-
cmd.arg("-Zincremental-info");
135-
}
136132
}
137133

138134
let crate_name = args.windows(2)

src/librustc_incremental/persist/file_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn report_format_mismatch(sess: &Session, file: &Path, message: &str) {
117117
debug!("read_file: {}", message);
118118

119119
if sess.opts.debugging_opts.incremental_info {
120-
eprintln!("incremental: ignoring cache artifact `{}`: {}",
120+
println!("[incremental] ignoring cache artifact `{}`: {}",
121121
file.file_name().unwrap().to_string_lossy(),
122122
message);
123123
}

src/librustc_incremental/persist/fs.rs

+12-9
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,12 @@ pub fn prepare_session_directory(sess: &Session,
256256
debug!("attempting to copy data from source: {}",
257257
source_directory.display());
258258

259-
let print_file_copy_stats = sess.opts.debugging_opts.incremental_info;
259+
260260

261261
// Try copying over all files from the source directory
262-
if let Ok(allows_links) = copy_files(&session_dir, &source_directory,
263-
print_file_copy_stats) {
262+
if let Ok(allows_links) = copy_files(sess,
263+
&session_dir,
264+
&source_directory) {
264265
debug!("successfully copied data from: {}",
265266
source_directory.display());
266267

@@ -390,9 +391,9 @@ pub fn delete_all_session_dir_contents(sess: &Session) -> io::Result<()> {
390391
Ok(())
391392
}
392393

393-
fn copy_files(target_dir: &Path,
394-
source_dir: &Path,
395-
print_stats_on_success: bool)
394+
fn copy_files(sess: &Session,
395+
target_dir: &Path,
396+
source_dir: &Path)
396397
-> Result<bool, ()> {
397398
// We acquire a shared lock on the lock file of the directory, so that
398399
// nobody deletes it out from under us while we are reading from it.
@@ -440,9 +441,11 @@ fn copy_files(target_dir: &Path,
440441
}
441442
}
442443

443-
if print_stats_on_success {
444-
eprintln!("incremental: session directory: {} files hard-linked", files_linked);
445-
eprintln!("incremental: session directory: {} files copied", files_copied);
444+
if sess.opts.debugging_opts.incremental_info {
445+
println!("[incremental] session directory: \
446+
{} files hard-linked", files_linked);
447+
println!("[incremental] session directory: \
448+
{} files copied", files_copied);
446449
}
447450

448451
Ok(files_linked > 0 || files_copied == 0)

src/librustc_incremental/persist/load.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ pub fn load_dep_graph(sess: &Session) -> PreviousDepGraph {
177177

178178
if prev_commandline_args_hash != sess.opts.dep_tracking_hash() {
179179
if sess.opts.debugging_opts.incremental_info {
180-
eprintln!("incremental: completely ignoring cache because of \
181-
differing commandline arguments");
180+
println!("[incremental] completely ignoring cache because of \
181+
differing commandline arguments");
182182
}
183183
// We can't reuse the cache, purge it.
184184
debug!("load_dep_graph_new: differing commandline arg hashes");

src/librustc_incremental/persist/save.rs

+72-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
use rustc::dep_graph::DepGraph;
11+
use rustc::dep_graph::{DepGraph, DepKind};
1212
use rustc::hir::def_id::DefId;
1313
use rustc::hir::svh::Svh;
1414
use rustc::ich::Fingerprint;
@@ -170,6 +170,77 @@ fn encode_dep_graph(tcx: TyCtxt,
170170

171171
// Encode the graph data.
172172
let serialized_graph = tcx.dep_graph.serialize();
173+
174+
if tcx.sess.opts.debugging_opts.incremental_info {
175+
#[derive(Clone)]
176+
struct Stat {
177+
kind: DepKind,
178+
node_counter: u64,
179+
edge_counter: u64,
180+
}
181+
182+
let total_node_count = serialized_graph.nodes.len();
183+
let total_edge_count = serialized_graph.edge_list_data.len();
184+
185+
let mut counts: FxHashMap<_, Stat> = FxHashMap();
186+
187+
for (i, &(node, _)) in serialized_graph.nodes.iter_enumerated() {
188+
let stat = counts.entry(node.kind).or_insert(Stat {
189+
kind: node.kind,
190+
node_counter: 0,
191+
edge_counter: 0,
192+
});
193+
194+
stat.node_counter += 1;
195+
let (edge_start, edge_end) = serialized_graph.edge_list_indices[i];
196+
stat.edge_counter += (edge_end - edge_start) as u64;
197+
}
198+
199+
let mut counts: Vec<_> = counts.values().cloned().collect();
200+
counts.sort_by_key(|s| -(s.node_counter as i64));
201+
202+
let percentage_of_all_nodes: Vec<f64> = counts.iter().map(|s| {
203+
(100.0 * (s.node_counter as f64)) / (total_node_count as f64)
204+
}).collect();
205+
206+
let average_edges_per_kind: Vec<f64> = counts.iter().map(|s| {
207+
(s.edge_counter as f64) / (s.node_counter as f64)
208+
}).collect();
209+
210+
println!("[incremental]");
211+
println!("[incremental] DepGraph Statistics");
212+
213+
const SEPARATOR: &str = "[incremental] --------------------------------\
214+
----------------------------------------------\
215+
------------";
216+
217+
println!("{}", SEPARATOR);
218+
println!("[incremental]");
219+
println!("[incremental] Total Node Count: {}", total_node_count);
220+
println!("[incremental] Total Edge Count: {}", total_edge_count);
221+
println!("[incremental]");
222+
println!("[incremental] {:<36}| {:<17}| {:<12}| {:<17}|",
223+
"Node Kind",
224+
"Node Frequency",
225+
"Node Count",
226+
"Avg. Edge Count");
227+
println!("[incremental] -------------------------------------\
228+
|------------------\
229+
|-------------\
230+
|------------------|");
231+
232+
for (i, stat) in counts.iter().enumerate() {
233+
println!("[incremental] {:<36}|{:>16.1}% |{:>12} |{:>17.1} |",
234+
format!("{:?}", stat.kind),
235+
percentage_of_all_nodes[i],
236+
stat.node_counter,
237+
average_edges_per_kind[i]);
238+
}
239+
240+
println!("{}", SEPARATOR);
241+
println!("[incremental]");
242+
}
243+
173244
serialized_graph.encode(encoder)?;
174245

175246
Ok(())

src/librustc_trans/back/write.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -1079,13 +1079,9 @@ fn produce_final_output_artifacts(sess: &Session,
10791079
}
10801080

10811081
pub fn dump_incremental_data(trans: &CrateTranslation) {
1082-
let mut reuse = 0;
1083-
for mtrans in trans.modules.iter() {
1084-
if mtrans.pre_existing {
1085-
reuse += 1;
1086-
}
1087-
}
1088-
eprintln!("incremental: re-using {} out of {} modules", reuse, trans.modules.len());
1082+
println!("[incremental] Re-using {} out of {} modules",
1083+
trans.modules.iter().filter(|m| m.pre_existing).count(),
1084+
trans.modules.len());
10891085
}
10901086

10911087
enum WorkItem {

src/tools/compiletest/src/runtest.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,6 @@ actual:\n\
20282028
// Add an extra flag pointing at the incremental directory.
20292029
let mut revision_props = self.props.clone();
20302030
revision_props.incremental_dir = Some(incremental_dir);
2031-
revision_props.compile_flags.push(String::from("-Zincremental-info"));
20322031

20332032
let revision_cx = TestCx {
20342033
config: self.config,

0 commit comments

Comments
 (0)