|
| 1 | +use crate::selector::CompileTestCase; |
1 | 2 | use crate::{ |
2 | 3 | ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkRequest, CodegenBackend, |
3 | 4 | CompileBenchmark, Target, |
4 | 5 | }; |
5 | 6 | use crate::{CollectionId, Index, Profile, QueuedCommit, Scenario, Step}; |
6 | 7 | use chrono::{DateTime, Utc}; |
7 | | -use hashbrown::HashMap; |
| 8 | +use hashbrown::{HashMap, HashSet}; |
8 | 9 | use std::sync::{Arc, Mutex}; |
9 | 10 | use std::time::Duration; |
10 | 11 | use tokio::sync::{OwnedSemaphorePermit, Semaphore}; |
@@ -183,6 +184,17 @@ pub trait Connection: Send + Sync { |
183 | 184 | /// Add an item to the `benchmark_requests`, if the `benchmark_request` |
184 | 185 | /// exists it will be ignored |
185 | 186 | async fn insert_benchmark_request(&self, benchmark_request: &BenchmarkRequest); |
| 187 | + |
| 188 | + /// Returns a set of compile-time benchmark test cases that were already computed for the |
| 189 | + /// given artifact. |
| 190 | + /// Note that for efficiency reasons, the function only checks if we have at least a single |
| 191 | + /// result for a given test case. It does not check if *all* test results from all test |
| 192 | + /// iterations were finished. |
| 193 | + /// Therefore, the result is an over-approximation. |
| 194 | + async fn get_compile_test_cases_with_measurements( |
| 195 | + &self, |
| 196 | + artifact_row_id: &ArtifactIdNumber, |
| 197 | + ) -> anyhow::Result<HashSet<CompileTestCase>>; |
186 | 198 | } |
187 | 199 |
|
188 | 200 | #[async_trait::async_trait] |
@@ -302,6 +314,9 @@ impl Pool { |
302 | 314 |
|
303 | 315 | #[cfg(test)] |
304 | 316 | mod tests { |
| 317 | + use super::*; |
| 318 | + use crate::metric::Metric; |
| 319 | + use crate::{tests::run_db_test, Commit, CommitType, Date}; |
305 | 320 | use chrono::Utc; |
306 | 321 | use std::str::FromStr; |
307 | 322 |
|
@@ -424,4 +439,64 @@ mod tests { |
424 | 439 | }) |
425 | 440 | .await; |
426 | 441 | } |
| 442 | + |
| 443 | + #[tokio::test] |
| 444 | + async fn get_compile_test_cases_with_data() { |
| 445 | + run_db_test(|ctx| async { |
| 446 | + let db = ctx.db_client().connection().await; |
| 447 | + |
| 448 | + let collection = db.collection_id("test").await; |
| 449 | + let artifact = db |
| 450 | + .artifact_id(&ArtifactId::Commit(create_commit( |
| 451 | + "abcdef", |
| 452 | + Utc::now(), |
| 453 | + CommitType::Try, |
| 454 | + ))) |
| 455 | + .await; |
| 456 | + db.record_compile_benchmark("benchmark", None, "primary".to_string()) |
| 457 | + .await; |
| 458 | + |
| 459 | + db.record_statistic( |
| 460 | + collection, |
| 461 | + artifact, |
| 462 | + "benchmark", |
| 463 | + Profile::Check, |
| 464 | + Scenario::IncrementalFresh, |
| 465 | + CodegenBackend::Llvm, |
| 466 | + Target::X86_64UnknownLinuxGnu, |
| 467 | + Metric::CacheMisses.as_str(), |
| 468 | + 1.0, |
| 469 | + ) |
| 470 | + .await; |
| 471 | + |
| 472 | + assert_eq!( |
| 473 | + db.get_compile_test_cases_with_measurements(&artifact) |
| 474 | + .await |
| 475 | + .unwrap(), |
| 476 | + HashSet::from([CompileTestCase { |
| 477 | + benchmark: "benchmark".into(), |
| 478 | + profile: Profile::Check, |
| 479 | + scenario: Scenario::IncrementalFresh, |
| 480 | + backend: CodegenBackend::Llvm, |
| 481 | + target: Target::X86_64UnknownLinuxGnu, |
| 482 | + }]) |
| 483 | + ); |
| 484 | + |
| 485 | + let artifact2 = db |
| 486 | + .artifact_id(&ArtifactId::Commit(create_commit( |
| 487 | + "abcdef2", |
| 488 | + Utc::now(), |
| 489 | + CommitType::Try, |
| 490 | + ))) |
| 491 | + .await; |
| 492 | + assert!(db |
| 493 | + .get_compile_test_cases_with_measurements(&artifact2) |
| 494 | + .await |
| 495 | + .unwrap() |
| 496 | + .is_empty()); |
| 497 | + |
| 498 | + Ok(ctx) |
| 499 | + }) |
| 500 | + .await; |
| 501 | + } |
427 | 502 | } |
0 commit comments