[Mesa-dev] [shader-db] [PATCH 2/3] nv-report: Match fields regardless of their order

Pierre Moreau pierre.morrow at free.fr
Sun Oct 8 09:08:47 UTC 2017


If a field was not present, its value will default to 0.

This lets the code run on outputs that did not include the amount of
shared memory used, for example.

Signed-off-by: Pierre Moreau <pierre.morrow at free.fr>
---
 nv-report.py | 38 ++++++++++++++++++++++++++++----------
 1 file changed, 28 insertions(+), 10 deletions(-)

diff --git a/nv-report.py b/nv-report.py
index 724c662..bb6b42d 100644
--- a/nv-report.py
+++ b/nv-report.py
@@ -5,19 +5,29 @@ We're matching lines like
 
 5.shader_test - type: 1, local: 0, gpr: 4, inst: 7, bytes: 56
 11.shader_test - type: 1, local: 0, gpr: 4, inst: 1, bytes: 8
+
+although the order of the fields after the dash does not matter, and all
+fields, except for the type, are optional.
 """
 
 import re
 import sys
 
+
+def getgroupvalue(m, groupname):
+    if not m[groupname]:
+        return 0
+    else:
+        return int(m[groupname].group(1), 10)
+
 class Stat(object):
 
     def __init__(self, m=None):
         if m:
-            self.local = int(m.group("local"), 10)
-            self.gpr = int(m.group("gpr"), 10)
-            self.inst = int(m.group("inst"), 10)
-            self.bytes = int(m.group("bytes"), 10)
+            self.local = getgroupvalue(m, "local")
+            self.gpr = getgroupvalue(m, "gpr")
+            self.inst = getgroupvalue(m, "inst")
+            self.bytes = getgroupvalue(m, "bytes")
         else:
             self.local = 0
             self.gpr = 0
@@ -45,9 +55,14 @@ class Stats(object):
         for attr in ("local", "gpr", "inst", "bytes"):
             setattr(self, attr, getattr(self, attr) + getattr(stat, attr))
 
-RE = re.compile(r"^(?P<name>.*) - type: (?P<type>\d+), local: (?P<local>\d+), "
-                r"gpr: (?P<gpr>\d+), inst: (?P<inst>\d+), "
-                r"bytes: (?P<bytes>\d+)$")
+RE = {
+        "name":   re.compile(r"^(.*) - "),
+        "type":   re.compile(r"type: (\d+)"),
+        "local":  re.compile(r"local: (\d+)"),
+        "gpr":    re.compile(r"gpr: (\d+)"),
+        "inst":   re.compile(r"inst: (\d+)"),
+        "bytes":  re.compile(r"bytes: (\d+)")
+}
 
 def analyze(fname):
     stats = Stats()
@@ -55,9 +70,12 @@ def analyze(fname):
         for line in f.xreadlines():
             if line.startswith("Thread "):
                 continue
-            m = RE.match(line)
-            assert m, line
-            stats.record(m.group("name") + " - " + m.group("type"), Stat(m))
+            m = {}
+            for attr in ("name", "type", "local", "gpr", "inst", "bytes"):
+                m[attr] = RE[attr].search(line)
+            assert m["name"], line
+            assert m["type"], line
+            stats.record(m["name"].group(1) + " - " + m["type"].group(1), Stat(m))
 
     return stats
 
-- 
2.14.2



More information about the mesa-dev mailing list