si-report.py 25.1 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#!/usr/bin/env python
# vim: set expandtab tabstop=4 softtabstop=4 shiftwidth=4: */
#
# Copyright 2015 Advanced Micro Devices, Inc.
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#

26 27
from collections import defaultdict
import itertools
28 29 30
import re
import sys

31 32 33 34 35
set_red = "\033[31m"
set_green = "\033[1;32m"
set_yellow = "\033[1;33m"
set_normal = "\033[0m"

36 37 38 39 40 41 42 43 44 45 46
def format_float(f, suffix = ' %'):
    return "{0:0.2f}{1}".format(f, 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:
47
        return 0 if a == 0 else float("inf")
48 49
    return 100 * float(a - b) / float(b)

50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
def format_table_cell(n, more_is_better = False, colored = True, is_percent = False):
    if is_percent and abs(n) < 0.01:
        return "     .    "

    str =  ("{:>8.2f} %" if is_percent else "{:>10}").format(n)
    if colored:
        if n > 0.5:
            str = (set_green if more_is_better else set_red) + str + set_normal
        elif n < -0.5:
            str = (set_red if more_is_better else set_green) + str + set_normal
    return str


def format_percent_change(b, a, more_is_better = False, colored = True):
    percent = calculate_percent_change(b, a)
    return format_table_cell(percent, more_is_better, colored, is_percent = True)

67 68 69 70 71 72 73 74 75 76 77 78 79
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:
80 81 82
    metrics = [
        ('sgprs', 'SGPRS', ''),
        ('vgprs', 'VGPRS', ''),
83 84
        ('spilled_sgprs', 'Spilled SGPRs', ''),
        ('spilled_vgprs', 'Spilled VGPRs', ''),
85
        ('privmem_vgprs', 'Private memory VGPRs', ''),
86
        ('scratch_size', 'Scratch size', 'dwords per thread'),
87 88
        ('code_size', 'Code Size', 'bytes'),
        ('lds', 'LDS', 'blocks'),
89
        ('maxwaves', 'Max Waves', ''),
90 91 92
        ('waitstates', 'Wait states', ''),
    ]

93
    def __init__(self):
94
        self.error = False
95

96 97
        for name in self.get_metrics():
            self.__dict__[name] = 0
98

99 100 101 102 103 104 105 106 107 108 109 110 111
        self._minmax_testname = {}

    def copy(self):
        copy = si_stats()
        copy.error = self.error

        for name in self.get_metrics():
            copy.__dict__[name] = self.__dict__[name]

        copy._minmax_testname = self._minmax_testname.copy()

        return copy

112
    def to_string(self, suffixes = True):
113 114
        strings = []
        for name, printname, suffix in si_stats.metrics:
115 116 117 118 119 120 121 122 123 124
            string = "{}: {}".format(printname, get_str(self.__dict__[name]))

            if suffixes and len(suffix) > 0:
                string += ' ' + suffix

            minmax_testname = self._minmax_testname.get(name)
            if minmax_testname is not None:
                string += ' (in {})'.format(minmax_testname)

            strings.append(string + '\n')
125
        return ''.join(strings)
126

127 128
    def get_metrics(self):
        return [m[0] for m in si_stats.metrics]
129 130 131 132 133

    def __str__(self):
        return self.to_string()

    def add(self, other):
134 135
        for name in self.get_metrics():
            self.__dict__[name] += other.__dict__[name]
136

137
    def update(self, comp, cmp_fn, testname):
138
        for name in self.get_metrics():
139 140 141 142 143
            current = self.__dict__[name]
            if type(current) != tuple:
                current = (0, 0, 0)
            if cmp_fn(current, comp.__dict__[name]):
                self.__dict__[name] = comp.__dict__[name]
144
                self._minmax_testname[name] = testname
145 146

    def update_max(self, comp):
147
        for name in self.get_metrics():
148 149 150 151 152 153 154
            current = self.__dict__[name]
            if type(current) == tuple:
                current = self.__dict__[name][0]
            if comp.__dict__[name][0] > current:
                self.__dict__[name] = comp.__dict__[name]

    def update_min(self, comp):
155
        for name in self.get_metrics():
156 157 158 159 160 161 162
            current = self.__dict__[name]
            if type(current) == tuple:
                current = self.__dict__[name][0]
            if comp.__dict__[name][0] < current:
                self.__dict__[name] = comp.__dict__[name]

    def update_increase(self, comp):
163
        for name in self.get_metrics():
164 165 166 167
            if comp.__dict__[name][0] > 0:
                self.__dict__[name] += 1

    def update_decrease(self, comp):
168
        for name in self.get_metrics():
169 170 171 172
            if comp.__dict__[name][0] < 0:
                self.__dict__[name] += 1

    def is_empty(self):
173
        for name in self.get_metrics():
174 175 176 177 178 179
            x = self.__dict__[name]
            if type(x) == tuple and x[0] is not 0:
                return False
            if type(x) != tuple and x is not 0:
                return False
        return True
180 181


182
class si_parser(object):
183 184 185 186 187 188 189 190 191 192 193
    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]+)"),
        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]+)"),
    ]

194
    re_nop = re.compile("^\ts_nop ([0-9]+)")
195

196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    def __init__(self):
        self._stats = None
        self._in_disasm = False

    def finish(self):
        return self._stats

    def parse(self, msg):
        if not self._in_disasm:
            if msg == "Shader Disassembly Begin":
                old_stats = self._stats
                self._stats = si_stats()
                self._in_disasm = True
                return old_stats

211 212 213 214 215
            for re in si_parser.re_stats:
                match = re.match(msg)
                if match is not None:
                    break

216
            if match is not None:
217 218
                if self._stats == None:
                    self._stats = si_stats()
219 220
                self._stats.sgprs = int(match.group(1))
                self._stats.vgprs = int(match.group(2))
221 222
                self._stats.spilled_sgprs = int(match.group(7))
                self._stats.spilled_vgprs = int(match.group(8))
223
                self._stats.privmem_vgprs = int(match.group(9)) if match.lastindex >= 9 else 0
224 225
                self._stats.code_size = int(match.group(3))
                self._stats.lds = int(match.group(4))
226
                self._stats.scratch_size = int(match.group(5)) / (64 * 4)
227
                self._stats.maxwaves = int(match.group(6))
228 229 230
                old_stats = self._stats
                self._stats = None
                return old_stats
231 232 233 234 235 236 237 238 239

            if msg == "LLVM compile failed":
                old_stats = self._stats
                self._stats = None

                if old_stats is None:
                    old_stats = si_stats()
                old_stats.error = True
                return old_stats
240 241 242 243
        else:
            if msg == "Shader Disassembly End":
                self._in_disasm = False
                return None
244

245 246 247 248
            match = si_parser.re_nop.match(msg)
            if match:
                self._stats.waitstates += 1 + int(match.groups()[0])
                return None
249

250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
def get_results(filename):
    """
    Returns a dictionary that maps shader_test names to lists of si_stats
    (corresponding to the different shaders within the test's programs).
    """
    results = defaultdict(list)
    parsers = defaultdict(si_parser)

    with open(filename, "r") as file:
        re_line = re.compile(r"^(.+\.shader_test) - (.*)$")

        for line in file:
            match = re_line.match(line)
            if match is None:
                continue

            name = match.group(1)
            message = match.group(2)

            stats = parsers[name].parse(message)
            if stats is not None:
                results[name].append(stats)

    for name, parser in parsers.items():
        stats = parser.finish()
        if stats is not None:
            print "Results for", name, "not fully parsed!"
            results[name].append(stats)
278 279 280 281 282 283

    return results


def compare_stats(before, after):
    result = si_stats()
284
    for name in result.get_metrics():
285 286 287 288 289
        b = before.__dict__[name]
        a = after.__dict__[name]
        result.__dict__[name] = (a - b, b, a)
    return result

290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305
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_regression(before, after):
    for field in before.get_metrics():
        if field == 'maxwaves':
            if before.__dict__[field] > after.__dict__[field]:
                return True
        else:
            if before.__dict__[field] < after.__dict__[field]:
                return True
    return False

306 307
def divide_stats(num, div):
    result = si_stats()
308
    for name in result.get_metrics():
309 310 311 312 313 314 315 316
        if div.__dict__[name] == 0:
            result.__dict__[name] = num.__dict__[name]
        else:
            result.__dict__[name] = 100.0 * float(num.__dict__[name]) / float(div.__dict__[name])
    return result

def print_before_after_stats(before, after, divisor = 1):
    result = si_stats()
317
    for name in result.get_metrics():
318 319 320 321 322 323 324 325 326 327 328
        b = before.__dict__[name] / divisor
        a = after.__dict__[name] / divisor
        if b == 0:
            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)

    print result

def print_cmp_stats(comp):
329
    result = comp.copy()
330
    for name in result.get_metrics():
331
        if type(result.__dict__[name]) != tuple:
332 333 334
            a = 0
            b = 0
        else:
335 336
            b = result.__dict__[name][1]
            a = result.__dict__[name][2]
337 338 339 340 341 342 343 344 345 346 347
        if b == 0:
            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)

    print result


def print_count(stats, divisor):
    result = si_stats()
348
    for name in result.get_metrics():
349 350 351 352 353
        count = stats.__dict__[name]
        percent = float(count) / float(divisor)
        result.__dict__[name] = '{} ({})'.format(get_str(count,''), get_str(percent))
    print result.to_string(False)

354
def compare_results(before_all_results, after_all_results):
355 356 357 358 359 360 361 362 363 364 365 366
    total_before = si_stats()
    total_after = si_stats()
    total_affected_before = si_stats()
    total_affected_after = si_stats()
    increases = si_stats()
    decreases = si_stats()
    max_increase_per = si_stats()
    max_decrease_per = si_stats()
    max_increase_unit = si_stats()
    max_decrease_unit = si_stats()

    num_affected = 0
367 368
    num_tests = 0
    num_shaders = 0
369 370
    num_after_errors = 0
    num_before_errors = 0
371 372 373 374 375 376

    all_names = set(itertools.chain(before_all_results.keys(), after_all_results.keys()))

    only_after_names = []
    only_before_names = []
    count_mismatch_names = []
377
    errors_names = []
378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393

    for name in all_names:
        before_test_results = before_all_results.get(name)
        after_test_results = after_all_results.get(name)

        if before_test_results is None:
            only_after_names.append(name)
            continue
        if after_test_results is None:
            only_before_names.append(name)
            continue

        if len(before_test_results) != len(after_test_results):
            count_mismatch_names.append(name)

        num_tests += 1
394
        have_error = False
395 396

        for before, after in zip(before_test_results, after_test_results):
397 398 399 400 401 402 403 404
            if before.error:
                num_before_errors += 1
            if after.error:
                num_after_errors += 1
            if after.error or before.error:
                have_error = True
                continue

405 406 407 408 409 410 411 412 413 414 415
            total_before.add(before)
            total_after.add(after)
            num_shaders += 1

            comp = compare_stats(before, after)
            if not comp.is_empty():
                num_affected += 1
                total_affected_before.add(before)
                total_affected_after.add(after)
                increases.update_increase(comp)
                decreases.update_decrease(comp)
416 417 418 419
                max_increase_per.update(comp, cmp_max_per, name)
                max_decrease_per.update(comp, cmp_min_per, name)
                max_increase_unit.update(comp, cmp_max_unit, name)
                max_decrease_unit.update(comp, cmp_min_unit, name)
420

421 422 423
        if have_error:
            errors_names.append(name)

424
    print '{} shaders in {} tests'.format(num_shaders, num_tests)
425 426 427
    if num_shaders == 0:
        return

428 429 430 431 432
    print "Totals:"
    print_before_after_stats(total_before, total_after)
    print "Totals from affected shaders:"
    print_before_after_stats(total_affected_before, total_affected_after)
    print "Increases:"
433
    print_count(increases, num_shaders)
434
    print "Decreases:"
435
    print_count(decreases, num_shaders)
436 437 438 439 440 441 442 443 444 445 446 447 448

    print "*** BY PERCENTAGE ***\n"
    print "Max Increase:\n"
    print_cmp_stats(max_increase_per)
    print "Max Decrease:\n"
    print_cmp_stats(max_decrease_per)

    print "*** BY UNIT ***\n"
    print "Max Increase:\n"
    print_cmp_stats(max_increase_unit)
    print "Max Decrease:\n"
    print_cmp_stats(max_decrease_unit)

449 450
    def report_ignored(names, what):
        if names:
451
            print "*** {} are ignored:".format(what)
452 453 454 455 456
            s = ', '.join(names[:5])
            if len(names) > 5:
                s += ', and {} more'.format(len(names) - 5)
            print s

457 458 459 460 461 462 463
    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)
464

465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483
class grouped_stats:
    def __init__(self):
        self.num_shaders = 0
        self.before = si_stats()
        self.after = si_stats()
        self.diff = si_stats()

    def add(self, before, after):
        self.num_shaders += 1
        self.before.add(before)
        self.after.add(after)

    def set_one_shader(self, before, after):
        self.before = before
        self.after = after
        self.diff = subtract_stats(after, before)

    def print_vgpr_spilling_app(self, name):
        if (self.after.spilled_vgprs > 0 or
484
            self.after.privmem_vgprs > 0):
485
            print " {:6}{:6}     {:6}   {:6}   {:22}".format(
486 487
                self.num_shaders,
                self.after.spilled_vgprs,
488
                self.after.privmem_vgprs,
489 490
                self.after.scratch_size,
                name)
491 492 493

    def print_one_shader_vgpr_spill(self, name):
        if (self.after.spilled_vgprs > 0 or
494
            self.after.privmem_vgprs > 0):
495
            print " {:6}{:6}{:6}   {:6}    {:22}".format(
496 497
                self.after.vgprs,
                self.after.spilled_vgprs,
498
                self.after.privmem_vgprs,
499 500
                self.after.scratch_size,
                name)
501 502 503

    def print_sgpr_spilling_app(self, name):
        if self.after.spilled_sgprs > 0:
504
            print " {:6} {:6}     {:>5.1f}      {:22}".format(
505 506
                self.num_shaders,
                self.after.spilled_sgprs,
507 508
                float(self.after.spilled_sgprs) / float(self.num_shaders),
                name)
509 510 511

    def print_one_shader_sgpr_spill(self, name):
        if self.after.spilled_sgprs > 0:
512
            print " {:6}{:6}   {:90}".format(
513
                self.after.sgprs,
514 515
                self.after.spilled_sgprs,
                name)
516 517

    def print_percentages(self, name):
518 519 520 521 522 523 524 525 526 527 528 529 530 531
        print " {:6}{:6}{}{}{}{}{}{}{}{}{}".format(
            name,
            self.num_shaders,
            format_percent_change(self.before.sgprs, self.after.sgprs),
            format_percent_change(self.before.vgprs, self.after.vgprs),
            format_percent_change(self.before.spilled_sgprs, self.after.spilled_sgprs),
            format_percent_change(self.before.spilled_vgprs, self.after.spilled_vgprs),
            format_percent_change(self.before.privmem_vgprs, self.after.privmem_vgprs),
            format_percent_change(self.before.scratch_size, self.after.scratch_size),
            format_percent_change(self.before.code_size, self.after.code_size),
            format_percent_change(self.before.maxwaves, self.after.maxwaves, more_is_better = True),
            format_percent_change(self.before.waitstates, self.after.waitstates))

    def print_percentages_end(self, name):
532
        print " {:22}{:6}{}{}{}{}{}{}{}{}{}".format(
533 534 535 536 537 538
            name,
            self.num_shaders,
            format_percent_change(self.before.sgprs, self.after.sgprs),
            format_percent_change(self.before.vgprs, self.after.vgprs),
            format_percent_change(self.before.spilled_sgprs, self.after.spilled_sgprs),
            format_percent_change(self.before.spilled_vgprs, self.after.spilled_vgprs),
539
            format_percent_change(self.before.privmem_vgprs, self.after.privmem_vgprs),
540
            format_percent_change(self.before.scratch_size, self.after.scratch_size),
541 542 543 544 545
            format_percent_change(self.before.code_size, self.after.code_size),
            format_percent_change(self.before.maxwaves, self.after.maxwaves, more_is_better = True),
            format_percent_change(self.before.waitstates, self.after.waitstates))

    def print_regression(self, name, field):
546
        more_is_better = field == "maxwaves"
547
        print " {:6}{:6}{}{}   {:90}".format(
548 549
            self.before.__dict__[field],
            self.after.__dict__[field],
550 551 552
            format_table_cell(self.after.__dict__[field] - self.before.__dict__[field],
                              more_is_better = more_is_better),
            format_percent_change(self.before.__dict__[field], self.after.__dict__[field],
553 554
                                  more_is_better = more_is_better),
            name)
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574

"""
Return "filename [index]", because files can contain multiple shaders.
"""
def get_shader_name(list, orig):
    for i in range(10):
        # add the index to the name
        name = orig + " [{}]".format(i)
        if name not in list:
                return name
    assert False
    return "(error)"


def print_yellow(str):
    print set_yellow + str + set_normal

def print_tables(before_all_results, after_all_results):
    re_app = re.compile(r"^.*/([^/]+)/[^/]+$")

575
    num_listed = 40
576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612
    apps = defaultdict(grouped_stats)
    shaders = defaultdict(grouped_stats)
    total = grouped_stats()
    total_affected = grouped_stats()

    all_files = set(itertools.chain(before_all_results.keys(),
                                    after_all_results.keys()))

    for file in all_files:
        # get the application name (inner-most directory)
        match_app = re_app.match(file)
        if match_app is None:
            app = "(unknown)"
        else:
            app = match_app.group(1)
        if len(app) > 22:
            app = app[0:19] + ".."

        before_test_results = before_all_results.get(file)
        after_test_results = after_all_results.get(file)

        if before_test_results is None or after_test_results is None:
            continue

        for before, after in zip(before_test_results, after_test_results):
            if after.error or before.error:
                continue

            apps[app].add(before, after)
            total.add(before, after)

            if not subtract_stats(before, after).is_empty():
                total_affected.add(before, after)

            # we don't have to add all shaders, just those that we may need
            # to display
            if (is_regression(before, after) or
613
                after.scratch_size > 0 or
614
                after.spilled_vgprs > 0 or
615
                after.privmem_vgprs > 0 or
616 617 618 619 620 621
                after.spilled_sgprs > 0):
                name = get_shader_name(shaders, file)
                shaders[name].set_one_shader(before, after)

    # worst VGPR spills
    num = 0
622
    sort_key = lambda v: -v[1].after.scratch_size
623 624
    for name, stats in sorted(shaders.items(), key = sort_key):
        if num == 0:
625 626
            print_yellow("WORST VGPR SPILLS (not deltas)" + (" " * 64))
            print_yellow("  VGPRs Spills Private Scratch")
627 628
        stats.print_one_shader_vgpr_spill(name)
        num += 1
629
        if num == num_listed:
630 631 632 633 634
            break
    if num > 0:
        print

    # VGPR spilling apps
635
    print_yellow("VGPR SPILLING APPS\nShaders SpillVGPR  PrivVGPR ScratchSize")
636 637 638 639 640 641 642 643 644
    for name, stats in sorted(apps.items()):
        stats.print_vgpr_spilling_app(name)
    print

    # worst SGPR spills
    num = 0
    sort_key = lambda v: -v[1].after.spilled_sgprs
    for name, stats in sorted(shaders.items(), key = sort_key):
        if num == 0:
645 646
            print_yellow("WORST SGPR SPILLS (not deltas)" + (" " * 64))
            print_yellow("  SGPRs Spills")
647 648
        stats.print_one_shader_sgpr_spill(name)
        num += 1
649
        if num == num_listed:
650 651 652 653 654
            break
    if num > 0:
        print

    # SGPR spilling apps
655
    print_yellow(" SGPR SPILLING APPS\nShaders SpillSGPR AvgPerSh")
656 657 658 659 660 661 662 663 664
    for name, stats in sorted(apps.items()):
        stats.print_sgpr_spilling_app(name)
    print

    # worst regressions
    metrics = si_stats().metrics
    for i in range(len(metrics)):
        field = metrics[i][0]
        num = 0
665 666 667 668 669 670
        more_is_better = metrics[i][0] == 'maxwaves'

        if more_is_better:
            sort_key = lambda v: v[1].diff.__dict__[field]
        else:
            sort_key = lambda v: -v[1].diff.__dict__[field]
671 672

        for name, stats in sorted(shaders.items(), key = sort_key):
673 674 675 676 677 678
            if more_is_better:
                if stats.diff.__dict__[field] >= 0:
                    continue
            else:
                if stats.diff.__dict__[field] <= 0:
                    continue
679 680

            if num == 0:
681 682 683 684 685 686 687 688
                print_yellow(" WORST REGRESSIONS - {:64}".format(metrics[i][1]))
                print_yellow(" Before After     Delta Percentage")
            stats.print_regression(name, field)
            num += 1
            if num == num_listed:
                break
        if num > 0:
            print
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712

    # biggest improvements
    metrics = si_stats().metrics
    for i in range(len(metrics)):
        field = metrics[i][0]
        num = 0
        more_is_better = metrics[i][0] == 'maxwaves'

        if more_is_better:
            sort_key = lambda v: -v[1].diff.__dict__[field]
        else:
            sort_key = lambda v: v[1].diff.__dict__[field]

        for name, stats in sorted(shaders.items(), key = sort_key):
            if more_is_better:
                if stats.diff.__dict__[field] <= 0:
                    continue
            else:
                if stats.diff.__dict__[field] >= 0:
                    continue

            if num == 0:
                print_yellow(" BIGGEST IMPROVEMENTS - {:64}".format(metrics[i][1]))
                print_yellow(" Before After     Delta Percentage")
713 714
            stats.print_regression(name, field)
            num += 1
715
            if num == num_listed:
716 717 718 719 720
                break
        if num > 0:
            print

    # percentages
721
    legend = "Shaders     SGPRs     VGPRs SpillSGPR SpillVGPR  PrivVGPR   Scratch  CodeSize  MaxWaves     Waits"
722 723
    print_yellow(" PERCENTAGE DELTAS    " + legend)
    for name, stats in sorted(apps.items()):
724
        stats.print_percentages_end(name)
725
    print " " + ("-" * (21 + len(legend)))
726
    total_affected.print_percentages_end("All affected")
727
    print " " + ("-" * (21 + len(legend)))
728
    total.print_percentages_end("Total")
729 730
    print

731 732 733 734
def main():
    before = sys.argv[1]
    after = sys.argv[2]

735 736 737 738 739
    results_before = get_results(before)
    results_after = get_results(after)

    compare_results(results_before, results_after)
    print_tables(results_before, results_after)
740 741 742

if __name__ == "__main__":
    main()