diff options
author | Eric Anholt <eric@anholt.net> | 2014-10-24 14:51:12 +0100 |
---|---|---|
committer | Eric Anholt <eric@anholt.net> | 2014-12-09 15:00:35 -0800 |
commit | 54e91e65b0d8b2a34d4760e100d7438700d03b9c (patch) | |
tree | 72537c27518dcdf9099ff3f9b43df81633d6e00b |
Import the scripts for running traces and comparing output.
These are derived from the shader-db scripts I wrote while at Intel,
but relying on the driver itself to provide the cooked information we
want.
-rwxr-xr-x | report.py | 154 | ||||
-rwxr-xr-x | run.py | 104 |
2 files changed, 258 insertions, 0 deletions
diff --git a/report.py b/report.py new file mode 100755 index 0000000..18e9323 --- /dev/null +++ b/report.py @@ -0,0 +1,154 @@ +#!/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, all_result_types): + file = open(filename, "r") + lines = file.read().split('\n') + + results = {} + + re_match = re.compile("(\S*)\s*(\S*)\s*:\s*(\S*)") + for line in lines: + m = re.match('SHADER-DB: (\S+): (\S+) prog (\S+): (\d+) (\S+)', line) + if m == None: + continue + + groups = m.groups() + + progname = groups[0] + shadertype = groups[1] + shadernumber = groups[2] + result_type = groups[4] + progtuple = (progname, shadertype, shadernumber, result_type) + results[progtuple] = int(groups[3]) + + all_result_types.add(result_type) + + 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() + + all_result_types = set() + + before = get_results(args[0], all_result_types) + after = get_results(args[1], all_result_types) + + total_before = {} + total_after = {} + affected_before = {} + affected_after = {} + + for t in all_result_types: + total_before[t] = 0 + total_after[t] = 0 + affected_before[t] = 0 + affected_after[t] = 0 + + helped = [] + hurt = [] + lost = [] + gained = [] + for p in before: + (progname, shadertype, shadernumber, result_type) = p + namestr = '{} {} {} {}'.format(progname, shadertype, shadernumber, result_type) + before_count = before[p] + + if after.get(p) != None: + after_count = after[p] + + total_before[result_type] += before_count + total_after[result_type] += after_count + + if before_count != after_count: + affected_before[result_type] += before_count + affected_after[result_type] += 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("") + + hurt.sort(key=lambda k: float(after[k] - before[k]) / before[k]) + for p in hurt: + (progname, shadertype, shadernumber, result_type) = p + namestr = '{} {} {} {}'.format(progname, shadertype, shadernumber, result_type) + 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("") + + for t in all_result_types: + print("total {} in shared programs: {}".format(t, change(total_before[t], total_after[t]))) + print("{} in affected programs: {}".format(t, change(affected_before[t], affected_after[t]))) + print("GAINED: {0}".format(len(gained))) + print("LOST: {0}".format(len(lost))) +if __name__ == "__main__": + main() @@ -0,0 +1,104 @@ +#!/usr/bin/env python3 + +from getopt import getopt, GetoptError +import re +import sys, os, time +import subprocess +from concurrent.futures import ThreadPoolExecutor +from multiprocessing import cpu_count + +def usage(): + USAGE = """\ +Usage: %(progName)s <dir | apitrace.trace>... + +Options: + -h, --help Show this message +""" + print(USAGE % {'progName': sys.argv[0]}) + sys.exit(1) + +def process_directories(dirpath): + filenames = set() + if os.path.isdir(dirpath): + for filename in os.listdir(dirpath): + filenames.update(process_directories(os.path.join(dirpath, filename))) + else: + filenames.add(dirpath) + return filenames + +def run_test(filename): + basename = os.path.basename(filename) + m = re.match('(.*).trace', basename) + if m is None: + return "" + + command = ['apitrace', + 'replay', + '-b', + filename] + + progname = m.group(1) + timebefore = time.time() + + out="" + + try: + p = subprocess.Popen( + command, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + (stdout, stderr) = p.communicate() + results = (stdout + stderr).decode("utf-8") + except KeyboardInterrupt: + exit(1) + except: + out += 'SHADER-DB: {0}: FAIL'.format(progname) + + timeafter = time.time() + + lines = list(results.split('\n')) + for line in lines: + m = re.match("SHADER-DB: (.*)", line) + if m != None: + out += 'SHADER-DB: {0}: {1}\n'.format(progname, m.group(1)) + + out += 'SHADER-DB: {}: {:.3f} secs\n'.format(progname, timeafter - timebefore) + return out + +def main(): + try: + option_list = [ + "help", + ] + options, args = getopt(sys.argv[1:], "h", option_list) + except GetoptError: + usage() + + env_add = {} + env_add["VC4_DEBUG=shaderdb,norast"] = "true" + env_add["force_glsl_extensions_warn"] = "true" + + os.environ.update(env_add) + + for name, value in options: + if name in ('-h', '--help'): + usage() + + if len(args) < 1: + args.append("traces") + + runtimebefore = time.time() + + filenames = set() + for i in args: + filenames.update(process_directories(i)) + + executor = ThreadPoolExecutor(cpu_count()) + for t in executor.map(run_test, filenames): + sys.stdout.write(t) + + runtimeafter = time.time() + print("shader-db run completed in {:.1f} secs".format(runtimeafter - runtimebefore)) + +if __name__ == "__main__": + main() |