[Mesa-dev] [PATCH shader-db 1/2] report.py: rework and update for cycle info

Connor Abbott cwabbott0 at gmail.com
Fri Oct 2 14:37:35 PDT 2015


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.

Signed-off-by: Connor Abbott <cwabbott0 at gmail.com>
---
 report.py | 140 ++++++++++++++++++++++++++++++--------------------------------
 1 file changed, 67 insertions(+), 73 deletions(-)

diff --git a/report.py b/report.py
index 4c06714..bc3a640 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*) cycles, (\S*) loops")
     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])
+	cycle_count = int(groups[3])
+        loop_count = int(groups[4])
+        if inst_count != 0:
+            results[(groups[0], groups[1])] = {
+                "instructions": inst_count,
+                "cycles": cycle_count,
+		"loops": loop_count
+            }
 
     return results
 
@@ -50,76 +55,77 @@ def main():
     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
+    for measurement in ["instructions", "cycles", "loops"]:
+        total_before = 0
+        total_after = 0
+        affected_before = 0
+        affected_after = 0
 
-    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]
+        helped = []
+        hurt = []
+        for p in args.before:
+            before_count = args.before[p][measurement]
+
+            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 measurement != "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][measurement]
 
-            if before_loop == after_loop:
-                total_before += before_count
-                total_after += after_count
+            total_before += before_count
+            total_after += after_count
 
             if before_count != after_count:
                 affected_before += before_count
                 affected_after += 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][measurement] - args.after[k][measurement]) / args.before[k][measurement])
+        for p in helped:
+            namestr = p[0] + " " + p[1]
+            print(measurement + " helped:   " + get_result_string(
+                namestr, args.before[p][measurement], args.after[p][measurement]))
+        if len(helped) > 0:
+            print("")
+
+        hurt.sort(
+            key=lambda k: float(args.after[k][measurement] - args.before[k][measurement]) / args.before[k][measurement])
+        for p in hurt:
+            namestr = p[0] + " " + p[1]
+            print(measurement + " HURT:   " + get_result_string(
+                namestr, args.before[p][measurement], args.after[p][measurement]))
+        if len(hurt) > 0:
+            print("")
+
+        print("total {0} in shared programs: {1}\n"
+    	  "{0} in affected programs: {2}\n"
+    	  "helped: {3}\n"
+    	  "HURT: {4}\n".format(
+    	      measurement,
+    	      change(total_before, total_after),
+    	      change(affected_before, affected_after),
+    	      len(helped),
+    	      len(hurt)))
 
-    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("")
+    lost = []
+    gained = []
 
-    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("")
+    for p in args.before:
+        if args.after.get(p) is None:
+            lost.append(p[0] + " " + p[1])
 
-    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("")
+    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 +139,8 @@ 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)))
+    print("LOST:   " + str(len(lost)))
+    print("GAINED: " + str(len(gained)))
 
 
 if __name__ == "__main__":
-- 
2.1.0



More information about the mesa-dev mailing list