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