Now that we have three separate things we want to measure (instructions, cycles, and loops), it's impractical to keep adding special code for changes in each thing. Instead, for each program in before and after we store a table of measurement -> value, and when reporting we loop over each measurement and report helped/hurt before reporting the gained/lost programs.
v2: - Swap loop count and cycle count to be compatible with older shader-db. - Fix indentation. - Report summary information (hurt/helped) last to make it easier to find. - Squash in second commit to avoid duplicating the list of measurements due to the above. Signed-off-by: Connor Abbott <cwabbo...@gmail.com> --- report.py | 164 ++++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 89 insertions(+), 75 deletions(-) diff --git a/report.py b/report.py index 4c06714..409474a 100755 --- a/report.py +++ b/report.py @@ -10,17 +10,22 @@ def get_results(filename): results = {} - re_match = re.compile(r"(\S+) - (.S \S+) shader: (\S*) inst, (\S*) loops") + re_match = re.compile(r"(\S+) - (.S \S+) shader: (\S*) inst, (\S*) loops, (\S*) cycles") for line in lines: match = re.search(re_match, line) if match is None: continue groups = match.groups() - count = int(groups[2]) - loop = int(groups[3]) - if count != 0: - results[(groups[0], groups[1])] = count, loop + inst_count = int(groups[2]) + loop_count = int(groups[3]) + cycle_count = int(groups[4]) + if inst_count != 0: + results[(groups[0], groups[1])] = { + "instructions": inst_count, + "cycles": cycle_count, + "loops": loop_count + } return results @@ -43,83 +48,92 @@ def get_result_string(p, b, a): p = p + ' ' return p + change(b, a) +def split_list(string): + return string.split(",") def main(): parser = argparse.ArgumentParser() + parser.add_argument("--measurements", "-m", type=split_list, + default=["instructions", "cycles", "loops"], + help="comma-separated list of measurements to report") parser.add_argument("before", type=get_results, help="the output of the original code") parser.add_argument("after", type=get_results, help="the output of the new code") args = parser.parse_args() - total_before = 0 - total_after = 0 - total_before_loop = 0 - total_after_loop = 0 - affected_before = 0 - affected_after = 0 + total_before = {} + total_after = {} + affected_before = {} + affected_after = {} + num_hurt = {} + num_helped = {} - helped = [] - hurt = [] - lost = [] - gained = [] - loop_change = [] - for p in args.before: - (name, type) = p - namestr = name + " " + type - before_count = args.before[p][0] - before_loop = args.before[p][1] + for m in args.measurements: + total_before[m] = 0 + total_after[m] = 0 + affected_before[m] = 0 + affected_after[m] = 0 + + print m + + helped = [] + hurt = [] + for p in args.before: + before_count = args.before[p][m] + + if args.after.get(p) is None: + continue - if args.after.get(p) is not None: - after_count = args.after[p][0] - after_loop = args.after[p][1] + # If the number of loops changed, then we may have unrolled some + # loops, in which case other measurements will be misleading. + if m != "loops" and args.before[p]["loops"] != args.after[p]["loops"]: + continue - total_before_loop += before_loop - total_after_loop += after_loop + after_count = args.after[p][m] - if before_loop == after_loop: - total_before += before_count - total_after += after_count + total_before[m] += before_count + total_after[m] += after_count if before_count != after_count: - affected_before += before_count - affected_after += after_count + affected_before[m] += before_count + affected_after[m] += after_count - if after_loop != before_loop: - loop_change.append(p); - elif after_count > before_count: + if after_count > before_count: hurt.append(p) else: helped.append(p) - else: - lost.append(namestr) - for p in args.after: - if args.before.get(p) is None: - gained.append(p[0] + " " + p[1]) + helped.sort( + key=lambda k: float(args.before[k][m] - args.after[k][m]) / args.before[k][m]) + for p in helped: + namestr = p[0] + " " + p[1] + print(m + " helped: " + get_result_string( + namestr, args.before[p][m], args.after[p][m])) + if len(helped) > 0: + print("") - helped.sort( - key=lambda k: float(args.before[k][0] - args.after[k][0]) / args.before[k][0]) - for p in helped: - namestr = p[0] + " " + p[1] - print("helped: " + get_result_string( - namestr, args.before[p][0], args.after[p][0])) - if len(helped) > 0: - print("") + hurt.sort( + key=lambda k: float(args.after[k][m] - args.before[k][m]) / args.before[k][m]) + for p in hurt: + namestr = p[0] + " " + p[1] + print(m + " HURT: " + get_result_string( + namestr, args.before[p][m], args.after[p][m])) + if len(hurt) > 0: + print("") - hurt.sort( - key=lambda k: float(args.after[k][0] - args.before[k][0]) / args.before[k][0]) - for p in hurt: - namestr = p[0] + " " + p[1] - print("HURT: " + get_result_string( - namestr, args.before[p][0], args.after[p][0])) - if len(hurt) > 0: - print("") + num_helped[m] = len(helped) + num_hurt[m] = len(hurt) - for p in loop_change: - namestr = p[0] + " " + p[1] - print("LOOP CHANGE (" + str(args.before[p][1]) + " -> " + str(args.after[p][1]) + - "): " + get_result_string(namestr, args.before[p][0], args.after[p][0])) - if len(loop_change) > 0: - print("") + + lost = [] + gained = [] + + for p in args.before: + if args.after.get(p) is None: + lost.append(p[0] + " " + p[1]) + + for p in args.after: + if args.before.get(p) is None: + gained.append(p[0] + " " + p[1]) lost.sort() for p in lost: @@ -133,20 +147,20 @@ def main(): if len(gained) > 0: print("") - print("total instructions in shared programs: {}\n" - "instructions in affected programs: {}\n" - "total loops in shared programs: {}\n" - "helped: {}\n" - "HURT: {}\n" - "GAINED: {}\n" - "LOST: {}".format( - change(total_before, total_after), - change(affected_before, affected_after), - change(total_before_loop, total_after_loop), - len(helped), - len(hurt), - len(gained), - len(lost))) + for m in args.measurements: + print("total {0} in shared programs: {1}\n" + "{0} in affected programs: {2}\n" + "helped: {3}\n" + "HURT: {4}\n".format( + m, + change(total_before[m], total_after[m]), + change(affected_before[m], affected_after[m]), + num_helped[m], + num_hurt[m])) + + + print("LOST: " + str(len(lost))) + print("GAINED: " + str(len(gained))) if __name__ == "__main__": -- 2.4.3 _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev