@@ -8,6 +8,7 @@ use std::{
8
8
collections:: { HashMap , HashSet } ,
9
9
ffi:: { OsStr , OsString } ,
10
10
io:: Write ,
11
+ os:: unix:: process:: CommandExt ,
11
12
path:: { Path , PathBuf } ,
12
13
process:: Command ,
13
14
str:: FromStr ,
@@ -349,6 +350,9 @@ impl App {
349
350
Xtasks :: Install { binary } => {
350
351
cmd. arg ( "install" ) . arg ( binary. as_ref ( ) ) ;
351
352
}
353
+ Xtasks :: Bench { } => {
354
+ cmd. arg ( "bench" ) ;
355
+ }
352
356
}
353
357
354
358
cmd
@@ -634,6 +638,8 @@ enum Xtasks {
634
638
/// ]
635
639
///
636
640
CiMatrix ,
641
+ /// Runs bencher in dry mode by default if not on the main branch
642
+ Bench { } ,
637
643
}
638
644
639
645
#[ derive( Serialize , Clone ) ]
@@ -709,6 +715,7 @@ impl Xtasks {
709
715
bevy_features,
710
716
} => Self :: codegen ( app_settings, output_dir, bevy_features) ,
711
717
Xtasks :: Install { binary } => Self :: install ( app_settings, binary) ,
718
+ Xtasks :: Bench { } => Self :: bench ( app_settings) ,
712
719
} ?;
713
720
714
721
Ok ( "" . into ( ) )
@@ -1208,6 +1215,77 @@ impl Xtasks {
1208
1215
Ok ( ( ) )
1209
1216
}
1210
1217
1218
+ fn bench ( app_settings : GlobalArgs ) -> Result < ( ) > {
1219
+ // first of all figure out which branch we're on
1220
+ // run // git rev-parse --abbrev-ref HEAD
1221
+
1222
+ let command = Command :: new ( "git" )
1223
+ . args ( [ "rev-parse" , "--abbrev-ref" , "HEAD" ] )
1224
+ . current_dir ( Self :: workspace_dir ( & app_settings) . unwrap ( ) )
1225
+ . output ( )
1226
+ . with_context ( || "Trying to figure out which branch we're on in benchmarking" ) ?;
1227
+ let branch = String :: from_utf8 ( command. stdout ) ?;
1228
+
1229
+ let is_main = branch. trim ( ) == "main" ;
1230
+
1231
+ // figure out if we're running in github actions
1232
+ let github_token = std:: env:: var ( "GITHUB_TOKEN" ) . ok ( ) ;
1233
+
1234
+ // get testbed
1235
+ // we want this to be a combination of
1236
+ // is_github_ci?
1237
+ // OS
1238
+ // machine id
1239
+
1240
+ let os = std:: env:: consts:: OS ;
1241
+
1242
+ let testbed = format ! (
1243
+ "{os}{}" ,
1244
+ github_token. is_some( ) . then_some( "-gha" ) . unwrap_or_default( )
1245
+ ) ;
1246
+
1247
+ // also figure out if we're on a fork
1248
+
1249
+ let token = std:: env:: var ( "BENCHER_API_TOKEN" ) . ok ( ) ;
1250
+
1251
+ let mut bencher_cmd = Command :: new ( "bencher" ) ;
1252
+ bencher_cmd
1253
+ . stdout ( std:: process:: Stdio :: inherit ( ) )
1254
+ . stderr ( std:: process:: Stdio :: inherit ( ) )
1255
+ . current_dir ( Self :: workspace_dir ( & app_settings) . unwrap ( ) )
1256
+ . arg ( "run" )
1257
+ . args ( [ "--project" , "bms" ] )
1258
+ . args ( [ "--branch" , & format ! ( "\" {branch}\" " ) ] )
1259
+ . args ( [ "--token" , & token. unwrap_or_default ( ) ] )
1260
+ . args ( [ "--testbed" , & testbed] )
1261
+ . args ( [ "--build-time" ] )
1262
+ . args ( [ "--threshold-measure" , "latency" ] )
1263
+ . args ( [ "--threshold-test" , "t_test" ] )
1264
+ . args ( [ "--threshold-max-sample-size" , "64" ] )
1265
+ . args ( [ "--threshold-upper-boundary" , "0.99" ] )
1266
+ . args ( [ "--thresholds-reset" ] )
1267
+ . args ( [ "--err" ] ) ;
1268
+
1269
+ if let Some ( token) = github_token {
1270
+ bencher_cmd. args ( [ "--github-actions" , & token] ) ;
1271
+ }
1272
+
1273
+ if !is_main {
1274
+ bencher_cmd. args ( [ "--dry-run" ] ) ;
1275
+ }
1276
+
1277
+ bencher_cmd
1278
+ . args ( [ "--adapter" , "rust_criterion" ] )
1279
+ . arg ( "cargo bench --features=lua54" ) ;
1280
+
1281
+ let out = bencher_cmd. output ( ) ?;
1282
+ if !out. status . success ( ) {
1283
+ bail ! ( "Failed to run bencher: {:?}" , out) ;
1284
+ }
1285
+
1286
+ Ok ( ( ) )
1287
+ }
1288
+
1211
1289
fn set_cargo_coverage_settings ( ) {
1212
1290
// This makes local dev hell
1213
1291
// std::env::set_var("CARGO_INCREMENTAL", "0");
@@ -1369,6 +1447,13 @@ impl Xtasks {
1369
1447
} ,
1370
1448
} ) ;
1371
1449
1450
+ // also run a benchmark
1451
+ // on non-main branches this will just dry run
1452
+ output. push ( App {
1453
+ global_args : default_args. clone ( ) ,
1454
+ subcmd : Xtasks :: Bench { } ,
1455
+ } ) ;
1456
+
1372
1457
// and finally run tests with coverage
1373
1458
output. push ( App {
1374
1459
global_args : default_args
0 commit comments