Skip to content

Commit 35569ca

Browse files
committed
profiling command streams
1 parent 010f2eb commit 35569ca

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

src/bootstrap/src/core/build_steps/compile.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2551,7 +2551,7 @@ pub fn stream_cargo(
25512551
}
25522552

25532553
// Make sure Cargo actually succeeded after we read all of its stdout.
2554-
let status = t!(streaming_command.wait());
2554+
let status = t!(streaming_command.wait(&builder.config.exec_ctx));
25552555
if builder.is_verbose() && !status.success() {
25562556
eprintln!(
25572557
"command did not execute successfully: {cmd:?}\n\

src/bootstrap/src/utils/exec.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ impl CommandProfiler {
183183
.unwrap();
184184
}
185185

186-
// Add aggregated summary
187186
let total_bootstrap_time = start_time.elapsed();
188187
let overhead_time =
189188
total_bootstrap_time.checked_sub(total_execution_duration).unwrap_or(Duration::ZERO);
@@ -588,6 +587,8 @@ pub struct StreamingCommand {
588587
child: Child,
589588
pub stdout: Option<ChildStdout>,
590589
pub stderr: Option<ChildStderr>,
590+
cache_key: CommandFingerprint,
591+
start_time: Instant,
591592
}
592593

593594
#[must_use]
@@ -780,6 +781,8 @@ impl ExecutionContext {
780781
if !command.run_in_dry_run && self.dry_run() {
781782
return None;
782783
}
784+
let start_time = Instant::now();
785+
let cache_key = command.cache_key();
783786
let cmd = &mut command.command;
784787
cmd.stdout(stdout.stdio());
785788
cmd.stderr(stderr.stdio());
@@ -791,7 +794,7 @@ impl ExecutionContext {
791794

792795
let stdout = child.stdout.take();
793796
let stderr = child.stderr.take();
794-
Some(StreamingCommand { child, stdout, stderr })
797+
Some(StreamingCommand { child, stdout, stderr, cache_key, start_time })
795798
}
796799
}
797800

@@ -802,8 +805,14 @@ impl AsRef<ExecutionContext> for ExecutionContext {
802805
}
803806

804807
impl StreamingCommand {
805-
pub fn wait(mut self) -> Result<ExitStatus, std::io::Error> {
806-
self.child.wait()
808+
pub fn wait(
809+
mut self,
810+
exec_ctx: impl AsRef<ExecutionContext>,
811+
) -> Result<ExitStatus, std::io::Error> {
812+
let exec_ctx = exec_ctx.as_ref();
813+
let output = self.child.wait();
814+
exec_ctx.profiler().record_execution(self.cache_key, self.start_time);
815+
output
807816
}
808817
}
809818

src/bootstrap/src/utils/render_tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fn run_tests(builder: &Builder<'_>, cmd: &mut BootstrapCommand, stream: bool) ->
6363
renderer.render_all();
6464
}
6565

66-
let status = streaming_command.wait().unwrap();
66+
let status = streaming_command.wait(&builder.config.exec_ctx).unwrap();
6767
if !status.success() && builder.is_verbose() {
6868
println!(
6969
"\n\ncommand did not execute successfully: {cmd:?}\n\

0 commit comments

Comments
 (0)