(
mut runner_fifo: RunnerFifo,
ipc: MemtrackIpcServer,
child: &mut std::process::Child,
)
| 207 | |
| 208 | impl MemoryExecutor { |
| 209 | async fn handle_fifo( |
| 210 | mut runner_fifo: RunnerFifo, |
| 211 | ipc: MemtrackIpcServer, |
| 212 | child: &mut std::process::Child, |
| 213 | ) -> anyhow::Result<(ExecutionTimestamps, std::process::ExitStatus)> { |
| 214 | // Accept the IPC connection from memtrack and get the sender it sends us |
| 215 | // Use a timeout to prevent hanging if the process doesn't start properly |
| 216 | // https://github.com/servo/ipc-channel/issues/261 |
| 217 | let (_, memtrack_sender) = timeout(Duration::from_secs(5), async move { |
| 218 | tokio::task::spawn_blocking(move || ipc.accept()) |
| 219 | .await |
| 220 | .context("Failed to spawn blocking task")? |
| 221 | .context("Failed to accept IPC connection") |
| 222 | }) |
| 223 | .await |
| 224 | .context("Timeout waiting for IPC connection from memtrack process")??; |
| 225 | let ipc_client = Rc::new(MemtrackIpcClient::from_accepted(memtrack_sender)); |
| 226 | |
| 227 | let on_cmd = async move |cmd: &FifoCommand| { |
| 228 | const INVALID_INTEGRATION_ERROR: &str = "This integration doesn't support memory profiling. Please update your integration to a version that supports memory profiling."; |
| 229 | |
| 230 | match cmd { |
| 231 | FifoCommand::SetIntegration { name, version } => { |
| 232 | let min_version = match name.as_str() { |
| 233 | "codspeed-rust" => Version::new(4, 2, 0), |
| 234 | "codspeed-cpp" => Version::new(2, 1, 0), |
| 235 | "pytest-codspeed" => Version::new(4, 3, 0), |
| 236 | "codspeed-node" => Version::new(5, 2, 0), |
| 237 | "exec-harness" => Version::new(1, 0, 0), |
| 238 | _ => { |
| 239 | panic!("{INVALID_INTEGRATION_ERROR}") |
| 240 | } |
| 241 | }; |
| 242 | |
| 243 | let Ok(cur_version) = Version::parse(version) else { |
| 244 | panic!("Received invalid integration version"); |
| 245 | }; |
| 246 | |
| 247 | if cur_version < min_version { |
| 248 | panic!("{INVALID_INTEGRATION_ERROR}") |
| 249 | } |
| 250 | } |
| 251 | FifoCommand::SetVersion(protocol_version) => { |
| 252 | if *protocol_version < 2 { |
| 253 | bail!( |
| 254 | "Memory profiling requires protocol version 2 or higher, but the integration is using version {protocol_version}. \ |
| 255 | {INVALID_INTEGRATION_ERROR}", |
| 256 | ); |
| 257 | } |
| 258 | } |
| 259 | FifoCommand::StartProfiler => { |
| 260 | debug!("Enabling memtrack via IPC"); |
| 261 | if let Err(e) = ipc_client.enable() { |
| 262 | error!("Failed to enable memtrack: {e}"); |
| 263 | return Ok(Some(FifoCommand::Err)); |
| 264 | } |
| 265 | } |
| 266 | FifoCommand::StopProfiler => { |
nothing calls this directly
no test coverage detected