22from .constants import PERFORMANCE_LOG_PATH , PERFORMANCE_SUMMARY_PATH , ACCURACY_LOG_PATH , VALID_DIVISIONS
33from .utils import list_dir
44from .parsers .loadgen_parser import LoadgenParser
5- from typing import Generator
5+ from typing import Generator , Literal
6+ import logging
7+
8+ logging .basicConfig (
9+ level = logging .INFO ,
10+ format = "[%(asctime)s %(filename)s:%(lineno)d %(levelname)s] %(message)s" ,
11+ )
612
713
814class SubmissionLogs :
@@ -15,26 +21,36 @@ class Loader:
1521 def __init__ (self , root , version ) -> None :
1622 self .root = root
1723 self .version = version
18- self .perf_log_path = PERFORMANCE_LOG_PATH .get (version , PERFORMANCE_LOG_PATH ["default" ])
19- self .perf_summary_path = PERFORMANCE_SUMMARY_PATH .get (version , PERFORMANCE_SUMMARY_PATH ["default" ])
20- self .acc_log_path = ACCURACY_LOG_PATH .get (version , ACCURACY_LOG_PATH ["default" ])
24+ self .logger = logging .getLogger ("LoadgenParser" )
25+ self .perf_log_path = os .path .join (self .root , PERFORMANCE_LOG_PATH .get (version , PERFORMANCE_LOG_PATH ["default" ]))
26+ self .perf_summary_path = os .path .join (self .root , PERFORMANCE_SUMMARY_PATH .get (version , PERFORMANCE_SUMMARY_PATH ["default" ]))
27+ self .acc_log_path = os .path .join (self .root , ACCURACY_LOG_PATH .get (version , ACCURACY_LOG_PATH ["default" ]))
28+
29+ def load_single_log (self , path , log_type : Literal ["Performance" , "Accuracy" , "Test" ]):
30+ log = None
31+ if os .path .exists (path ):
32+ self .logger .info ("Loading %s log from %s" , log_type , path )
33+ log = LoadgenParser (path )
34+ else :
35+ self .logger .info ("Could not load %s log from %s, path does not exist" , log_type , path )
36+ return log
2137
2238
23- def load (self ) -> Generator [SubmissionLogs , None ]:
39+ def load (self ) -> Generator [SubmissionLogs , None , None ]:
2440 for division in list_dir (self .root ):
2541 if division not in VALID_DIVISIONS :
2642 continue
2743 division_path = os .path .join (self .root , division )
28- for submitter in list_dir (division ):
44+ for submitter in list_dir (division_path ):
2945 results_path = os .path .join (division_path , submitter , "results" )
3046 for system in list_dir (results_path ):
3147 system_path = os .path .join (results_path , system )
3248 for benchmark in list_dir (system_path ):
3349 benchmark_path = os .path .join (system_path , benchmark )
34- for scenario in benchmark_path :
50+ for scenario in list_dir ( benchmark_path ) :
3551 scenario_path = os .path .join (benchmark_path , benchmark )
36- perf_log = LoadgenParser (self .perf_log_path .format (division = division , submitter = submitter , system = system , benchmark = system , scenario = scenario ))
37- acc_log = LoadgenParser (self .acc_log_path .format (division = division , submitter = submitter , system = system , benchmark = system , scenario = scenario ))
52+ perf_path = self .perf_log_path .format (division = division , submitter = submitter , system = system , benchmark = benchmark , scenario = scenario )
53+ acc_path = self .acc_log_path .format (division = division , submitter = submitter , system = system , benchmark = benchmark , scenario = scenario )
54+ perf_log = self .load_single_log (perf_path , "Performance" )
55+ acc_log = perf_log = self .load_single_log (acc_path , "Accuracy" )
3856 yield SubmissionLogs (perf_log , acc_log )
39- yield None
40-
0 commit comments