Drive a single benchmark run through a [`Profiler`]: wrap the command, spawn it, dispatch FIFO commands from the integration into the profiler's hooks, and stash the run's outputs for [`Profiler::finalize`] in teardown.
(
profiler: &mut dyn Profiler,
cmd_builder: CommandBuilder,
config: &ExecutorConfig,
profile_folder: &Path,
isolate: bool,
benchmark_state: &OnceCell<(FifoBenchmarkData, Execut
| 258 | /// spawn it, dispatch FIFO commands from the integration into the profiler's |
| 259 | /// hooks, and stash the run's outputs for [`Profiler::finalize`] in teardown. |
| 260 | async fn run_with_profiler( |
| 261 | profiler: &mut dyn Profiler, |
| 262 | cmd_builder: CommandBuilder, |
| 263 | config: &ExecutorConfig, |
| 264 | profile_folder: &Path, |
| 265 | isolate: bool, |
| 266 | benchmark_state: &OnceCell<(FifoBenchmarkData, ExecutionTimestamps)>, |
| 267 | ) -> Result<std::process::ExitStatus> { |
| 268 | let wrapped = profiler |
| 269 | .wrap_command(cmd_builder, config, profile_folder, isolate) |
| 270 | .await?; |
| 271 | let cmd = wrapped.build(); |
| 272 | debug!("cmd: {cmd:?}"); |
| 273 | |
| 274 | let mut runner_fifo = RunnerFifo::new()?; |
| 275 | |
| 276 | run_command_with_log_pipe_and_callback(cmd, async move |mut child| { |
| 277 | let on_cmd = async |c: &FifoCommand| match c { |
| 278 | FifoCommand::StartProfiler => { |
| 279 | profiler.on_start_profiler().await?; |
| 280 | Ok(None) |
| 281 | } |
| 282 | FifoCommand::StopProfiler => { |
| 283 | profiler.on_stop_profiler().await?; |
| 284 | Ok(None) |
| 285 | } |
| 286 | #[allow(deprecated)] |
| 287 | FifoCommand::PingProfiler => Ok(Some(if profiler.on_ping().await? { |
| 288 | FifoCommand::Ack |
| 289 | } else { |
| 290 | FifoCommand::Err |
| 291 | })), |
| 292 | FifoCommand::GetIntegrationMode => Ok(Some(FifoCommand::IntegrationModeResponse( |
| 293 | IntegrationMode::Walltime, |
| 294 | ))), |
| 295 | _ => Ok(None), |
| 296 | }; |
| 297 | |
| 298 | let (timestamps, fifo_data, exit_status) = |
| 299 | runner_fifo.handle_fifo_messages(&mut child, on_cmd).await?; |
| 300 | |
| 301 | let _ = benchmark_state.set((fifo_data, timestamps)); |
| 302 | |
| 303 | Ok(exit_status) |
| 304 | }) |
| 305 | .await |
| 306 | } |
| 307 | |
| 308 | #[cfg(test)] |
| 309 | mod tests { |
no test coverage detected