Clone of mesa.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

api_speed.py 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. #!/usr/bin/env python2
  2. # (C) Copyright IBM Corporation 2004
  3. # All Rights Reserved.
  4. #
  5. # Permission is hereby granted, free of charge, to any person obtaining a
  6. # copy of this software and associated documentation files (the "Software"),
  7. # to deal in the Software without restriction, including without limitation
  8. # on the rights to use, copy, modify, merge, publish, distribute, sub
  9. # license, and/or sell copies of the Software, and to permit persons to whom
  10. # the Software is furnished to do so, subject to the following conditions:
  11. #
  12. # The above copyright notice and this permission notice (including the next
  13. # paragraph) shall be included in all copies or substantial portions of the
  14. # Software.
  15. #
  16. # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. # FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
  19. # IBM AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  21. # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  22. # IN THE SOFTWARE.
  23. #
  24. # Authors:
  25. # Ian Romanick <idr@us.ibm.com>
  26. # This script is used to run api_speed against several different libGL
  27. # libraries and compare the results. See the show_usage function for more
  28. # details on how to use it.
  29. import re, os, sys, getopt
  30. class results:
  31. def process_file(self, f):
  32. self.cycles = {}
  33. self.iterations = -1
  34. for line in f.readlines():
  35. m = re.match("(\d+) calls to (.{20}) required (\d+) cycles.", line)
  36. if self.iterations != -1 and int(m.group(1)) != self.iterations:
  37. raise
  38. # This could be done with lstrip, but the version of
  39. # the Python library on my system doesn't have it.
  40. # The installed version of Python is quite old. :(
  41. temp = m.group(2)
  42. function_name = None
  43. for i in range(len(temp)):
  44. if temp[i] != ' ':
  45. function_name = temp[i:]
  46. break
  47. if function_name == None:
  48. raise
  49. self.cycles[ function_name ] = int(m.group(3))
  50. self.iterations = int(m.group(1))
  51. def show_results(self):
  52. for name in self.cycles:
  53. print "%s -> %f" % (name, float(self.cycles[name]) / self.iterations)
  54. def compare_results(self, other):
  55. for name in self.cycles:
  56. if other.cycles.has_key(name):
  57. a = float(self.cycles[name]) / float(self.iterations)
  58. b = float(other.cycles[name]) / float(other.iterations)
  59. if abs( a ) < 0.000001:
  60. print "a = %f, b = %f" % (a, b)
  61. else:
  62. p = (100.0 * b / a) - 100.0
  63. print "%- 20s %7.2f - %7.2f = % -6.2f (%+.1f%%)" % (name, a, b, a - b, p)
  64. return
  65. def make_execution_string(lib, iterations):
  66. if lib == None:
  67. return "./api_speed %u" % (iterations)
  68. else:
  69. return "LD_PRELOAD=%s ./api_speed %u" % (lib, iterations)
  70. def show_usage():
  71. print """Usage: %s [-i iterations] {library ...}
  72. The full path to one or more libGL libraries (including the full name of the
  73. library) can be included on the command-line. Each library will be tested,
  74. and the results compared. The first library listed will be used as the
  75. "base line" for all comparisons.""" % (sys.argv[0])
  76. sys.exit(1)
  77. if __name__ == '__main__':
  78. try:
  79. (args, trail) = getopt.getopt(sys.argv[1:], "i:")
  80. except Exception,e:
  81. show_usage()
  82. iterations = 1000000
  83. try:
  84. for (arg,val) in args:
  85. if arg == "-i":
  86. iterations = int(val)
  87. except Exception,e:
  88. show_usage()
  89. # If no libraries were specifically named, just run the test against
  90. # the default system libGL.
  91. if len(trail) == 0:
  92. trail.append(None)
  93. result_array = []
  94. names = []
  95. for lib in trail:
  96. s = make_execution_string( lib, iterations )
  97. r = results()
  98. r.process_file( os.popen(s) )
  99. names.append(lib)
  100. result_array.append(r)
  101. # If the test was only run against one library, just show the results
  102. # of the test run. Otherwise, compare each successive run against
  103. # the first run.
  104. if len( result_array ) == 1:
  105. result_array[0].show_results()
  106. else:
  107. for i in range(1, len( result_array )):
  108. print "%s vs. %s" % (names[0], names[i])
  109. result_array[0].compare_results( result_array[i] )
  110. print ""