Skip to content

Commit d5a1bc4

Browse files
gebnerCopilot
andcommitted
Add --time-passes flag to show per-pass timing
Prints elapsed time for each pipeline phase to stderr: parse, prune, check, merge, restructure_goto, elab, and emit. Also shows declaration and module counts at each stage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent cf4ee1b commit d5a1bc4

1 file changed

Lines changed: 58 additions & 1 deletion

File tree

src/main.rs

Lines changed: 58 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::{path::Path, rc::Rc};
1+
use std::{path::Path, rc::Rc, time::Instant};
22

33
use crate::{
44
diag::{Diagnostic, Diagnostics},
@@ -28,6 +28,9 @@ struct Cli {
2828
#[arg(long = "print-ir")]
2929
print_ir: bool,
3030

31+
#[arg(long = "time-passes")]
32+
time_passes: bool,
33+
3134
#[arg(short = 'I')]
3235
include_paths: Vec<String>,
3336

@@ -103,6 +106,7 @@ fn main() {
103106
};
104107
let mut diags = Diagnostics::empty();
105108

109+
let parse_start = Instant::now();
106110
for file in &cli.files {
107111
let file_name = std::path::absolute(file)
108112
.unwrap()
@@ -121,22 +125,75 @@ fn main() {
121125
combined_tu.decls.extend(tu.decls);
122126
diags.merge(file_diags);
123127
}
128+
if cli.time_passes {
129+
eprintln!(
130+
" parse ({} files, {} decls): {:.3}s",
131+
cli.files.len(),
132+
combined_tu.decls.len(),
133+
parse_start.elapsed().as_secs_f64()
134+
);
135+
}
124136

125137
// Run passes
138+
let t = Instant::now();
126139
pass::prune::prune(&mut combined_tu);
140+
if cli.time_passes {
141+
eprintln!(
142+
" prune ({} decls): {:.3}s",
143+
combined_tu.decls.len(),
144+
t.elapsed().as_secs_f64()
145+
);
146+
}
147+
148+
let t = Instant::now();
127149
pass::check::check(&mut diags, &mut combined_tu, "prune", false);
150+
if cli.time_passes {
151+
eprintln!(" check (post-prune): {:.3}s", t.elapsed().as_secs_f64());
152+
}
153+
154+
let t = Instant::now();
128155
pass::merge::merge(&mut diags, &mut combined_tu);
156+
if cli.time_passes {
157+
eprintln!(
158+
" merge ({} decls): {:.3}s",
159+
combined_tu.decls.len(),
160+
t.elapsed().as_secs_f64()
161+
);
162+
}
163+
164+
let t = Instant::now();
129165
pass::restructure_goto::restructure_goto(&mut combined_tu);
166+
if cli.time_passes {
167+
eprintln!(" restructure_goto: {:.3}s", t.elapsed().as_secs_f64());
168+
}
169+
170+
let t = Instant::now();
130171
pass::elab::elab(&mut diags, &mut combined_tu);
172+
if cli.time_passes {
173+
eprintln!(" elab: {:.3}s", t.elapsed().as_secs_f64());
174+
}
175+
176+
let t = Instant::now();
131177
pass::check::check(&mut diags, &mut combined_tu, "elab", true);
178+
if cli.time_passes {
179+
eprintln!(" check (post-elab): {:.3}s", t.elapsed().as_secs_f64());
180+
}
132181

133182
if cli.print_ir {
134183
println!("{}", combined_tu);
135184
return;
136185
}
137186

138187
// Emit per-declaration modules
188+
let t = Instant::now();
139189
let modules = pass::emit::emit_multifile(&mut diags, &combined_tu);
190+
if cli.time_passes {
191+
eprintln!(
192+
" emit ({} modules): {:.3}s",
193+
modules.len(),
194+
t.elapsed().as_secs_f64()
195+
);
196+
}
140197

141198
let outdir = match &cli.outdir {
142199
Some(outdir) => Path::new(outdir).to_path_buf(),

0 commit comments

Comments
 (0)