|
| 1 | +use crate::selector::CompileTestCase; |
1 | 2 | use crate::{ |
2 | 3 | ArtifactCollection, ArtifactId, ArtifactIdNumber, CodegenBackend, CompileBenchmark, Target, |
3 | 4 | }; |
4 | 5 | use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step}; |
5 | 6 | use chrono::{DateTime, Utc}; |
6 | | -use hashbrown::HashMap; |
| 7 | +use hashbrown::{HashMap, HashSet}; |
7 | 8 | use std::sync::{Arc, Mutex}; |
8 | 9 | use std::time::Duration; |
9 | 10 | use tokio::sync::{OwnedSemaphorePermit, Semaphore}; |
@@ -178,6 +179,17 @@ pub trait Connection: Send + Sync { |
178 | 179 |
|
179 | 180 | /// Removes all data associated with the given artifact. |
180 | 181 | async fn purge_artifact(&self, aid: &ArtifactId); |
| 182 | + |
| 183 | + /// Returns a set of compile-time benchmark test cases that were already computed for the |
| 184 | + /// given artifact. |
| 185 | + /// Note that for efficiency reasons, the function only checks if we have at least a single |
| 186 | + /// result for a given test case. It does not check if *all* test results from all test |
| 187 | + /// iterations were finished. |
| 188 | + /// Therefore, the result is an over-approximation. |
| 189 | + async fn get_compile_test_cases_with_measurements( |
| 190 | + &self, |
| 191 | + artifact_row_id: &ArtifactIdNumber, |
| 192 | + ) -> anyhow::Result<HashSet<CompileTestCase>>; |
181 | 193 | } |
182 | 194 |
|
183 | 195 | #[async_trait::async_trait] |
@@ -297,11 +309,11 @@ impl Pool { |
297 | 309 |
|
298 | 310 | #[cfg(test)] |
299 | 311 | mod tests { |
300 | | - use chrono::Utc; |
301 | | - use std::str::FromStr; |
302 | | - |
303 | 312 | use super::*; |
| 313 | + use crate::metric::Metric; |
304 | 314 | use crate::{tests::run_db_test, Commit, CommitType, Date}; |
| 315 | + use chrono::Utc; |
| 316 | + use std::str::FromStr; |
305 | 317 |
|
306 | 318 | /// Create a Commit |
307 | 319 | fn create_commit(commit_sha: &str, time: chrono::DateTime<Utc>, r#type: CommitType) -> Commit { |
@@ -370,4 +382,64 @@ mod tests { |
370 | 382 | }) |
371 | 383 | .await; |
372 | 384 | } |
| 385 | + |
| 386 | + #[tokio::test] |
| 387 | + async fn get_compile_test_cases_with_data() { |
| 388 | + run_db_test(|ctx| async { |
| 389 | + let db = ctx.db_client().connection().await; |
| 390 | + |
| 391 | + let collection = db.collection_id("test").await; |
| 392 | + let artifact = db |
| 393 | + .artifact_id(&ArtifactId::Commit(create_commit( |
| 394 | + "abcdef", |
| 395 | + Utc::now(), |
| 396 | + CommitType::Try, |
| 397 | + ))) |
| 398 | + .await; |
| 399 | + db.record_compile_benchmark("benchmark", None, "primary".to_string()) |
| 400 | + .await; |
| 401 | + |
| 402 | + db.record_statistic( |
| 403 | + collection, |
| 404 | + artifact, |
| 405 | + "benchmark", |
| 406 | + Profile::Check, |
| 407 | + Scenario::IncrementalFresh, |
| 408 | + CodegenBackend::Llvm, |
| 409 | + Target::X86_64UnknownLinuxGnu, |
| 410 | + Metric::CacheMisses.as_str(), |
| 411 | + 1.0, |
| 412 | + ) |
| 413 | + .await; |
| 414 | + |
| 415 | + assert_eq!( |
| 416 | + db.get_compile_test_cases_with_measurements(&artifact) |
| 417 | + .await |
| 418 | + .unwrap(), |
| 419 | + HashSet::from([CompileTestCase { |
| 420 | + benchmark: "benchmark".into(), |
| 421 | + profile: Profile::Check, |
| 422 | + scenario: Scenario::IncrementalFresh, |
| 423 | + backend: CodegenBackend::Llvm, |
| 424 | + target: Target::X86_64UnknownLinuxGnu, |
| 425 | + }]) |
| 426 | + ); |
| 427 | + |
| 428 | + let artifact2 = db |
| 429 | + .artifact_id(&ArtifactId::Commit(create_commit( |
| 430 | + "abcdef2", |
| 431 | + Utc::now(), |
| 432 | + CommitType::Try, |
| 433 | + ))) |
| 434 | + .await; |
| 435 | + assert!(db |
| 436 | + .get_compile_test_cases_with_measurements(&artifact2) |
| 437 | + .await |
| 438 | + .unwrap() |
| 439 | + .is_empty()); |
| 440 | + |
| 441 | + Ok(ctx) |
| 442 | + }) |
| 443 | + .await; |
| 444 | + } |
373 | 445 | } |
0 commit comments