Skip to content

Commit c4075bf

Browse files
authored
Merge pull request #2352 from Jamesbarford/feat/allow-target-selection
Add `target` for GitHub commands
2 parents ba8021a + d1393fa commit c4075bf

File tree

8 files changed

+128
-53
lines changed

8 files changed

+128
-53
lines changed

database/schema.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ Columns:
268268
* `completed`: Completed request.
269269
* **backends** (`text NOT NULL`): Comma-separated list of codegen backends to benchmark. If empty, the default set of codegen backends will be benchmarked.
270270
* **profiles** (`text NOT NULL`): Comma-separated list of profiles to benchmark. If empty, the default set of profiles will be benchmarked.
271+
* **targets** (`text NOT NULL`): Comma-separated list of targets to benchmark. If empty, the default `x86_64-unknown-linux-gnu` will be benchmarked.
271272

272273
### collector_config
273274

database/src/lib.rs

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,14 @@ impl Target {
383383
pub fn all() -> Vec<Self> {
384384
vec![Self::X86_64UnknownLinuxGnu]
385385
}
386+
387+
pub fn default_targets() -> Vec<Self> {
388+
vec![Self::X86_64UnknownLinuxGnu]
389+
}
390+
391+
pub fn is_optional(self) -> bool {
392+
self != Target::X86_64UnknownLinuxGnu
393+
}
386394
}
387395

388396
impl FromStr for Target {
@@ -913,6 +921,7 @@ pub struct BenchmarkRequest {
913921
status: BenchmarkRequestStatus,
914922
backends: String,
915923
profiles: String,
924+
targets: String,
916925
}
917926

918927
impl BenchmarkRequest {
@@ -927,11 +936,17 @@ impl BenchmarkRequest {
927936
status: BenchmarkRequestStatus::ArtifactsReady,
928937
backends: String::new(),
929938
profiles: String::new(),
939+
targets: String::new(),
930940
}
931941
}
932942

933943
/// Create a try request that is in the `WaitingForArtifacts` status.
934-
pub fn create_try_without_artifacts(pr: u32, backends: &str, profiles: &str) -> Self {
944+
pub fn create_try_without_artifacts(
945+
pr: u32,
946+
backends: &str,
947+
profiles: &str,
948+
targets: &str,
949+
) -> Self {
935950
Self {
936951
commit_type: BenchmarkRequestType::Try {
937952
pr,
@@ -943,6 +958,7 @@ impl BenchmarkRequest {
943958
status: BenchmarkRequestStatus::WaitingForArtifacts,
944959
backends: backends.to_string(),
945960
profiles: profiles.to_string(),
961+
targets: targets.to_string(),
946962
}
947963
}
948964

@@ -959,6 +975,7 @@ impl BenchmarkRequest {
959975
status: BenchmarkRequestStatus::ArtifactsReady,
960976
backends: String::new(),
961977
profiles: String::new(),
978+
targets: String::new(),
962979
}
963980
}
964981

@@ -1037,6 +1054,15 @@ impl BenchmarkRequest {
10371054
parse_profiles(&self.profiles).map_err(|e| anyhow::anyhow!("{e}"))
10381055
}
10391056

1057+
/// Get the targets for the request
1058+
pub fn targets(&self) -> anyhow::Result<Vec<Target>> {
1059+
if self.targets.trim().is_empty() {
1060+
return Ok(Target::default_targets());
1061+
}
1062+
1063+
parse_targets(&self.targets).map_err(|e| anyhow::anyhow!("{e}"))
1064+
}
1065+
10401066
pub fn is_completed(&self) -> bool {
10411067
matches!(self.status, BenchmarkRequestStatus::Completed { .. })
10421068
}
@@ -1056,18 +1082,26 @@ pub enum BenchmarkRequestInsertResult {
10561082
NothingInserted,
10571083
}
10581084

1059-
pub fn parse_backends(backends: &str) -> Result<Vec<CodegenBackend>, String> {
1060-
backends
1085+
fn parse_comma_separated<T>(raw_string: &str, name: &str) -> Result<Vec<T>, String>
1086+
where
1087+
T: FromStr,
1088+
{
1089+
raw_string
10611090
.split(',')
1062-
.map(|s| CodegenBackend::from_str(s).map_err(|_| format!("Invalid backend: {s}")))
1091+
.map(|s| T::from_str(s).map_err(|_| format!("Invalid {name}: {s}")))
10631092
.collect()
10641093
}
10651094

1095+
pub fn parse_backends(backends: &str) -> Result<Vec<CodegenBackend>, String> {
1096+
parse_comma_separated(backends, "backend")
1097+
}
1098+
10661099
pub fn parse_profiles(profiles: &str) -> Result<Vec<Profile>, String> {
1067-
profiles
1068-
.split(',')
1069-
.map(|s| Profile::from_str(s).map_err(|_| format!("Invalid profile: {s}")))
1070-
.collect()
1100+
parse_comma_separated(profiles, "profile")
1101+
}
1102+
1103+
pub fn parse_targets(targets: &str) -> Result<Vec<Target>, String> {
1104+
parse_comma_separated(targets, "target")
10711105
}
10721106

10731107
/// Cached information about benchmark requests in the DB

database/src/pool.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,7 @@ mod tests {
576576
// But this should fail, as we can't have two queued requests at once
577577
let result = db
578578
.insert_benchmark_request(&BenchmarkRequest::create_try_without_artifacts(
579-
42, "", "",
579+
42, "", "", "",
580580
))
581581
.await
582582
.unwrap();
@@ -675,7 +675,7 @@ mod tests {
675675
run_postgres_test(|ctx| async {
676676
let db = ctx.db();
677677

678-
let req = BenchmarkRequest::create_try_without_artifacts(42, "", "");
678+
let req = BenchmarkRequest::create_try_without_artifacts(42, "", "", "");
679679

680680
db.insert_benchmark_request(&req).await.unwrap();
681681
assert!(db

database/src/pool/postgres.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ static MIGRATIONS: &[&str] = &[
441441
ALTER TABLE runtime_pstat_series ADD CONSTRAINT runtime_test_case UNIQUE(benchmark, target, metric);
442442
"#,
443443
r#"ALTER TABLE job_queue ADD COLUMN is_optional BOOLEAN NOT NULL DEFAULT FALSE"#,
444+
r#"ALTER TABLE benchmark_request ADD COLUMN targets TEXT NOT NULL DEFAULT ''"#,
444445
];
445446

446447
#[async_trait::async_trait]
@@ -801,7 +802,7 @@ impl PostgresConnection {
801802

802803
// `tag` should be kept as the first column
803804
const BENCHMARK_REQUEST_COLUMNS: &str =
804-
"tag, parent_sha, pr, commit_type, status, created_at, completed_at, backends, profiles, commit_date, duration_ms";
805+
"tag, parent_sha, pr, commit_type, status, created_at, completed_at, backends, profiles, commit_date, duration_ms, targets";
805806

806807
#[async_trait::async_trait]
807808
impl<P> Connection for P
@@ -2193,8 +2194,8 @@ where
21932194

21942195
for row in rows {
21952196
let tag = row.get::<_, &str>(0);
2196-
let error_benchmark = row.get::<_, Option<String>>(11);
2197-
let error_content = row.get::<_, Option<String>>(12);
2197+
let error_benchmark = row.get::<_, Option<String>>(12);
2198+
let error_content = row.get::<_, Option<String>>(13);
21982199

21992200
// We already saw this request, just add errors
22002201
if let Some(errors) = errors.get_mut(tag) {
@@ -2350,6 +2351,7 @@ fn row_to_benchmark_request(row: &Row, row_offset: Option<usize>) -> BenchmarkRe
23502351
let profiles = row.get::<_, String>(8 + row_offset);
23512352
let commit_date = row.get::<_, Option<DateTime<Utc>>>(9 + row_offset);
23522353
let duration_ms = row.get::<_, Option<i32>>(10 + row_offset);
2354+
let targets = row.get::<_, String>(11 + row_offset);
23532355

23542356
let pr = pr.map(|v| v as u32);
23552357

@@ -2371,6 +2373,7 @@ fn row_to_benchmark_request(row: &Row, row_offset: Option<usize>) -> BenchmarkRe
23712373
status,
23722374
backends,
23732375
profiles,
2376+
targets,
23742377
},
23752378
BENCHMARK_REQUEST_MASTER_STR => BenchmarkRequest {
23762379
commit_type: BenchmarkRequestType::Master {
@@ -2383,6 +2386,7 @@ fn row_to_benchmark_request(row: &Row, row_offset: Option<usize>) -> BenchmarkRe
23832386
status,
23842387
backends,
23852388
profiles,
2389+
targets,
23862390
},
23872391
BENCHMARK_REQUEST_RELEASE_STR => BenchmarkRequest {
23882392
commit_type: BenchmarkRequestType::Release {
@@ -2393,6 +2397,7 @@ fn row_to_benchmark_request(row: &Row, row_offset: Option<usize>) -> BenchmarkRe
23932397
status,
23942398
backends,
23952399
profiles,
2400+
targets,
23962401
},
23972402
_ => panic!("Invalid `commit_type` for `BenchmarkRequest` {commit_type}",),
23982403
}

database/src/tests/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ impl TestContext {
153153

154154
/// Create a new try benchmark request without artifacts and add it to the DB.
155155
pub async fn insert_try_request(&self, pr: u32) -> BenchmarkRequest {
156-
let req = BenchmarkRequest::create_try_without_artifacts(pr, "", "");
156+
let req = BenchmarkRequest::create_try_without_artifacts(pr, "", "", "");
157157
self.db().insert_benchmark_request(&req).await.unwrap();
158158
req
159159
}

site/frontend/templates/pages/help.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ <h3><b><code>@rust-timer</code> commands</b></h3>
5353
If you select a non-default profile, rustc-perf will also gather data for this profile for the
5454
parent/baseline commit, so that we have something to compare to.
5555
</li>
56+
<li><code>targets=&lt;TARGETS&gt;</code> configures which targets should be benchmarked.
57+
If no targets are provided <code>x86_64-unknown-linux-gnu</code> is the default.
58+
Please note presently the only valid option is <code>x86_64-unknown-linux-gnu</code>.
59+
</li>
5660
</ul>
5761
<p><code>@rust-timer build $commit</code> will queue a perf run for the given commit
5862
<code>$commit</code>.

site/src/job_queue/mod.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,7 @@ pub async fn enqueue_benchmark_request(
268268

269269
let backends = request.backends()?;
270270
let profiles = request.profiles()?;
271+
let targets = request.targets()?;
271272

272273
#[derive(PartialEq, Debug)]
273274
enum EnqueueMode {
@@ -327,12 +328,12 @@ pub async fn enqueue_benchmark_request(
327328
};
328329

329330
// Target x benchmark_set x backend x profile -> BenchmarkJob
330-
for target in Target::all() {
331+
for &target in targets.iter() {
331332
// We only have X86_64 at the moment and when we add other targets do
332333
// not want to block the Benchmark request from completing to wait on
333334
// other targets. Essentially, for the time being, other targets will
334335
// run in the background
335-
let is_optional = target != Target::X86_64UnknownLinuxGnu;
336+
let is_optional = target.is_optional();
336337

337338
for benchmark_set in 0..get_benchmark_sets_for_target(target.into()).len() {
338339
for &backend in backends.iter() {
@@ -629,7 +630,7 @@ mod tests {
629630
}
630631

631632
fn create_try(pr: u32) -> BenchmarkRequest {
632-
BenchmarkRequest::create_try_without_artifacts(pr, "", "")
633+
BenchmarkRequest::create_try_without_artifacts(pr, "", "", "")
633634
}
634635

635636
fn create_release(tag: &str) -> BenchmarkRequest {

0 commit comments

Comments
 (0)