Commit b701d357 authored by Brewer, Wes's avatar Brewer, Wes
Browse files

Refactor get_current_utilization b/c it didn't handle case where job.trace_quanta not set

parent badf9df6
Loading
Loading
Loading
Loading
+10 −9
Original line number Diff line number Diff line
@@ -634,22 +634,23 @@ def convert_numpy_to_builtin(obj):


def get_current_utilization(trace, job: Job):
    # Return utilizaiton for a trace at the jobs current running time.
    # Note: this should move to a trace.py and a Trace class!
    util = 0.0
    """Return utilization for a trace at the job's current running time.
       Note: this should move to a trace.py and a Trace class!
    """
    if not job.trace_quanta:
        raise ValueError("job.trace_quanta is not set; cannot compute utilization.")

    if job.trace_quanta:
    time_quanta_index = int((job.running_time - job.trace_start_time) // job.trace_quanta)
    if time_quanta_index < 0:
        time_quanta_index = 0

    if (isinstance(trace, list) and trace != []) or \
    if (isinstance(trace, list) and trace) or \
       (isinstance(trace, np.ndarray) and trace.size != 0):
        if time_quanta_index < len(trace):
            util = get_utilization(trace, time_quanta_index)
        else:
            util = get_utilization(trace, max(0, len(trace) - 1))
    elif isinstance(trace, float) or isinstance(trace, int):
    elif isinstance(trace, (float, int)):
        util = trace
    else:
        util = 0.0