starpu_fxt_number_events_to_names.py.in 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. # StarPU --- Runtime system for heterogeneous multicore architectures.
  4. #
  5. # Copyright (C) 2020-2021 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  6. #
  7. # StarPU is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU Lesser General Public License as published by
  9. # the Free Software Foundation; either version 2.1 of the License, or (at
  10. # your option) any later version.
  11. #
  12. # StarPU is distributed in the hope that it will be useful, but
  13. # WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. #
  16. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  17. #
  18. import sys
  19. """
  20. STARPU_FXT_EVENT_DEFINES is generated by configure and is the output of
  21. the following command:
  22. grep -E "#define\s+_STARPU_(MPI_)?FUT_" src/common/fxt.h mpi/src/starpu_mpi_fxt.h | grep 0x | grep -v 0x1 | cut -d : -f 2
  23. """
  24. fxt_codes_raw = """
  25. @STARPU_FXT_EVENT_DEFINES@
  26. """
  27. PROGNAME=sys.argv[0]
  28. number_events_path = None
  29. def usage():
  30. print("Convert event keys in number_events.data to event names")
  31. print("")
  32. print("Usage: %s <number_events.data path>" % PROGNAME)
  33. print("")
  34. print("Options:")
  35. print(" -h, --help display this help and exit")
  36. print(" -v, --version output version information and exit")
  37. print("")
  38. print("Report bugs to <@PACKAGE_BUGREPORT@>")
  39. sys.exit(1)
  40. if len(sys.argv) == 2:
  41. if sys.argv[1] == '-v' or sys.argv[1] == '--version':
  42. print("%s (@PACKAGE_NAME@) @PACKAGE_VERSION@" % PROGNAME)
  43. sys.exit(0)
  44. elif sys.argv[1] == '-h' or sys.argv[1] == '--help':
  45. usage()
  46. else:
  47. number_events_path = sys.argv[1]
  48. else:
  49. usage()
  50. def man():
  51. print("Sepecify file containing event stats")
  52. sys.exit(1)
  53. # Process fxt_code_raw content to ease the conversion:
  54. fxt_codes = dict()
  55. for line in fxt_codes_raw.split("\n"):
  56. elements = line.split()
  57. if len(elements) == 3:
  58. key = int(elements[2][2:], 16)
  59. assert key not in fxt_codes
  60. fxt_codes[key] = elements[1]
  61. # Convert content of the file:
  62. nb_events = 0
  63. with open(number_events_path, 'r') as f:
  64. for line in f:
  65. elements = line.split()
  66. if len(elements) == 2:
  67. key = int(elements[0][2:], 16)
  68. nb = int(elements[1])
  69. nb_events += nb
  70. if key in fxt_codes:
  71. print("%12d %s" % (nb, fxt_codes[key]))
  72. else:
  73. print("%12d %s" % (nb, elements[0]))
  74. print(" TOTAL: %d" % nb_events)