diff options
author | Eric Anholt <eric@anholt.net> | 2012-06-06 17:03:33 -0700 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2012-06-06 18:49:40 -0700 |
commit | aa4c13d372b9f0ada586e50bb324f36441fe7adf (patch) | |
tree | 84491514eb9471a67c0e354a8ee8da881c0b5db7 | |
parent | 8f9790319594262177c44ba6fefad085745af559 (diff) |
Convert the scripts to python and make them way better.
This one parses the 8/16 wide fs separately, writes test output to a
file, and handles ^C sanely.
-rwxr-xr-x | report.pl | 109 | ||||
-rwxr-xr-x | report.py | 144 | ||||
-rwxr-xr-x | run.pl | 20 | ||||
-rwxr-xr-x | run.py | 98 |
4 files changed, 242 insertions, 129 deletions
diff --git a/report.pl b/report.pl deleted file mode 100755 index 34838f3..0000000 --- a/report.pl +++ /dev/null @@ -1,109 +0,0 @@ -#!/usr/bin/env perl - -my $before_name = $ARGV[0]; -my $after_name = $ARGV[1]; - -if ($#ARGV != 1) { - printf("usage: report.pl <before> <after>\n"); -} - -open(BEFORE, $before_name) or die; -open(AFTER, $after_name) or die; - -my %before = (); -my %after = (); - -my $total_programs_before; - -while (<BEFORE>) { - my $line = $_; - - $line =~ /(.*):(.*)/; - - $before{$1} = $2; - $total_programs_before++; -} - -while (<AFTER>) { - my $line = $_; - - $line =~ /(.*):(.*)/; - - $after{$1} = $2; -} - -delete $before{"total"}; -delete $after{"total"}; - -my $total_instructions_before = 0; -my $total_instructions_after = 0; -my $affected_programs_before = 0; -my $affected_instructions_before = 0; -my $affected_instructions_after = 0; - -my %hurt_programs = (); - -while (my ($prog, $before_count) = each(%before)) { - my $after_count = $after{$prog}; - if ($after_count == "") { - next; - } - - $total_instructions_before += $before_count; - $total_instructions_after += $after_count; - - if ($before_count == $after_count) { - next; - } - - if ($after_count > $before_count && $before_count != 0) { - $hurt_programs{$prog} = $after_count / $before_count; - } - - printf("%s: %4d -> %4d\n", - $prog, $before_count, $after_count); - - $affected_instructions_before += $before_count; - $affected_instructions_after += $after_count; - - $affected_programs_before++; -} - -printf("\n"); - -printf("Total instructions: %d -> %d\n", - $total_instructions_before, $total_instructions_after); - -printf("%d/%d programs affected (%.1f%%)\n", - $affected_programs_before, $total_programs_before, - 100 * $affected_programs_before / $total_programs_before); - -if ($affected_instructions_after < $affected_instructions_before) { - printf("%d -> %d instructions in affected programs (%.1f%% reduction)\n", - $affected_instructions_before, - $affected_instructions_after, - 100 - (100 * $affected_instructions_after / - $affected_instructions_before)); -} - -if ($affected_instructions_after > $affected_instructions_before) { - printf("%d -> %d instructions in affected programs (%.1f%% increase)\n", - $affected_instructions_before, - $affected_instructions_after, - (100 * $affected_instructions_after / - $affected_instructions_before) - 100); -} - -my $header = 0; - -if (keys(%hurt_programs) != 0) { - printf("hurt programs:\n"); - my @names = keys %hurt_programs; - my @sorted = sort { - $hurt_programs{$a} <=> $hurt_programs{$b} - } @names; - - foreach (@sorted) { - printf("%s: %.02f%%\n", $_, $hurt_programs{$_} * 100 - 100); - } -} diff --git a/report.py b/report.py new file mode 100755 index 0000000..5bb7a7b --- /dev/null +++ b/report.py @@ -0,0 +1,144 @@ +#!/usr/bin/env python + +from getopt import getopt, GetoptError +import re +import sys, os +import subprocess + +def usage(): + USAGE = """\ +Usage: %(progName)s <before> <after> + +Options: + -h, --help Show this message +""" + print USAGE % {'progName': sys.argv[0]} + sys.exit(1) + +def get_results(filename): + file = open(filename, "r") + lines = file.read().split('\n') + + results = {} + + re_match = re.compile("(\S*)\s*(\S*)\s*: (\S*)") + for line in lines: + match = re.search(re_match, line) + if match == None: + continue + + groups = match.groups() + count = int(groups[2]) + if count != 0: + results[(groups[0], groups[1])] = count + + return results + +def get_delta(b, a): + if b != 0 and a != 0: + frac = float(a) / float(b) - 1.0 + return ' ({:.2f}%)'.format(frac * 100.0) + else: + return '' + +def change(b, a): + return str(b) + " -> " + str(a) + get_delta(b, a) + +def get_result_string(p, b, a): + p = p + ": " + while len(p) < 50: + p = p + ' ' + return p + change(b, a) + +def main(): + try: + option_list = [ + "help", + ] + options, args = getopt(sys.argv[1:], "h", option_list) + except GetoptError: + usage() + + for name, value in options: + if name in ('-h', '--help'): + usage() + + if len(args) != 2: + usage() + + before = get_results(args[0]) + after = get_results(args[1]) + + total_before = 0 + total_after = 0 + affected_before = 0 + affected_after = 0 + + helped = [] + hurt = [] + lost = [] + gained = [] + for p in before: + (name, type) = p + namestr = name + " " + type + before_count = before[p] + + if after.get(p) != None: + after_count = after[p] + + total_before += before_count + total_after += after_count + + if before_count != after_count: + affected_before += before_count + affected_after += after_count + + result = get_result_string(namestr, before_count, after_count) + if after_count > before_count: + hurt.append(p) + else: + helped.append(result) + else: + lost.append(namestr) + + for p in after: + if (before.get(p) == None): + gained.append(p[0] + " " + p[1]) + + helped.sort() + for r in helped: + print "helped: " + r + if len(helped) > 0: + print "" + + def hurt_sort(k1, k2): + if (float(after[k1] - before[k1]) / before[k1] > + float(after[k2] - before[k2]) / before[k2]): + return 1 + else: + return -1 + + hurt.sort(cmp=hurt_sort) + for p in hurt: + namestr = p[0] + " " + p[1] + print "HURT: " + get_result_string(namestr, before[p], after[p]) + if len(hurt) > 0: + print "" + + lost.sort() + for p in lost: + print "LOST: " + p + if len(lost) > 0: + print "" + + gained.sort() + for p in gained: + print "GAINED: " + p + if len(gained) > 0: + print "" + + print "total instructions in shared programs: " + change(total_before, total_after) + print "instructions in affected programs: " + change(affected_before, affected_after) + +if __name__ == "__main__": + main() @@ -1,20 +0,0 @@ -#!/usr/bin/env perl - -$env = "env shader_precompile=true INTEL_DEBUG=wm,vs"; -$glslparsertest = "/home/anholt/src/piglit/bin/glslparsertest"; - -my $total = 0; -foreach my $filename (@ARGV) { - $output = `$env $glslparsertest $filename pass 2> /dev/null`; - - my $count = 0; - foreach my $line (split(/\n/, $output)) { - if ($line =~ /align1/) { - $count++; - } - } - printf("$filename: $count\n"); - - $total += $count; -} -printf("total: $total\n"); @@ -0,0 +1,98 @@ +#!/usr/bin/env python + +from getopt import getopt, GetoptError +import re +import sys, os +import subprocess + +def usage(): + USAGE = """\ +Usage: %(progName)s [shader.frag] [shader.vert] + +Options: + -h, --help Show this message +""" + print USAGE % {'progName': sys.argv[0]} + sys.exit(1) + +def run_test(filename): + command = ['/home/anholt/src/piglit/bin/glslparsertest', + filename, + 'pass'] + + env_add = {} + env_add["shader_precompile"] = "true" + env_add["INTEL_DEBUG"] = "vs,wm" + + env = os.environ.copy() + env.update(env_add) + + try: + p = subprocess.Popen( + command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + env=env) + except: + print filename + " FAIL" + return + + try: + (stdout, stderr) = p.communicate() + results = stdout + stderr + except KeyboardInterrupt: + exit(1) + except: + print filename + " FAIL " + return + + with open(filename + '.out', 'w') as file: + file.write(results) + + current_type = 'UNKNOWN' + counts = {} + lines = list(results.split('\n')) + + re_fs_8 = re.compile("^Native code for fragment.*8-wide") + re_fs_16 = re.compile("^Native code for fragment.*16-wide") + re_vs = re.compile("^Native code for vertex") + re_align = re.compile("{ align") + counts["vs "] = 0 + counts["fs8 "] = 0 + counts["fs16"] = 0 + for line in lines: + if (re.search(re_vs, line)): + current_type = "vs " + elif (re.search(re_fs_8, line)): + current_type = "fs8 " + elif (re.search(re_fs_16, line)): + current_type = "fs16" + elif (re.search(re_align, line)): + counts[current_type] = counts[current_type] + 1 + + for t in counts: + if counts[t] != 0: + print filename + " " + t + ": " + str(counts[t]) + sys.stdout.flush() + +def main(): + try: + option_list = [ + "help", + ] + options, args = getopt(sys.argv[1:], "h", option_list) + except GetoptError: + usage() + + for name, value in options: + if name in ('-h', '--help'): + usage() + + if len(args) < 1: + usage() + + for filename in args: + run_test(filename) + +if __name__ == "__main__": + main() |