2 ##########################################################################
4 # Copyright 2012 VMware, Inc.
7 # Permission is hereby granted, free of charge, to any person obtaining a copy
8 # of this software and associated documentation files (the "Software"), to deal
9 # in the Software without restriction, including without limitation the rights
10 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 # copies of the Software, and to permit persons to whom the Software is
12 # furnished to do so, subject to the following conditions:
14 # The above copyright notice and this permission notice shall be included in
15 # all copies or substantial portions of the Software.
17 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
25 ##########################################################################/
29 if len(sys.argv) <= 1:
30 print 'Please specify a file to read'
36 for line in open(sys.argv[1], 'r'):
37 words = line.split(' ')
39 if line.startswith('#'):
42 if words[0:3] == ['use','shader','program']:
43 activeShader = long(words[3])
44 elif words[0] == 'call':
47 duration = long(words[3])
49 if shaderTimes.has_key(activeShader):
50 shaderTimes[activeShader]['draws'] += 1
51 shaderTimes[activeShader]['duration'] += duration
52 if duration > shaderTimes[activeShader]['longestDuration']:
53 shaderTimes[activeShader]['longest'] = id
54 shaderTimes[activeShader]['longestDuration'] = duration
56 shaderTimes[activeShader] = {'draws': 1, 'duration': duration, 'longest': id, 'longestDuration': duration}
58 sortedShaderTimes = sorted(shaderTimes.items(), key=lambda x: x[1]['duration'], reverse=True)
60 print '+------------+--------------+--------------------+--------------+-------------+'
61 print '| Shader[id] | Draws [#] | Duration [ns] v | Per Call[ns] | Longest[id] |'
62 print '+------------+--------------+--------------------+--------------+-------------+'
64 for shader in sortedShaderTimes:
65 id = str(shader[0]).rjust(10)
66 draw = str(shader[1]['draws']).rjust(12)
67 dura = str(shader[1]['duration']).rjust(18)
68 perCall = str(shader[1]['duration'] / shader[1]['draws']).rjust(12)
69 longest = str(shader[1]['longest']).rjust(11)
70 print "| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest)
72 print '+------------+--------------+--------------------+--------------+-------------+'