@@ -713,6 +713,11 @@ enum Commands {
713
713
#[ arg( long) ]
714
714
git_sha : Option < String > ,
715
715
716
+ /// Periodically check if the collector's commit SHA matches the commit SHA of the
717
+ /// rustc-perf repository.
718
+ #[ arg( long) ]
719
+ check_git_sha : bool ,
720
+
716
721
#[ command( flatten) ]
717
722
db : DbOption ,
718
723
} ,
@@ -1360,6 +1365,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
1360
1365
Commands :: BenchmarkJobQueue {
1361
1366
collector_name,
1362
1367
git_sha,
1368
+ check_git_sha,
1363
1369
db,
1364
1370
} => {
1365
1371
log_db ( & db) ;
@@ -1368,7 +1374,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
1368
1374
Some ( sha) => sha,
1369
1375
None => {
1370
1376
let mut cmd = Command :: new ( "git" ) ;
1371
- cmd. args ( & [ "rev-parse" , "HEAD" ] ) ;
1377
+ cmd. args ( [ "rev-parse" , "HEAD" ] ) ;
1372
1378
let stdout = command_output ( & mut cmd)
1373
1379
. context ( "Cannot determine current commit SHA" ) ?
1374
1380
. stdout ;
@@ -1395,6 +1401,13 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
1395
1401
) ) ;
1396
1402
}
1397
1403
1404
+ log:: info!(
1405
+ "Starting collector with target {}, benchmark set {} and commit {}" ,
1406
+ collector_config. target( ) ,
1407
+ collector_config. benchmark_set( ) . get_id( ) ,
1408
+ collector_config. commit_sha( ) . expect( "missing commit SHA" )
1409
+ ) ;
1410
+
1398
1411
let benchmarks =
1399
1412
get_compile_benchmarks ( & compile_benchmark_dir, CompileBenchmarkFilter :: All ) ?;
1400
1413
@@ -1403,6 +1416,7 @@ Make sure to modify `{dir}/perf-config.json` if the category/artifact don't matc
1403
1416
conn,
1404
1417
& collector_config,
1405
1418
benchmarks,
1419
+ check_git_sha,
1406
1420
) ) ?;
1407
1421
1408
1422
Ok ( 0 )
@@ -1418,8 +1432,10 @@ async fn run_job_queue_benchmarks(
1418
1432
mut conn : Box < dyn Connection > ,
1419
1433
collector : & CollectorConfig ,
1420
1434
all_compile_benchmarks : Vec < Benchmark > ,
1435
+ check_git_sha : bool ,
1421
1436
) -> anyhow:: Result < ( ) > {
1422
- // TODO: check collector SHA vs site SHA
1437
+ let mut last_request_tag = None ;
1438
+
1423
1439
while let Some ( ( benchmark_job, artifact_id) ) = conn
1424
1440
. dequeue_benchmark_job (
1425
1441
collector. name ( ) ,
@@ -1428,6 +1444,22 @@ async fn run_job_queue_benchmarks(
1428
1444
)
1429
1445
. await ?
1430
1446
{
1447
+ // Here we check if we should update our commit SHA, if rustc-perf has been updated.
1448
+ // We only check for updates when we switch *benchmark requests*, not *benchmark jobs*,
1449
+ // to avoid changing code in the middle of benchmarking the same request.
1450
+ // Note that if an update happens, the job that we have just dequeued will have its deque
1451
+ // counter increased. But since updates are relatively rare, that shouldn't be a big deal,
1452
+ // it will be dequeued again when the collector starts again.
1453
+ if check_git_sha
1454
+ && last_request_tag. is_some ( )
1455
+ && last_request_tag. as_deref ( ) != Some ( benchmark_job. request_tag ( ) )
1456
+ && needs_git_update ( collector)
1457
+ {
1458
+ log:: warn!( "Exiting collector to update itself from git." ) ;
1459
+ return Ok ( ( ) ) ;
1460
+ }
1461
+ last_request_tag = Some ( benchmark_job. request_tag ( ) . to_string ( ) ) ;
1462
+
1431
1463
log:: info!( "Dequeued job {benchmark_job:?}, artifact_id {artifact_id:?}" ) ;
1432
1464
let result = run_benchmark_job (
1433
1465
conn. as_mut ( ) ,
@@ -1491,6 +1523,39 @@ async fn run_job_queue_benchmarks(
1491
1523
Ok ( ( ) )
1492
1524
}
1493
1525
1526
+ /// Returns true if the commit SHA of collector does not match the latest commit SHA of the master
1527
+ /// branch of https://github.com/rust-lang/rustc-perf.
1528
+ fn needs_git_update ( collector : & CollectorConfig ) -> bool {
1529
+ let Some ( commit_sha) = collector. commit_sha ( ) else {
1530
+ return false ;
1531
+ } ;
1532
+
1533
+ let mut cmd = Command :: new ( "git" ) ;
1534
+ cmd. arg ( "ls-remote" )
1535
+ . arg ( "https://github.com/rust-lang/rustc-perf" )
1536
+ . arg ( "HEAD" ) ;
1537
+ let upstream_sha = match command_output ( & mut cmd) {
1538
+ Ok ( output) => String :: from_utf8 ( output. stdout )
1539
+ . unwrap ( )
1540
+ . split_whitespace ( )
1541
+ . next ( )
1542
+ . unwrap ( )
1543
+ . to_string ( ) ,
1544
+ Err ( error) => {
1545
+ log:: error!( "Cannot determine latest SHA of rustc-perf: {error:?}" ) ;
1546
+ return false ;
1547
+ }
1548
+ } ;
1549
+ if commit_sha != upstream_sha {
1550
+ log:: warn!(
1551
+ "Commit {commit_sha} of collector is outdated, latest commit is {upstream_sha}."
1552
+ ) ;
1553
+ true
1554
+ } else {
1555
+ false
1556
+ }
1557
+ }
1558
+
1494
1559
/// Error that happened during benchmarking of a job.
1495
1560
enum BenchmarkJobError {
1496
1561
/// The error is non-recoverable.
0 commit comments