Skip to content

Commit efdcb43

Browse files
authored
Rollup merge of #82256 - eddyb:time-passes-stderr, r=varkor
Print -Ztime-passes (and misc stats/logs) on stderr, not stdout. I've tried not to change anything that looked similar to `rustc --print`, where people might use automation, and/or any "bulk" prints, such as dumping an entire Graphviz (`dot`) graph on stdout. The reason I want `-Ztime-passes` to be on stderr like debug logging is I can get a complete (and correctly interleaved) view just by looking at stderr, which is merely a convenience when running `rustc`/Cargo directly, but even more important when it's nested in a build script, as Cargo will split the build script output into stdout (named `output`) and `stderr`.
2 parents 555db2d + 6165d1c commit efdcb43

File tree

12 files changed

+64
-64
lines changed

12 files changed

+64
-64
lines changed

compiler/rustc_data_structures/src/profiling.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ pub fn print_time_passes_entry(
608608
(None, None) => String::new(),
609609
};
610610

611-
println!("time: {:>7}{}\t{}", duration_to_secs_str(dur), mem_string, what);
611+
eprintln!("time: {:>7}{}\t{}", duration_to_secs_str(dur), mem_string, what);
612612
}
613613

614614
// Hack up our own formatting for the duration to make it easier for scripts

compiler/rustc_incremental/src/persist/file_format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ fn report_format_mismatch(report_incremental_info: bool, file: &Path, message: &
109109
debug!("read_file: {}", message);
110110

111111
if report_incremental_info {
112-
println!(
112+
eprintln!(
113113
"[incremental] ignoring cache artifact `{}`: {}",
114114
file.file_name().unwrap().to_string_lossy(),
115115
message

compiler/rustc_incremental/src/persist/fs.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -440,12 +440,12 @@ fn copy_files(sess: &Session, target_dir: &Path, source_dir: &Path) -> Result<bo
440440
}
441441

442442
if sess.opts.debugging_opts.incremental_info {
443-
println!(
443+
eprintln!(
444444
"[incremental] session directory: \
445445
{} files hard-linked",
446446
files_linked
447447
);
448-
println!(
448+
eprintln!(
449449
"[incremental] session directory: \
450450
{} files copied",
451451
files_copied

compiler/rustc_incremental/src/persist/load.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
170170

171171
if prev_commandline_args_hash != expected_hash {
172172
if report_incremental_info {
173-
println!(
173+
eprintln!(
174174
"[incremental] completely ignoring cache because of \
175175
differing commandline arguments"
176176
);

compiler/rustc_interface/src/passes.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,8 @@ pub fn parse<'a>(sess: &'a Session, input: &Input) -> PResult<'a, ast::Crate> {
6464
}
6565

6666
if sess.opts.debugging_opts.input_stats {
67-
println!("Lines of code: {}", sess.source_map().count_lines());
68-
println!("Pre-expansion node count: {}", count_nodes(&krate));
67+
eprintln!("Lines of code: {}", sess.source_map().count_lines());
68+
eprintln!("Pre-expansion node count: {}", count_nodes(&krate));
6969
}
7070

7171
if let Some(ref s) = sess.opts.debugging_opts.show_span {
@@ -394,7 +394,7 @@ fn configure_and_expand_inner<'a>(
394394
// Done with macro expansion!
395395

396396
if sess.opts.debugging_opts.input_stats {
397-
println!("Post-expansion node count: {}", count_nodes(&krate));
397+
eprintln!("Post-expansion node count: {}", count_nodes(&krate));
398398
}
399399

400400
if sess.opts.debugging_opts.hir_stats {

compiler/rustc_metadata/src/rmeta/encoder.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -695,23 +695,23 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
695695
}
696696
}
697697

698-
println!("metadata stats:");
699-
println!(" dep bytes: {}", dep_bytes);
700-
println!(" lib feature bytes: {}", lib_feature_bytes);
701-
println!(" lang item bytes: {}", lang_item_bytes);
702-
println!(" diagnostic item bytes: {}", diagnostic_item_bytes);
703-
println!(" native bytes: {}", native_lib_bytes);
704-
println!(" source_map bytes: {}", source_map_bytes);
705-
println!(" impl bytes: {}", impl_bytes);
706-
println!(" exp. symbols bytes: {}", exported_symbols_bytes);
707-
println!(" def-path table bytes: {}", def_path_table_bytes);
708-
println!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
709-
println!(" mir bytes: {}", mir_bytes);
710-
println!(" item bytes: {}", item_bytes);
711-
println!(" table bytes: {}", tables_bytes);
712-
println!(" hygiene bytes: {}", hygiene_bytes);
713-
println!(" zero bytes: {}", zero_bytes);
714-
println!(" total bytes: {}", total_bytes);
698+
eprintln!("metadata stats:");
699+
eprintln!(" dep bytes: {}", dep_bytes);
700+
eprintln!(" lib feature bytes: {}", lib_feature_bytes);
701+
eprintln!(" lang item bytes: {}", lang_item_bytes);
702+
eprintln!(" diagnostic item bytes: {}", diagnostic_item_bytes);
703+
eprintln!(" native bytes: {}", native_lib_bytes);
704+
eprintln!(" source_map bytes: {}", source_map_bytes);
705+
eprintln!(" impl bytes: {}", impl_bytes);
706+
eprintln!(" exp. symbols bytes: {}", exported_symbols_bytes);
707+
eprintln!(" def-path table bytes: {}", def_path_table_bytes);
708+
eprintln!(" proc-macro-data-bytes: {}", proc_macro_data_bytes);
709+
eprintln!(" mir bytes: {}", mir_bytes);
710+
eprintln!(" item bytes: {}", item_bytes);
711+
eprintln!(" table bytes: {}", tables_bytes);
712+
eprintln!(" hygiene bytes: {}", hygiene_bytes);
713+
eprintln!(" zero bytes: {}", zero_bytes);
714+
eprintln!(" total bytes: {}", total_bytes);
715715
}
716716

717717
root

compiler/rustc_middle/src/ty/query/stats.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,29 @@ pub fn print_stats(tcx: TyCtxt<'_>) {
6767
if cfg!(debug_assertions) {
6868
let hits: usize = queries.iter().map(|s| s.cache_hits).sum();
6969
let results: usize = queries.iter().map(|s| s.entry_count).sum();
70-
println!("\nQuery cache hit rate: {}", hits as f64 / (hits + results) as f64);
70+
eprintln!("\nQuery cache hit rate: {}", hits as f64 / (hits + results) as f64);
7171
}
7272

7373
let mut query_key_sizes = queries.clone();
7474
query_key_sizes.sort_by_key(|q| q.key_size);
75-
println!("\nLarge query keys:");
75+
eprintln!("\nLarge query keys:");
7676
for q in query_key_sizes.iter().rev().filter(|q| q.key_size > 8) {
77-
println!(" {} - {} x {} - {}", q.name, q.key_size, q.entry_count, q.key_type);
77+
eprintln!(" {} - {} x {} - {}", q.name, q.key_size, q.entry_count, q.key_type);
7878
}
7979

8080
let mut query_value_sizes = queries.clone();
8181
query_value_sizes.sort_by_key(|q| q.value_size);
82-
println!("\nLarge query values:");
82+
eprintln!("\nLarge query values:");
8383
for q in query_value_sizes.iter().rev().filter(|q| q.value_size > 8) {
84-
println!(" {} - {} x {} - {}", q.name, q.value_size, q.entry_count, q.value_type);
84+
eprintln!(" {} - {} x {} - {}", q.name, q.value_size, q.entry_count, q.value_type);
8585
}
8686

8787
if cfg!(debug_assertions) {
8888
let mut query_cache_hits = queries.clone();
8989
query_cache_hits.sort_by_key(|q| q.cache_hits);
90-
println!("\nQuery cache hits:");
90+
eprintln!("\nQuery cache hits:");
9191
for q in query_cache_hits.iter().rev() {
92-
println!(
92+
eprintln!(
9393
" {} - {} ({}%)",
9494
q.name,
9595
q.cache_hits,
@@ -100,19 +100,19 @@ pub fn print_stats(tcx: TyCtxt<'_>) {
100100

101101
let mut query_value_count = queries.clone();
102102
query_value_count.sort_by_key(|q| q.entry_count);
103-
println!("\nQuery value count:");
103+
eprintln!("\nQuery value count:");
104104
for q in query_value_count.iter().rev() {
105-
println!(" {} - {}", q.name, q.entry_count);
105+
eprintln!(" {} - {}", q.name, q.entry_count);
106106
}
107107

108108
let mut def_id_density: Vec<_> =
109109
queries.iter().filter(|q| q.local_def_id_keys.is_some()).collect();
110110
def_id_density.sort_by_key(|q| q.local_def_id_keys.unwrap());
111-
println!("\nLocal DefId density:");
111+
eprintln!("\nLocal DefId density:");
112112
let total = tcx.hir().definitions().def_index_count() as f64;
113113
for q in def_id_density.iter().rev() {
114114
let local = q.local_def_id_keys.unwrap();
115-
println!(" {} - {} = ({}%)", q.name, local, (local as f64 * 100.0) / total);
115+
eprintln!(" {} - {} = ({}%)", q.name, local, (local as f64 * 100.0) / total);
116116
}
117117
}
118118

compiler/rustc_mir/src/transform/coverage/tests.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ macro_rules! assert_successors {
327327
fn test_covgraph_goto_switchint() {
328328
let mir_body = goto_switchint();
329329
if false {
330-
println!("basic_blocks = {}", debug_basic_blocks(&mir_body));
330+
eprintln!("basic_blocks = {}", debug_basic_blocks(&mir_body));
331331
}
332332
let basic_coverage_blocks = graph::CoverageGraph::from_mir(&mir_body);
333333
print_coverage_graphviz("covgraph_goto_switchint ", &mir_body, &basic_coverage_blocks);
@@ -583,11 +583,11 @@ fn test_find_loop_backedges_none() {
583583
let mir_body = goto_switchint();
584584
let basic_coverage_blocks = graph::CoverageGraph::from_mir(&mir_body);
585585
if false {
586-
println!(
586+
eprintln!(
587587
"basic_coverage_blocks = {:?}",
588588
basic_coverage_blocks.iter_enumerated().collect::<Vec<_>>()
589589
);
590-
println!("successors = {:?}", basic_coverage_blocks.successors);
590+
eprintln!("successors = {:?}", basic_coverage_blocks.successors);
591591
}
592592
let backedges = graph::find_loop_backedges(&basic_coverage_blocks);
593593
assert_eq!(

compiler/rustc_passes/src/hir_stats.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -66,13 +66,13 @@ impl<'k> StatCollector<'k> {
6666

6767
let mut total_size = 0;
6868

69-
println!("\n{}\n", title);
69+
eprintln!("\n{}\n", title);
7070

71-
println!("{:<18}{:>18}{:>14}{:>14}", "Name", "Accumulated Size", "Count", "Item Size");
72-
println!("----------------------------------------------------------------");
71+
eprintln!("{:<18}{:>18}{:>14}{:>14}", "Name", "Accumulated Size", "Count", "Item Size");
72+
eprintln!("----------------------------------------------------------------");
7373

7474
for (label, data) in stats {
75-
println!(
75+
eprintln!(
7676
"{:<18}{:>18}{:>14}{:>14}",
7777
label,
7878
to_readable_str(data.count * data.size),
@@ -82,8 +82,8 @@ impl<'k> StatCollector<'k> {
8282

8383
total_size += data.count * data.size;
8484
}
85-
println!("----------------------------------------------------------------");
86-
println!("{:<18}{:>18}\n", "Total", to_readable_str(total_size));
85+
eprintln!("----------------------------------------------------------------");
86+
eprintln!("{:<18}{:>18}\n", "Total", to_readable_str(total_size));
8787
}
8888
}
8989

compiler/rustc_query_system/src/dep_graph/graph.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -964,29 +964,29 @@ impl<K: DepKind> DepGraph<K> {
964964
----------------------------------------------\
965965
------------";
966966

967-
println!("[incremental]");
968-
println!("[incremental] DepGraph Statistics");
969-
println!("{}", SEPARATOR);
970-
println!("[incremental]");
971-
println!("[incremental] Total Node Count: {}", total_node_count);
972-
println!("[incremental] Total Edge Count: {}", total_edge_count);
967+
eprintln!("[incremental]");
968+
eprintln!("[incremental] DepGraph Statistics");
969+
eprintln!("{}", SEPARATOR);
970+
eprintln!("[incremental]");
971+
eprintln!("[incremental] Total Node Count: {}", total_node_count);
972+
eprintln!("[incremental] Total Edge Count: {}", total_edge_count);
973973

974974
if cfg!(debug_assertions) {
975975
let total_edge_reads = current.total_read_count.load(Relaxed);
976976
let total_duplicate_edge_reads = current.total_duplicate_read_count.load(Relaxed);
977977

978-
println!("[incremental] Total Edge Reads: {}", total_edge_reads);
979-
println!("[incremental] Total Duplicate Edge Reads: {}", total_duplicate_edge_reads);
978+
eprintln!("[incremental] Total Edge Reads: {}", total_edge_reads);
979+
eprintln!("[incremental] Total Duplicate Edge Reads: {}", total_duplicate_edge_reads);
980980
}
981981

982-
println!("[incremental]");
982+
eprintln!("[incremental]");
983983

984-
println!(
984+
eprintln!(
985985
"[incremental] {:<36}| {:<17}| {:<12}| {:<17}|",
986986
"Node Kind", "Node Frequency", "Node Count", "Avg. Edge Count"
987987
);
988988

989-
println!(
989+
eprintln!(
990990
"[incremental] -------------------------------------\
991991
|------------------\
992992
|-------------\
@@ -997,7 +997,7 @@ impl<K: DepKind> DepGraph<K> {
997997
let node_kind_ratio = (100.0 * (stat.node_counter as f64)) / (total_node_count as f64);
998998
let node_kind_avg_edges = (stat.edge_counter as f64) / (stat.node_counter as f64);
999999

1000-
println!(
1000+
eprintln!(
10011001
"[incremental] {:<36}|{:>16.1}% |{:>12} |{:>17.1} |",
10021002
format!("{:?}", stat.kind),
10031003
node_kind_ratio,
@@ -1006,8 +1006,8 @@ impl<K: DepKind> DepGraph<K> {
10061006
);
10071007
}
10081008

1009-
println!("{}", SEPARATOR);
1010-
println!("[incremental]");
1009+
eprintln!("{}", SEPARATOR);
1010+
eprintln!("[incremental]");
10111011
}
10121012

10131013
fn next_virtual_depnode_index(&self) -> DepNodeIndex {

compiler/rustc_session/src/session.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -959,19 +959,19 @@ impl Session {
959959
}
960960

961961
pub fn print_perf_stats(&self) {
962-
println!(
962+
eprintln!(
963963
"Total time spent computing symbol hashes: {}",
964964
duration_to_secs_str(*self.perf_stats.symbol_hash_time.lock())
965965
);
966-
println!(
966+
eprintln!(
967967
"Total queries canonicalized: {}",
968968
self.perf_stats.queries_canonicalized.load(Ordering::Relaxed)
969969
);
970-
println!(
970+
eprintln!(
971971
"normalize_generic_arg_after_erasing_regions: {}",
972972
self.perf_stats.normalize_generic_arg_after_erasing_regions.load(Ordering::Relaxed)
973973
);
974-
println!(
974+
eprintln!(
975975
"normalize_projection_ty: {}",
976976
self.perf_stats.normalize_projection_ty.load(Ordering::Relaxed)
977977
);

compiler/rustc_span/src/source_map/tests.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ impl SourceMapExtension for SourceMap {
243243
substring: &str,
244244
n: usize,
245245
) -> Span {
246-
println!(
246+
eprintln!(
247247
"span_substr(file={:?}/{:?}, substring={:?}, n={})",
248248
file.name, file.start_pos, substring, n
249249
);

0 commit comments

Comments
 (0)