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