1- use std:: env;
1+ use std:: { env, fmt :: Display } ;
22
33use crate :: prelude:: * ;
44
@@ -12,22 +12,51 @@ use anyhow::bail;
1212use executor:: Executor ;
1313use helpers:: profile_folder:: create_profile_folder;
1414pub use interfaces:: { ExecutorName , RunData } ;
15- use valgrind:: executor:: { ValgrindExecutor , INSTRUMENTATION_RUNNER_MODE } ;
16- use wall_time:: executor:: { WallTimeExecutor , WALL_TIME_RUNNER_MODE } ;
15+ use valgrind:: executor:: ValgrindExecutor ;
16+ use wall_time:: executor:: WallTimeExecutor ;
17+
18+ pub enum RunnerMode {
19+ Instrumentation ,
20+ WallTime ,
21+ }
22+
23+ impl Display for RunnerMode {
24+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
25+ match self {
26+ RunnerMode :: Instrumentation => write ! ( f, "instrumentation" ) ,
27+ RunnerMode :: WallTime => write ! ( f, "walltime" ) ,
28+ }
29+ }
30+ }
31+
32+ impl TryFrom < & str > for RunnerMode {
33+ type Error = anyhow:: Error ;
34+
35+ fn try_from ( value : & str ) -> Result < Self > {
36+ match value {
37+ "instrumentation" => Ok ( RunnerMode :: Instrumentation ) ,
38+ "walltime" => Ok ( RunnerMode :: WallTime ) ,
39+ _ => bail ! ( "Unknown runner mode: {}" , value) ,
40+ }
41+ }
42+ }
1743
1844pub const EXECUTOR_TARGET : & str = "executor" ;
1945
20- pub fn get_executor ( ) -> Result < Box < dyn Executor > > {
46+ pub fn get_mode ( ) -> Result < RunnerMode > {
2147 if let Ok ( runner_mode) = env:: var ( "CODSPEED_RUNNER_MODE" ) {
2248 debug ! ( "CODSPEED_RUNNER_MODE is set to {}" , runner_mode) ;
23- match runner_mode. as_str ( ) {
24- INSTRUMENTATION_RUNNER_MODE => Ok ( Box :: new ( ValgrindExecutor ) ) ,
25- WALL_TIME_RUNNER_MODE => Ok ( Box :: new ( WallTimeExecutor ) ) ,
26- _ => bail ! ( "Unknown codspeed runner mode" ) ,
27- }
49+ RunnerMode :: try_from ( runner_mode. as_str ( ) )
2850 } else {
29- debug ! ( "CODSPEED_RUNNER_MODE is not set, using valgrind" ) ;
30- Ok ( Box :: new ( ValgrindExecutor ) )
51+ debug ! ( "CODSPEED_RUNNER_MODE is not set, using instrumentation" ) ;
52+ Ok ( RunnerMode :: Instrumentation )
53+ }
54+ }
55+
56+ pub fn get_executor_from_mode ( mode : RunnerMode ) -> Box < dyn Executor > {
57+ match mode {
58+ RunnerMode :: Instrumentation => Box :: new ( ValgrindExecutor ) ,
59+ RunnerMode :: WallTime => Box :: new ( WallTimeExecutor ) ,
3160 }
3261}
3362
0 commit comments