@@ -227,6 +227,11 @@ impl Profile {
227227 Profile :: Clippy => "clippy" ,
228228 }
229229 }
230+
231+ /// Set of default profiles that should be benchmarked for a master/try artifact.
232+ pub fn default_profiles ( ) -> Vec < Self > {
233+ vec ! [ Profile :: Check , Profile :: Debug , Profile :: Doc , Profile :: Opt ]
234+ }
230235}
231236
232237impl std:: str:: FromStr for Profile {
@@ -365,6 +370,10 @@ impl Target {
365370 Target :: X86_64UnknownLinuxGnu => "x86_64-unknown-linux-gnu" ,
366371 }
367372 }
373+
374+ pub fn all ( ) -> Vec < Self > {
375+ vec ! [ Self :: X86_64UnknownLinuxGnu ]
376+ }
368377}
369378
370379impl FromStr for Target {
@@ -988,6 +997,35 @@ impl BenchmarkRequest {
988997 pub fn is_release ( & self ) -> bool {
989998 matches ! ( self . commit_type, BenchmarkRequestType :: Release { .. } )
990999 }
1000+
1001+ /// Get the codegen backends for the request
1002+ pub fn backends ( & self ) -> anyhow:: Result < Vec < CodegenBackend > > {
1003+ // Empty string; default to LLVM.
1004+ if self . backends . trim ( ) . is_empty ( ) {
1005+ return Ok ( vec ! [ CodegenBackend :: Llvm ] ) ;
1006+ }
1007+
1008+ self . backends
1009+ . split ( ',' )
1010+ . map ( |s| {
1011+ CodegenBackend :: from_str ( s) . map_err ( |_| anyhow:: anyhow!( "Invalid backend: {s}" ) )
1012+ } )
1013+ . collect ( )
1014+ }
1015+
1016+ /// Get the profiles for the request
1017+ pub fn profiles ( & self ) -> anyhow:: Result < Vec < Profile > > {
1018+ // No profile string; fall back to the library defaults.
1019+ if self . profiles . trim ( ) . is_empty ( ) {
1020+ return Ok ( Profile :: default_profiles ( ) ) ;
1021+ }
1022+
1023+ self . profiles
1024+ . split ( ',' )
1025+ . map ( Profile :: from_str)
1026+ . collect :: < Result < Vec < _ > , _ > > ( )
1027+ . map_err ( |e| anyhow:: anyhow!( "Invalid backend: {e}" ) )
1028+ }
9911029}
9921030
9931031/// Cached information about benchmark requests in the DB
@@ -1010,3 +1048,99 @@ impl BenchmarkRequestIndex {
10101048 & self . completed
10111049 }
10121050}
1051+
1052+ #[ derive( Debug , Clone , PartialEq ) ]
1053+ pub enum BenchmarkJobStatus {
1054+ Queued ,
1055+ InProgress ,
1056+ Success ,
1057+ Failure ,
1058+ }
1059+
1060+ const BENCHMARK_JOB_STATUS_QUEUED_STR : & str = "queued" ;
1061+ const BENCHMARK_JOB_STATUS_IN_PROGRESS_STR : & str = "in_progress" ;
1062+ const BENCHMARK_JOB_STATUS_SUCCESS_STR : & str = "success" ;
1063+ const BENCHMARK_JOB_STATUS_FAILURE_STR : & str = "failure" ;
1064+
1065+ impl BenchmarkJobStatus {
1066+ pub fn as_str ( & self ) -> & str {
1067+ match self {
1068+ BenchmarkJobStatus :: Queued => BENCHMARK_JOB_STATUS_QUEUED_STR ,
1069+ BenchmarkJobStatus :: InProgress => BENCHMARK_JOB_STATUS_IN_PROGRESS_STR ,
1070+ BenchmarkJobStatus :: Success => BENCHMARK_JOB_STATUS_SUCCESS_STR ,
1071+ BenchmarkJobStatus :: Failure => BENCHMARK_JOB_STATUS_FAILURE_STR ,
1072+ }
1073+ }
1074+ }
1075+
1076+ impl fmt:: Display for BenchmarkJobStatus {
1077+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1078+ write ! ( f, "{}" , self . as_str( ) )
1079+ }
1080+ }
1081+
1082+ #[ derive( Debug , Clone , PartialEq ) ]
1083+ pub struct BenchmarkSet ( u32 ) ;
1084+
1085+ #[ derive( Debug , Clone , PartialEq ) ]
1086+ pub struct BenchmarkJob {
1087+ target : Target ,
1088+ backend : CodegenBackend ,
1089+ profile : Profile ,
1090+ request_tag : String ,
1091+ benchmark_set : BenchmarkSet ,
1092+ created_at : DateTime < Utc > ,
1093+ started_at : Option < DateTime < Utc > > ,
1094+ completed_at : Option < DateTime < Utc > > ,
1095+ status : BenchmarkJobStatus ,
1096+ retry : u32 ,
1097+ }
1098+
1099+ impl BenchmarkJob {
1100+ pub fn new (
1101+ target : Target ,
1102+ backend : CodegenBackend ,
1103+ profile : Profile ,
1104+ request_tag : & str ,
1105+ benchmark_set : u32 ,
1106+ created_at : DateTime < Utc > ,
1107+ status : BenchmarkJobStatus ,
1108+ ) -> Self {
1109+ BenchmarkJob {
1110+ target,
1111+ backend,
1112+ profile,
1113+ request_tag : request_tag. to_string ( ) ,
1114+ benchmark_set : BenchmarkSet ( benchmark_set) ,
1115+ created_at,
1116+ started_at : None ,
1117+ completed_at : None ,
1118+ status,
1119+ retry : 0 ,
1120+ }
1121+ }
1122+
1123+ pub fn request_tag ( & self ) -> & str {
1124+ & self . request_tag
1125+ }
1126+
1127+ pub fn target ( & self ) -> Target {
1128+ self . target
1129+ }
1130+
1131+ pub fn backend ( & self ) -> CodegenBackend {
1132+ self . backend
1133+ }
1134+
1135+ pub fn profile ( & self ) -> Profile {
1136+ self . profile
1137+ }
1138+
1139+ pub fn benchmark_set ( & self ) -> u32 {
1140+ self . benchmark_set . 0
1141+ }
1142+
1143+ pub fn status ( & self ) -> & BenchmarkJobStatus {
1144+ & self . status
1145+ }
1146+ }
0 commit comments