summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Olšák <marek.olsak@amd.com>2023-04-13 18:28:45 -0400
committerMarek Olšák <marek.olsak@amd.com>2023-05-14 22:39:13 -0400
commite06ff745bb45f8b603d310d09e481e0682137071 (patch)
tree14a8864dd6550db82acecc14675c73011887bbcf
parent2de3da1c4e5b5507111f1521e64e90ef5cb92744 (diff)
si-report.py: fix syntax and style issues
reported by pycodestyle
-rwxr-xr-xsi-report.py115
1 files changed, 67 insertions, 48 deletions
diff --git a/si-report.py b/si-report.py
index 0bed55e..241d2a5 100755
--- a/si-report.py
+++ b/si-report.py
@@ -33,27 +33,31 @@ set_green = "\033[1;32m"
set_yellow = "\033[1;33m"
set_normal = "\033[0m"
-def format_float(f, suffix = ' %'):
+
+def format_float(f, suffix=' %'):
return "{0:0.2f}{1}".format(f, suffix)
-def get_str(value, suffix = ' %'):
+
+def get_str(value, suffix=' %'):
if type(value) == float:
return format_float(value, suffix)
else:
return value
+
def calculate_percent_change(b, a):
if b == 0:
return 0 if a == 0 else float("inf")
return 100 * float(a - b) / float(b)
-def format_table_cell(n, more_is_better = False, colored = True, is_percent = False, min_width=10):
+
+def format_table_cell(n, more_is_better=False, colored=True, is_percent=False, min_width=10):
if is_percent:
if abs(n) < 0.01:
return "{:^{width}}".format(".", width=min_width)
min_width = min_width - 2
- str = ("{:>{width}.2f} %" if is_percent else "{:>{width}}").format(n, width=min_width)
+ str = ("{:>{width}.2f} %" if is_percent else "{:>{width}}").format(n, width=min_width)
if colored:
if n > 0.5:
str = (set_green if more_is_better else set_red) + str + set_normal
@@ -62,22 +66,27 @@ def format_table_cell(n, more_is_better = False, colored = True, is_percent = Fa
return str
-def format_percent_change(b, a, more_is_better = False, colored = True, min_width=8):
+def format_percent_change(b, a, more_is_better=False, colored=True, min_width=8):
percent = calculate_percent_change(b, a)
- return format_table_cell(percent, more_is_better, colored, min_width=min_width, is_percent = True)
+ return format_table_cell(percent, more_is_better, colored, min_width=min_width, is_percent=True)
+
def cmp_max_unit(current, comp):
return comp[0] > current[0]
+
def cmp_min_unit(current, comp):
return comp[0] < current[0]
+
def cmp_max_per(current, comp):
return calculate_percent_change(comp[1], comp[2]) > calculate_percent_change(current[1], current[2])
+
def cmp_min_per(current, comp):
return calculate_percent_change(comp[1], comp[2]) < calculate_percent_change(current[1], current[2])
+
class si_stats:
metrics = [
('sgprs', 'SGPRS', ''),
@@ -111,7 +120,7 @@ class si_stats:
return copy
- def to_string(self, suffixes = True):
+ def to_string(self, suffixes=True):
strings = []
for name, printname, suffix in si_stats.metrics:
string = " {}: {}".format(printname, get_str(self.__dict__[name]))
@@ -174,9 +183,9 @@ class si_stats:
def is_empty(self):
for name in self.get_metrics():
x = self.__dict__[name]
- if type(x) == tuple and x[0] is not 0:
+ if type(x) == tuple and x[0] != 0:
return False
- if type(x) != tuple and x is not 0:
+ if type(x) != tuple and x != 0:
return False
return True
@@ -184,17 +193,17 @@ class si_stats:
class si_parser(object):
re_stats = [
re.compile(
- r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) "+
- r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: "+
- r"([0-9]+) Spilled VGPRs: ([0-9]+) PrivMem VGPRs: ([0-9]+) Outputs: ([0-9]+) "+
+ r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) " +
+ r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: " +
+ r"([0-9]+) Spilled VGPRs: ([0-9]+) PrivMem VGPRs: ([0-9]+) Outputs: ([0-9]+) " +
r"PatchOutputs: ([0-9]+)"),
re.compile(
- r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) "+
- r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: "+
+ r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) " +
+ r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: " +
r"([0-9]+) Spilled VGPRs: ([0-9]+) PrivMem VGPRs: ([0-9]+)"),
re.compile(
- r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) "+
- r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: "+
+ r"^Shader Stats: SGPRS: ([0-9]+) VGPRS: ([0-9]+) Code Size: ([0-9]+) " +
+ r"LDS: ([0-9]+) Scratch: ([0-9]+) Max Waves: ([0-9]+) Spilled SGPRs: " +
r"([0-9]+) Spilled VGPRs: ([0-9]+)"),
]
@@ -213,13 +222,13 @@ class si_parser(object):
self._in_disasm = True
return old_stats
- for re in si_parser.re_stats:
- match = re.match(msg)
+ for r in si_parser.re_stats:
+ match = r.match(msg)
if match is not None:
break
if match is not None:
- if self._stats == None:
+ if self._stats is None:
self._stats = si_stats()
self._stats.sgprs = int(match.group(1))
self._stats.vgprs = int(match.group(2))
@@ -248,6 +257,7 @@ class si_parser(object):
self._in_disasm = False
return None
+
def get_results(filename):
"""
Returns a dictionary that maps shader_test names to lists of si_stats
@@ -274,7 +284,7 @@ def get_results(filename):
for name, parser in parsers.items():
stats = parser.finish()
if stats is not None:
- print "Results for", name, "not fully parsed!"
+ print("Results for {} not fully parsed!".format(name))
results[name].append(stats)
return results
@@ -288,18 +298,21 @@ def compare_stats(before, after):
result.__dict__[name] = (a - b, b, a)
return result
+
def subtract_stats(x, y):
result = si_stats()
for name in result.get_metrics():
result.__dict__[name] = x.__dict__[name] - y.__dict__[name]
return result
+
def is_different(before, after):
for field in before.get_metrics():
if before.__dict__[field] != after.__dict__[field]:
return True
return False
+
def divide_stats(num, div):
result = si_stats()
for name in result.get_metrics():
@@ -309,7 +322,8 @@ def divide_stats(num, div):
result.__dict__[name] = 100.0 * float(num.__dict__[name]) / float(div.__dict__[name])
return result
-def print_before_after_stats(before, after, divisor = 1):
+
+def print_before_after_stats(before, after, divisor=1):
result = si_stats()
for name in result.get_metrics():
b = before.__dict__[name] / divisor
@@ -318,9 +332,9 @@ def print_before_after_stats(before, after, divisor = 1):
percent = format_float(0.0)
else:
percent = format_float(100 * float(a - b) / float(b))
- result.__dict__[name] = '{} -> {} ({})'.format(get_str(b,''), get_str(a,''), percent)
+ result.__dict__[name] = '{} -> {} ({})'.format(get_str(b, ''), get_str(a, ''), percent)
- print result
+ print(result)
def compare_results(before_all_results, after_all_results):
@@ -400,19 +414,20 @@ def compare_results(before_all_results, after_all_results):
def report_ignored(names, what):
if names:
- print "*** {} are ignored:".format(what)
+ print("*** {} are ignored:".format(what))
s = ', '.join(names[:5])
if len(names) > 5:
s += ', and {} more'.format(len(names) - 5)
- print s
+ print(s)
report_ignored(only_after_names, "Tests only in 'after' results")
report_ignored(only_before_names, "Tests only in 'before' results")
report_ignored(count_mismatch_names, "Tests with different number of shaders")
report_ignored(errors_names, "Shaders with compilation errors")
if num_after_errors > 0 or num_before_errors > 0:
- print "*** Compile errors encountered! (before: {}, after: {})".format(
- num_before_errors, num_after_errors)
+ print("*** Compile errors encountered! (before: {}, after: {})".format(
+ num_before_errors, num_after_errors))
+
class grouped_stats:
def __init__(self):
@@ -434,40 +449,40 @@ class grouped_stats:
def print_vgpr_spilling_app(self, name):
if (self.after.spilled_vgprs > 0 or
self.after.privmem_vgprs > 0):
- print " {:6}{:6} {:6} {:6} {:22}".format(
+ print(" {:6}{:6} {:6} {:6} {:22}".format(
self.num_shaders,
self.after.spilled_vgprs,
self.after.privmem_vgprs,
self.after.scratch_size,
- name)
+ name))
def print_one_shader_vgpr_spill(self, name):
if (self.after.spilled_vgprs > 0 or
self.after.privmem_vgprs > 0):
- print " {:6}{:6}{:6} {:6} {:22}".format(
+ print(" {:6}{:6}{:6} {:6} {:22}".format(
self.after.vgprs,
self.after.spilled_vgprs,
self.after.privmem_vgprs,
self.after.scratch_size,
- name)
+ name))
def print_sgpr_spilling_app(self, name):
if self.after.spilled_sgprs > 0:
- print " {:6} {:6} {:>5.1f} {:22}".format(
+ print(" {:6} {:6} {:>5.1f} {:22}".format(
self.num_shaders,
self.after.spilled_sgprs,
float(self.after.spilled_sgprs) / float(self.num_shaders),
- name)
+ name))
def print_one_shader_sgpr_spill(self, name):
if self.after.spilled_sgprs > 0:
- print " {:6}{:6} {:90}".format(
+ print(" {:6}{:6} {:90}".format(
self.after.sgprs,
self.after.spilled_sgprs,
- name)
+ name))
def print_percentages_end(self, name, align, legend):
- print "| {:{app_width}} |{:{shader_width}}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|".format(
+ print("| {:{app_width}} |{:{shader_width}}|{}|{}|{}|{}|{}|{}|{}|{}|{}|{}|".format(
name,
self.num_shaders,
format_percent_change(self.before.sgprs, self.after.sgprs, min_width=len(legend[1])),
@@ -477,23 +492,24 @@ class grouped_stats:
format_percent_change(self.before.privmem_vgprs, self.after.privmem_vgprs, min_width=len(legend[5])),
format_percent_change(self.before.scratch_size, self.after.scratch_size, min_width=len(legend[6])),
format_percent_change(self.before.code_size, self.after.code_size, min_width=len(legend[7])),
- format_percent_change(self.before.maxwaves, self.after.maxwaves, min_width=len(legend[8]), more_is_better = True),
+ format_percent_change(self.before.maxwaves, self.after.maxwaves, min_width=len(legend[8]), more_is_better=True),
format_percent_change(self.before.outputs, self.after.outputs, min_width=len(legend[9])),
format_percent_change(self.before.patchoutputs, self.after.patchoutputs, min_width=len(legend[10])),
app_width=align,
- shader_width=len(legend[0]))
+ shader_width=len(legend[0])))
def print_regression(self, name, field):
more_is_better = field == "maxwaves"
- print " {:6}{:6}{} {} {:90}".format(
+ print(" {:6}{:6}{} {} {:90}".format(
self.before.__dict__[field],
self.after.__dict__[field],
format_table_cell(self.after.__dict__[field] - self.before.__dict__[field],
- more_is_better = more_is_better),
+ more_is_better=more_is_better),
format_percent_change(self.before.__dict__[field], self.after.__dict__[field],
- more_is_better = more_is_better,
+ more_is_better=more_is_better,
min_width=len("Percentage")),
- name)
+ name))
+
"""
Return "filename [index]", because files can contain multiple shaders.
@@ -503,13 +519,14 @@ def get_shader_name(list, orig):
# add the index to the name
name = orig + " [{}]".format(i)
if name not in list:
- return name
+ return name
assert False
return "(error)"
def print_yellow(str):
- print set_yellow + str + set_normal
+ print(set_yellow + str + set_normal)
+
def print_tables(before_all_results, after_all_results):
re_app = re.compile(r"^.*/([^/]+)/[^/]+$")
@@ -563,7 +580,7 @@ def print_tables(before_all_results, after_all_results):
# worst VGPR spills
num = 0
sort_key = lambda v: -v[1].after.scratch_size
- for name, stats in sorted(shaders.items(), key = sort_key):
+ for name, stats in sorted(shaders.items(), key=sort_key):
if num == 0:
print_yellow("WORST VGPR SPILLS (not deltas)" + (" " * 64))
print_yellow(" VGPRs Spills Private Scratch")
@@ -583,7 +600,7 @@ def print_tables(before_all_results, after_all_results):
# worst SGPR spills
num = 0
sort_key = lambda v: -v[1].after.spilled_sgprs
- for name, stats in sorted(shaders.items(), key = sort_key):
+ for name, stats in sorted(shaders.items(), key=sort_key):
if num == 0:
print_yellow("WORST SGPR SPILLS (not deltas)" + (" " * 64))
print_yellow(" SGPRs Spills")
@@ -612,7 +629,7 @@ def print_tables(before_all_results, after_all_results):
else:
sort_key = lambda v: -v[1].diff.__dict__[field]
- for name, stats in sorted(shaders.items(), key = sort_key):
+ for name, stats in sorted(shaders.items(), key=sort_key):
if more_is_better:
if stats.diff.__dict__[field] >= 0:
continue
@@ -642,7 +659,7 @@ def print_tables(before_all_results, after_all_results):
else:
sort_key = lambda v: v[1].diff.__dict__[field]
- for name, stats in sorted(shaders.items(), key = sort_key):
+ for name, stats in sorted(shaders.items(), key=sort_key):
if more_is_better:
if stats.diff.__dict__[field] <= 0:
continue
@@ -675,6 +692,7 @@ def print_tables(before_all_results, after_all_results):
total.print_percentages_end("Total", longest_app_name, legend)
print
+
def main():
before = sys.argv[1]
after = sys.argv[2]
@@ -685,5 +703,6 @@ def main():
compare_results(results_before, results_after)
print_tables(results_before, results_after)
+
if __name__ == "__main__":
main()