diff --git a/swf_moulinette.py b/swf_filter.py similarity index 83% rename from swf_moulinette.py rename to swf_filter.py index e24a4e53893d442707e68517c467a976e09c71b7..e03708dcdbb9bf3c0b21de63d0a4eaa716cd098b 100755 --- a/swf_moulinette.py +++ b/swf_filter.py @@ -1,7 +1,7 @@ #!/usr/bin/env python3 """ -SWF parser to make selections and obtain some stats. +SWF parser allowing to filter jobs from an input file according to some criteria. Inspired from https://gitlab.inria.fr/batsim/batsim/-/blob/master/tools/swf_to_batsim_workload_compute_only.py """ @@ -21,15 +21,12 @@ def generate_workload(input_swf, output_swf=None, indent=None, translate_submit_times=False, keep_only=None, - verbose=False, quiet=False, job_size_function_string='1*nb_res'): """Makes a selection from a SWF trace, optionally outputing it as SWF.""" element = '([-+]?\d+(?:\.\d+)?)' r = re.compile('\s*' + (element + '\s+') * 17 + element + '\s*') - current_id = 0 - # Some counters... not_selected = {"nb": 0, "coreh": 0} selected = {"nb": 0, "coreh": 0} @@ -37,14 +34,12 @@ def generate_workload(input_swf, output_swf=None, not_line_match_format = 0 users = [] - minimum_observed_submit_time = float('inf') - # Let's loop over the lines of the input file - i = 1 + i = 0 for line in input_swf: i += 1 - if i % 100000 == 0: - print("Processing swf line", i) + if not quiet and i % 10000 == 0: + print(f"\r\033[KProcessing swf line {i}", end="") res = r.match(line) @@ -96,19 +91,20 @@ def generate_workload(input_swf, output_swf=None, else: not_line_match_format += 1 - print('-------------------\nEnd parsing') - print('Total {} jobs and {} users have been created.'.format( - selected["nb"], len(users))) - print( - 'Total number of core-hours: {:.0f}'.format(selected["coreh"] / 3600)) - print('{} valid jobs were not selected (keep_only) for {:.0f} core-hour'.format( - not_selected["nb"], not_selected["coreh"] / 3600)) - print("Jobs not selected: {:.1f}% in number, {:.1f}% in core-hour" - .format(not_selected["nb"] / (not_selected["nb"]+selected["nb"]) * 100, - not_selected["coreh"] / (selected["coreh"]+not_selected["coreh"]) * 100)) - print('{} out of {} lines in the file did not match the swf format'.format( - not_line_match_format, i)) - print('{} jobs were not valid'.format(not_valid)) + if not quiet: + print('\n-------------------\nEnd parsing.') + print('Total {} jobs and {} users have been created.'.format( + selected["nb"], len(users))) + print( + 'Total number of core-hours: {:.0f}'.format(selected["coreh"] / 3600)) + print('{} valid jobs were not selected (keep_only) for {:.0f} core-hour'.format( + not_selected["nb"], not_selected["coreh"] / 3600)) + print("Jobs not selected: {:.1f}% in number, {:.1f}% in core-hour" + .format(not_selected["nb"] / (not_selected["nb"]+selected["nb"]) * 100, + not_selected["coreh"] / (selected["coreh"]+not_selected["coreh"]) * 100)) + print('{} out of {} lines in the file did not match the swf format'.format( + not_line_match_format, i)) + print('{} jobs were not valid'.format(not_valid)) @@ -155,9 +151,7 @@ def main(): default=None, help='If set, this parameter is evaluated to choose which jobs should be kept') - group = parser.add_mutually_exclusive_group() - group.add_argument("-v", "--verbose", action="store_true") - group.add_argument("-q", "--quiet", action="store_true") + parser.add_argument("-q", "--quiet", action="store_true") args = parser.parse_args() @@ -171,7 +165,6 @@ def main(): indent=args.indent, translate_submit_times=args.translate_submit_times, keep_only=args.keep_only, - verbose=args.verbose, quiet=args.quiet, job_size_function_string=args.job_size_function)