| 140 | } |
| 141 | |
| 142 | async fn run( |
| 143 | &mut self, |
| 144 | execution_context: &ExecutionContext, |
| 145 | _mongo_tracer: &Option<MongoTracer>, |
| 146 | ) -> Result<()> { |
| 147 | // Create the results/ directory inside the profile folder to avoid having memtrack create it with wrong permissions |
| 148 | std::fs::create_dir_all(execution_context.profile_folder.join("results"))?; |
| 149 | |
| 150 | Self::ensure_privileges()?; |
| 151 | |
| 152 | let (ipc, cmd_builder, _env_file) = Self::build_memtrack_command(execution_context)?; |
| 153 | let cmd = cmd_builder.build(); |
| 154 | debug!("cmd: {cmd:?}"); |
| 155 | |
| 156 | let runner_fifo = RunnerFifo::new()?; |
| 157 | let on_process_started = |mut child: std::process::Child| async move { |
| 158 | let (marker_result, exit_status) = |
| 159 | Self::handle_fifo(runner_fifo, ipc, &mut child).await?; |
| 160 | |
| 161 | // Directly write to the profile folder, to avoid having to define another field |
| 162 | marker_result |
| 163 | .save_to(execution_context.profile_folder.join("results")) |
| 164 | .unwrap(); |
| 165 | |
| 166 | Ok(exit_status) |
| 167 | }; |
| 168 | |
| 169 | let status = run_command_with_log_pipe_and_callback(cmd, on_process_started).await?; |
| 170 | debug!("cmd exit status: {status:?}"); |
| 171 | |
| 172 | if !status.success() { |
| 173 | bail!("failed to execute memory tracker process: {status}"); |
| 174 | } |
| 175 | |
| 176 | Ok(()) |
| 177 | } |
| 178 | |
| 179 | async fn teardown(&self, execution_context: &ExecutionContext) -> Result<()> { |
| 180 | let results_dir = execution_context.profile_folder.join("results"); |