1b17d1066Smrg#!/usr/bin/env python3 2b17d1066Smrg 3b17d1066Smrg# This file is part of GCC. 4b17d1066Smrg# 5b17d1066Smrg# GCC is free software; you can redistribute it and/or modify it under 6b17d1066Smrg# the terms of the GNU General Public License as published by the Free 7b17d1066Smrg# Software Foundation; either version 3, or (at your option) any later 8b17d1066Smrg# version. 9b17d1066Smrg# 10b17d1066Smrg# GCC is distributed in the hope that it will be useful, but WITHOUT ANY 11b17d1066Smrg# WARRANTY; without even the implied warranty of MERCHANTABILITY or 12b17d1066Smrg# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13b17d1066Smrg# for more details. 14b17d1066Smrg# 15b17d1066Smrg# You should have received a copy of the GNU General Public License 16b17d1066Smrg# along with GCC; see the file COPYING3. If not see 17b17d1066Smrg# <http://www.gnu.org/licenses/>. */ 18b17d1066Smrg 19b17d1066Smrgimport sys 20b17d1066Smrgimport os 21b17d1066Smrgimport subprocess 22b17d1066Smrgimport tempfile 23b17d1066Smrgimport argparse 24b17d1066Smrg 25b17d1066Smrgscript_location = os.path.realpath(__file__) 26b17d1066Smrg 27b17d1066Smrgparser = argparse.ArgumentParser() 28b17d1066Smrgparser.add_argument('location', metavar = 'dump_file', 29*b1e83836Smrg help = 'Sub-folder with SPEC benchmarks (e.g. Programming/cpu2017/benchspec/CPU)') 30b17d1066Smrgparser.add_argument('-s', '--sorting', dest = 'sorting', 31b17d1066Smrg choices = ['branches', 'branch-hitrate', 'hitrate', 'coverage', 'name'], 32b17d1066Smrg default = 'branches') 33a3e9eb18Smrgparser.add_argument('-d', '--def-file', help = 'path to predict.def') 34*b1e83836Smrgparser.add_argument('-v', '--verbose', action = 'store_true', help = 'Print verbose informations') 35b17d1066Smrg 36b17d1066Smrgargs = parser.parse_args() 37b17d1066Smrg 38b17d1066Smrgbenchmarks = os.listdir(args.location) 39b17d1066Smrg 40b17d1066Smrgfor b in sorted(benchmarks): 41b17d1066Smrg dumps = [] 42b17d1066Smrg for root, dirs, files in os.walk(os.path.join(args.location, b)): 43b17d1066Smrg for x in files: 44b17d1066Smrg if x.endswith('.profile'): 45b17d1066Smrg dumps.append(os.path.join(root, x)) 46b17d1066Smrg 47b17d1066Smrg if len(dumps) == 0: 48b17d1066Smrg continue 49b17d1066Smrg 50b17d1066Smrg temp = tempfile.NamedTemporaryFile(delete = False) 51b17d1066Smrg for d in dumps: 52b17d1066Smrg temp.write(open(d, 'rb').read()) 53b17d1066Smrg 54b17d1066Smrg temp.close() 55b17d1066Smrg 56b17d1066Smrg print() 57*b1e83836Smrg print(f' {b} '.center(160, '=')) 58b17d1066Smrg sys.stdout.flush() 59b17d1066Smrg p = [os.path.join(os.path.dirname(script_location), 'analyze_brprob.py'), 60b17d1066Smrg temp.name, '--sorting', args.sorting] 61*b1e83836Smrg if args.def_file: 62a3e9eb18Smrg p += ['-d', args.def_file] 63*b1e83836Smrg if args.verbose: 64*b1e83836Smrg p.append('-v') 65a3e9eb18Smrg 66b17d1066Smrg p = subprocess.check_call(p) 67b17d1066Smrg sys.stdout.flush() 68b17d1066Smrg 69b17d1066Smrg os.remove(temp.name) 70