analyze_brprob_spec.py 2.1 KB

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