|
| 1 | +use crate::selector::CompileTestCase; |
1 | 2 | use crate::{ |
2 | 3 | ArtifactCollection, ArtifactId, ArtifactIdNumber, BenchmarkRequest, BenchmarkRequestIndex, |
3 | 4 | BenchmarkRequestStatus, CodegenBackend, 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}; |
@@ -220,6 +221,17 @@ pub trait Connection: Send + Sync { |
220 | 221 | profile: &Profile, |
221 | 222 | benchmark_set: u32, |
222 | 223 | ) -> anyhow::Result<()>; |
| 224 | + |
| 225 | + /// Returns a set of compile-time benchmark test cases that were already computed for the |
| 226 | + /// given artifact. |
| 227 | + /// Note that for efficiency reasons, the function only checks if we have at least a single |
| 228 | + /// result for a given test case. It does not check if *all* test results from all test |
| 229 | + /// iterations were finished. |
| 230 | + /// Therefore, the result is an over-approximation. |
| 231 | + async fn get_compile_test_cases_with_measurements( |
| 232 | + &self, |
| 233 | + artifact_row_id: &ArtifactIdNumber, |
| 234 | + ) -> anyhow::Result<HashSet<CompileTestCase>>; |
223 | 235 | } |
224 | 236 |
|
225 | 237 | #[async_trait::async_trait] |
@@ -339,6 +351,9 @@ impl Pool { |
339 | 351 |
|
340 | 352 | #[cfg(test)] |
341 | 353 | mod tests { |
| 354 | + use super::*; |
| 355 | + use crate::metric::Metric; |
| 356 | + use crate::{tests::run_db_test, Commit, CommitType, Date}; |
342 | 357 | use chrono::Utc; |
343 | 358 | use std::str::FromStr; |
344 | 359 |
|
@@ -625,4 +640,64 @@ mod tests { |
625 | 640 | }) |
626 | 641 | .await; |
627 | 642 | } |
| 643 | + |
| 644 | + #[tokio::test] |
| 645 | + async fn get_compile_test_cases_with_data() { |
| 646 | + run_db_test(|ctx| async { |
| 647 | + let db = ctx.db_client().connection().await; |
| 648 | + |
| 649 | + let collection = db.collection_id("test").await; |
| 650 | + let artifact = db |
| 651 | + .artifact_id(&ArtifactId::Commit(create_commit( |
| 652 | + "abcdef", |
| 653 | + Utc::now(), |
| 654 | + CommitType::Try, |
| 655 | + ))) |
| 656 | + .await; |
| 657 | + db.record_compile_benchmark("benchmark", None, "primary".to_string()) |
| 658 | + .await; |
| 659 | + |
| 660 | + db.record_statistic( |
| 661 | + collection, |
| 662 | + artifact, |
| 663 | + "benchmark", |
| 664 | + Profile::Check, |
| 665 | + Scenario::IncrementalFresh, |
| 666 | + CodegenBackend::Llvm, |
| 667 | + Target::X86_64UnknownLinuxGnu, |
| 668 | + Metric::CacheMisses.as_str(), |
| 669 | + 1.0, |
| 670 | + ) |
| 671 | + .await; |
| 672 | + |
| 673 | + assert_eq!( |
| 674 | + db.get_compile_test_cases_with_measurements(&artifact) |
| 675 | + .await |
| 676 | + .unwrap(), |
| 677 | + HashSet::from([CompileTestCase { |
| 678 | + benchmark: "benchmark".into(), |
| 679 | + profile: Profile::Check, |
| 680 | + scenario: Scenario::IncrementalFresh, |
| 681 | + backend: CodegenBackend::Llvm, |
| 682 | + target: Target::X86_64UnknownLinuxGnu, |
| 683 | + }]) |
| 684 | + ); |
| 685 | + |
| 686 | + let artifact2 = db |
| 687 | + .artifact_id(&ArtifactId::Commit(create_commit( |
| 688 | + "abcdef2", |
| 689 | + Utc::now(), |
| 690 | + CommitType::Try, |
| 691 | + ))) |
| 692 | + .await; |
| 693 | + assert!(db |
| 694 | + .get_compile_test_cases_with_measurements(&artifact2) |
| 695 | + .await |
| 696 | + .unwrap() |
| 697 | + .is_empty()); |
| 698 | + |
| 699 | + Ok(ctx) |
| 700 | + }) |
| 701 | + .await; |
| 702 | + } |
628 | 703 | } |
0 commit comments