Skip to content
Snippets Groups Projects
Commit a1396675 authored by Maël Madon's avatar Maël Madon
Browse files

add option no_SABjson_output

parent a6f7b71a
Branches
Tags
No related merge requests found
Pipeline #4517 passed
......@@ -5,18 +5,11 @@ from src.user_session_builder import User
from src.workload import SwfField, Job
def swf2sessions(input_swf, output_dir, delim_approach, delim_threshold,
dynamic_reduction, build_graph_rep, session_stat,
def swf2sessions(input_swf, out_dir, delim_approach, delim_threshold,
dynamic_reduction, build_graph_rep, session_stat, no_SABjson_output,
job_walltime_factor, given_walltime_only, job_grain, quiet):
users = {}
if not os.path.exists(output_dir):
os.makedirs(output_dir)
if build_graph_rep:
if not os.path.exists(f"{output_dir}/graphs"):
os.makedirs(f"{output_dir}/graphs")
# Read SWF
element = '([-+]?\d+(?:\.\d+)?)'
r = re.compile('\s*' + (element + '\s+') * 17 + element + '\s*')
......@@ -58,20 +51,32 @@ def swf2sessions(input_swf, output_dir, delim_approach, delim_threshold,
user = users[user_id]
user.add_job(job)
# SWF finished, output for each user
for user_id, user in users.items():
with open(f"{output_dir}/user{user_id}.SABjson", "w") as file:
json.dump(user.to_dict(), file)
if build_graph_rep:
user.export_dependancy_graph(f"{output_dir}/graphs")
# SWF finished, write output files
# - SABjson:
if not(no_SABjson_output):
if not(os.path.exists(out_dir)):
os.makedirs(out_dir)
for user_id, user in users.items():
with open(f"{out_dir}/user{user_id}.SABjson", "w") as file:
json.dump(user.to_dict(), file)
# - graph:
if build_graph_rep:
if not(os.path.exists(f"{out_dir}/graphs")):
os.makedirs(f"{out_dir}/graphs")
for _, user in users.items():
user.export_dependancy_graph(f"{out_dir}/graphs")
# - session stat:
if session_stat:
stats = {}
for user_id, user in users.items():
stats[user_id] = user.to_session_stat()
with open(f"{output_dir}_session_stat.json", "w") as file:
with open(f"{out_dir}_session_stat.json", "w") as file:
json.dump(stats, file)
if not quiet:
......@@ -79,11 +84,11 @@ def swf2sessions(input_swf, output_dir, delim_approach, delim_threshold,
print("Number of users: ", len(users))
print("Number of sessions: ",
sum([len(u.sessions) for u in users.values()]))
print(f"The output files have been stored in the folder {output_dir}")
print(f"The output files have been stored in the folder {out_dir}")
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='TODO')
parser = argparse.ArgumentParser(description="Python script to read a workload trace in the Standard Workload Format (SWF), decompose it into user sessions, analyse the dependencies between sessions and store the results in the Session Annotated Batsim JSON format (SABjson).")
parser.add_argument('input_swf',
type=argparse.FileType('r'),
help='The input SWF file')
......@@ -135,6 +140,10 @@ if __name__ == "__main__":
"about the original session durations (finish times) that are NOT "
"embedded in the SABjsons."
)
parser.add_argument(
'--no_SABjson_output', action="store_true",
help="Disable SABjson output (for graph-only or session_stat-only usages)."
)
parser.add_argument("-q",
"--quiet",
......@@ -184,12 +193,13 @@ if __name__ == "__main__":
"The threshold must be a positive value.")
swf2sessions(input_swf=args.input_swf,
output_dir=args.output_dir,
out_dir=args.output_dir,
delim_approach=delim,
delim_threshold=threshold,
dynamic_reduction=not (args.no_dynamic_reduction),
build_graph_rep=args.graph,
session_stat=args.session_stat,
no_SABjson_output=args.no_SABjson_output,
job_walltime_factor=args.job_walltime_factor,
given_walltime_only=args.given_walltime_only,
job_grain=args.job_grain,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment