Commit 23b74403 authored by Jan Kiene's avatar Jan Kiene
Browse files

handle zero values that cause division error

parent 9a31c518
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -33,8 +33,20 @@ def check_linewise_logfile(filepath, cols):
        # do not report any changes then
        prev = curr

    change_ratios = [abs(float(curr[i]) / float(prev[i]) - 1) > THRESH for i in cols]
    changes_found = any(change_ratios)
    changes_found = False
    for c in cols:
        if curr[c] == prev[c]:
            abs_perc_change = 0
        else:
            try:
                abs_perc_change = abs(float(curr[c]) / float(prev[c]) - 1)
            except ZeroDivisionError:
                # in some cases, such as missing instrumentation, values can be zero, so catch that here
                # from the first if we know that curr can not be 0 too -> report change
                abs_perc_change = THRESH + 1
        if abs_perc_change > THRESH:
            changes_found = True
            break

    if changes_found:
        print("Previous log line:", prev)