13ad841b2Smrg#!/usr/bin/env python3 23ad841b2Smrg 33ad841b2Smrg# This file is part of GCC. 43ad841b2Smrg# 53ad841b2Smrg# GCC is free software; you can redistribute it and/or modify it under 63ad841b2Smrg# the terms of the GNU General Public License as published by the Free 73ad841b2Smrg# Software Foundation; either version 3, or (at your option) any later 83ad841b2Smrg# version. 93ad841b2Smrg# 103ad841b2Smrg# GCC is distributed in the hope that it will be useful, but WITHOUT ANY 113ad841b2Smrg# WARRANTY; without even the implied warranty of MERCHANTABILITY or 123ad841b2Smrg# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 133ad841b2Smrg# for more details. 143ad841b2Smrg# 153ad841b2Smrg# You should have received a copy of the GNU General Public License 163ad841b2Smrg# along with GCC; see the file COPYING3. If not see 173ad841b2Smrg# <http://www.gnu.org/licenses/>. */ 183ad841b2Smrg 193ad841b2Smrgimport sys 203ad841b2Smrgimport os 213ad841b2Smrgimport subprocess 223ad841b2Smrgimport tempfile 233ad841b2Smrgimport argparse 243ad841b2Smrg 253ad841b2Smrgscript_location = os.path.realpath(__file__) 263ad841b2Smrg 273ad841b2Smrgparser = argparse.ArgumentParser() 283ad841b2Smrgparser.add_argument('location', metavar = 'dump_file', 293ad841b2Smrg help = 'Location with SPEC benchmarks') 303ad841b2Smrgparser.add_argument('-s', '--sorting', dest = 'sorting', 313ad841b2Smrg choices = ['branches', 'branch-hitrate', 'hitrate', 'coverage', 'name'], 323ad841b2Smrg default = 'branches') 33*cef8759bSmrgparser.add_argument('-d', '--def-file', help = 'path to predict.def') 343ad841b2Smrg 353ad841b2Smrgargs = parser.parse_args() 363ad841b2Smrg 373ad841b2Smrgbenchmarks = os.listdir(args.location) 383ad841b2Smrg 393ad841b2Smrgfor b in sorted(benchmarks): 403ad841b2Smrg dumps = [] 413ad841b2Smrg for root, dirs, files in os.walk(os.path.join(args.location, b)): 423ad841b2Smrg for x in files: 433ad841b2Smrg if x.endswith('.profile'): 443ad841b2Smrg dumps.append(os.path.join(root, x)) 453ad841b2Smrg 463ad841b2Smrg if len(dumps) == 0: 473ad841b2Smrg continue 483ad841b2Smrg 493ad841b2Smrg temp = tempfile.NamedTemporaryFile(delete = False) 503ad841b2Smrg for d in dumps: 513ad841b2Smrg temp.write(open(d, 'rb').read()) 523ad841b2Smrg 533ad841b2Smrg temp.close() 543ad841b2Smrg 553ad841b2Smrg print() 563ad841b2Smrg print(b) 573ad841b2Smrg sys.stdout.flush() 583ad841b2Smrg p = [os.path.join(os.path.dirname(script_location), 'analyze_brprob.py'), 593ad841b2Smrg temp.name, '--sorting', args.sorting] 60*cef8759bSmrg if args.def_file != None: 61*cef8759bSmrg p += ['-d', args.def_file] 62*cef8759bSmrg 633ad841b2Smrg p = subprocess.check_call(p) 643ad841b2Smrg sys.stdout.flush() 653ad841b2Smrg 663ad841b2Smrg os.remove(temp.name) 67