Create a profile archive from the profile folder and return its md5 hash encoded in base64 For Valgrind, we create a gzip-compressed tar archive of the entire profile folder. For WallTime, we check the folder size and create either a compressed or uncompressed tar archive based on the MAX_UNCOMPRESSED_PROFILE_SIZE_BYTES threshold.
(
profile_folder: &std::path::Path,
executor_name: ExecutorName,
)
| 58 | /// For WallTime, we check the folder size and create either a compressed or uncompressed tar archive |
| 59 | /// based on the MAX_UNCOMPRESSED_PROFILE_SIZE_BYTES threshold. |
| 60 | async fn create_profile_archive( |
| 61 | profile_folder: &std::path::Path, |
| 62 | executor_name: ExecutorName, |
| 63 | ) -> Result<ProfileArchive> { |
| 64 | let time_start = std::time::Instant::now(); |
| 65 | let profile_archive = match executor_name { |
| 66 | ExecutorName::Valgrind => { |
| 67 | debug!("Creating compressed tar archive for Valgrind"); |
| 68 | let enc = GzipEncoder::new(Vec::new()); |
| 69 | let mut tar = Builder::new(enc); |
| 70 | tar.append_dir_all(".", profile_folder).await?; |
| 71 | let mut gzip_encoder = tar.into_inner().await?; |
| 72 | gzip_encoder.shutdown().await?; |
| 73 | let data = gzip_encoder.into_inner(); |
| 74 | ProfileArchive::new_compressed_in_memory(data) |
| 75 | } |
| 76 | ExecutorName::Memory | ExecutorName::WallTime => { |
| 77 | // Check folder size to decide on compression |
| 78 | let folder_size_bytes = calculate_folder_size(profile_folder).await?; |
| 79 | let should_compress = folder_size_bytes >= MAX_UNCOMPRESSED_PROFILE_SIZE_BYTES; |
| 80 | |
| 81 | let temp_file = tempfile::NamedTempFile::new()?; |
| 82 | let temp_path = temp_file.path().to_path_buf(); |
| 83 | |
| 84 | // Create a tokio File handle to the temporary file |
| 85 | let file = File::create(&temp_path).await?; |
| 86 | |
| 87 | // Persist the temporary file to prevent deletion when temp_file goes out of scope |
| 88 | let persistent_path = temp_file.into_temp_path().keep()?; |
| 89 | |
| 90 | if should_compress { |
| 91 | debug!( |
| 92 | "Profile folder size ({} MiB) exceeds threshold ({} MiB), creating compressed tar.gz archive on disk", |
| 93 | bytes_to_mib(folder_size_bytes), |
| 94 | bytes_to_mib(MAX_UNCOMPRESSED_PROFILE_SIZE_BYTES) |
| 95 | ); |
| 96 | let enc = GzipEncoder::new(file); |
| 97 | let mut tar = Builder::new(enc); |
| 98 | tar.append_dir_all(".", profile_folder).await?; |
| 99 | let mut gzip_encoder = tar.into_inner().await?; |
| 100 | gzip_encoder.shutdown().await?; |
| 101 | gzip_encoder.into_inner().sync_all().await?; |
| 102 | |
| 103 | ProfileArchive::new_compressed_on_disk(persistent_path)? |
| 104 | } else { |
| 105 | debug!( |
| 106 | "Profile folder size ({} MiB) is below threshold ({} MiB), creating uncompressed tar archive on disk", |
| 107 | bytes_to_mib(folder_size_bytes), |
| 108 | bytes_to_mib(MAX_UNCOMPRESSED_PROFILE_SIZE_BYTES) |
| 109 | ); |
| 110 | let mut tar = Builder::new(file); |
| 111 | tar.append_dir_all(".", profile_folder).await?; |
| 112 | tar.into_inner().await?.sync_all().await?; |
| 113 | |
| 114 | ProfileArchive::new_uncompressed_on_disk(persistent_path)? |
| 115 | } |
| 116 | } |
| 117 | }; |
no test coverage detected