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

start working on SWF -> SABjson parser

parent b7c3b9c1
Branches
No related tags found
No related merge requests found
__pycache__
.vscode
out/*
\ No newline at end of file
out/*
workloads/*
!workloads/KTH-SP2-1996-2.1-cln.swf
from workload import SwfField, Job
\ No newline at end of file
#!/usr/bin/env python3
"""SWF types and functions."""
from enum import Enum, unique
@unique
class SwfField(Enum):
"""Maps SWF columns and their meaning."""
JOB_ID = 1
SUBMIT_TIME = 2
WAIT_TIME = 3
RUN_TIME = 4
ALLOCATED_PROCESSOR_COUNT = 5
AVERAGE_CPU_TIME_USED = 6
USED_MEMORY = 7
REQUESTED_NUMBER_OF_PROCESSORS = 8
REQUESTED_TIME = 9
REQUESTED_MEMORY = 10
STATUS = 11
USER_ID = 12
GROUP_ID = 13
APPLICATION_ID = 14
QUEUD_ID = 15
PARTITION_ID = 16
PRECEDING_JOB_ID = 17
THINK_TIME_FROM_PRECEDING_JOB = 18
class Job:
"""Class representing a job in the workload."""
def __init__(self,
job_id,
submit_time,
finish_time,
start_time=None,
nb_requested_resources=None,
walltime=None):
self.id = job_id
self.submit_time = submit_time
self.start_time = start_time
self.finish_time = finish_time
self.res = nb_requested_resources
self.walltime = walltime
def to_dict(self):
"""Job object to dictionnary, for printing or json export."""
run_time = self.finish_time - self.start_time
return {
"id": self.id,
"profile": str(run_time),
"res": self.res,
"subtime": self.submit_time,
"walltime": self.walltime
}
class Session:
"""Class representing a user session."""
def __init__(self, id, first_submit):
self.id = id
self.first_submit = first_submit
self.preceding_sessions = []
self.tt_after_prec_sess = []
self.jobs = []
def to_dict(self):
"""Session object to dictionnary, for printing or json export."""
return {
"id": self.id,
"first_submit_time": self.first_submit,
"preceding_sessions": self.preceding_sessions,
"thinking_time_after_preceding_session": self.tt_after_prec_sess,
"nb_jobs": len(self.jobs),
"jobs": [j.to_dict() for j in self.jobs]
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment