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