| 167 | } |
| 168 | |
| 169 | pub async fn stop(&mut self) -> Result<()> { |
| 170 | let response = Client::new() |
| 171 | .post(format!("{}/terminate", self.server_address)) |
| 172 | .send() |
| 173 | .await?; |
| 174 | if !response.status().is_success() { |
| 175 | bail!("Failed to terminate the MongoDB tracer"); |
| 176 | } |
| 177 | |
| 178 | if let Some(process) = self.process.as_mut() { |
| 179 | process |
| 180 | .kill() |
| 181 | .context("Failed to kill the MongoDB tracer")?; |
| 182 | } |
| 183 | |
| 184 | let instruments_out_dir = Path::new(&self.profile_folder).join("instruments"); |
| 185 | fs::create_dir_all(&instruments_out_dir).await?; |
| 186 | |
| 187 | let mongo_data = response.bytes().await?; |
| 188 | let mongo_data_path = instruments_out_dir.join("mongo.json"); |
| 189 | fs::write(mongo_data_path, mongo_data).await?; |
| 190 | |
| 191 | Ok(()) |
| 192 | } |
| 193 | |
| 194 | /// Applies the necessary transformations to the command to run the benchmark |
| 195 | /// TODO: move this to a `Instrument` trait, refactor and implement it for valgring as well |