[Mesa-dev] [PATCH shader-db v2 1/5] nv-report: deduplicate list of fields
Rhys Perry
pendingchaos02 at gmail.com
Sun Aug 5 12:06:08 UTC 2018
Signed-off-by: Rhys Perry <pendingchaos02 at gmail.com>
Reviewed-by: Ilia Mirkin <imirkin at alum.mit.edu>
---
nv-report.py | 53 +++++++++++++++++++----------------------------------
1 file changed, 19 insertions(+), 34 deletions(-)
diff --git a/nv-report.py b/nv-report.py
index bdc2093a73..3f0be63557 100644
--- a/nv-report.py
+++ b/nv-report.py
@@ -14,6 +14,9 @@ import re
import sys
+STATS = ["local", "shared", "gpr", "inst", "bytes"]
+ATTRS = ["name", "type"] + STATS
+
def getgroupvalue(m, groupname):
if not m[groupname]:
return 0
@@ -23,51 +26,33 @@ def getgroupvalue(m, groupname):
class Stat(object):
def __init__(self, m=None):
- if m:
- self.local = getgroupvalue(m, "local")
- self.shared = getgroupvalue(m, "shared")
- self.gpr = getgroupvalue(m, "gpr")
- self.inst = getgroupvalue(m, "inst")
- self.bytes = getgroupvalue(m, "bytes")
- else:
- self.local = 0
- self.shared = 0
- self.gpr = 0
- self.inst = 0
- self.bytes = 0
+ for attr in STATS:
+ setattr(self, attr, getgroupvalue(m, attr) if m else 0)
def __eq__(self, other):
- return (self.local == other.local and
- self.shared == other.shared and
- self.gpr == other.gpr and
- self.inst == other.inst and
- self.bytes == other.bytes)
+ for attr in STATS:
+ if getattr(self, attr) != getattr(other, attr):
+ return False
+ return True
class Stats(object):
def __init__(self):
self.stats = {}
- self.local = 0
- self.shared = 0
- self.gpr = 0
- self.inst = 0
- self.bytes = 0
+ for attr in STATS:
+ setattr(self, attr, 0)
def record(self, name, stat):
assert name not in self.stats, name
self.stats[name] = stat
- for attr in ("local", "shared", "gpr", "inst", "bytes"):
+ for attr in STATS:
setattr(self, attr, getattr(self, attr) + getattr(stat, attr))
RE = {
"name": re.compile(r"^(.*) - "),
- "type": re.compile(r"type: (\d+)"),
- "local": re.compile(r"local: (\d+)"),
- "shared": re.compile(r"shared: (\d+)"),
- "gpr": re.compile(r"gpr: (\d+)"),
- "inst": re.compile(r"inst: (\d+)"),
- "bytes": re.compile(r"bytes: (\d+)")
}
+for attr in ["type"] + STATS:
+ RE[attr] = re.compile(attr + ": (\d+)")
def analyze(fname):
stats = Stats()
@@ -76,7 +61,7 @@ def analyze(fname):
if line.startswith("Thread "):
continue
m = {}
- for attr in ("name", "type", "local", "shared", "gpr", "inst", "bytes"):
+ for attr in ATTRS:
m[attr] = RE[attr].search(line)
assert m["name"], line
assert m["type"], line
@@ -108,7 +93,7 @@ def main(argv):
a = after.stats[key]
b = before.stats[key]
if a != b:
- for attr in ("local", "shared", "gpr", "inst", "bytes"):
+ for attr in STATS:
aa = getattr(a, attr)
ba = getattr(b, attr)
if aa == ba:
@@ -125,13 +110,13 @@ def main(argv):
print "total shared used in shared programs :", diff(before.shared, after.shared)
print "total local used in shared programs :", diff(before.local, after.local)
print
- print "%10s %10s %10s %10s %10s %10s " % ("", "local", "shared", "gpr", "inst", "bytes")
+ print ("%10s " * (len(STATS) + 1)) % tuple([""] + STATS)
print "%10s " % "helped",
- for attr in ("local", "shared", "gpr", "inst", "bytes"):
+ for attr in STATS:
print "%10d " % getattr(helped, attr),
print
print "%10s " % "hurt",
- for attr in ("local", "shared", "gpr", "inst", "bytes"):
+ for attr in STATS:
print "%10d " % getattr(hurt, attr),
--
2.14.4
More information about the mesa-dev
mailing list