blob: bcb661c581297bd3ed11add4d3d54f09b00b5433 [file] [log] [blame]
James Bentone38b98a2012-07-25 13:52:14 +01001#!/usr/bin/env python
2##########################################################################
3#
4# Copyright 2012 VMware, Inc.
5# All Rights Reserved.
6#
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:
13#
14# The above copyright notice and this permission notice shall be included in
15# all copies or substantial portions of the Software.
16#
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
23# THE SOFTWARE.
24#
25##########################################################################/
26
José Fonsecab7634e42012-08-06 17:35:06 +010027
James Bentone38b98a2012-07-25 13:52:14 +010028import sys
29
James Bentone38b98a2012-07-25 13:52:14 +010030
José Fonsecab7634e42012-08-06 17:35:06 +010031def process(stream):
32 times = {}
James Benton91aed522012-07-31 14:11:14 +010033
José Fonsecab7634e42012-08-06 17:35:06 +010034 # frame_begin no gpu_start cpu_start
35 # frame_end no gpu_end gpu_dura cpu_end cpu_dura
36 # call no gpu_start gpu_dura cpu_start cpu_dura pixels program name
James Bentone38b98a2012-07-25 13:52:14 +010037
José Fonsecab7634e42012-08-06 17:35:06 +010038 for line in stream:
39 words = line.split(' ')
James Bentone38b98a2012-07-25 13:52:14 +010040
José Fonsecab7634e42012-08-06 17:35:06 +010041 if line.startswith('#'):
42 continue
James Bentone38b98a2012-07-25 13:52:14 +010043
José Fonsecab7634e42012-08-06 17:35:06 +010044 if words[0] == 'call':
45 id = long(words[1])
46 duration = long(words[3])
47 shader = long(words[7])
48 func = words[8]
James Bentone38b98a2012-07-25 13:52:14 +010049
José Fonsecab7634e42012-08-06 17:35:06 +010050 if times.has_key(shader):
51 times[shader]['draws'] += 1
52 times[shader]['duration'] += duration
James Benton91aed522012-07-31 14:11:14 +010053
José Fonsecab7634e42012-08-06 17:35:06 +010054 if duration > times[shader]['longestDuration']:
55 times[shader]['longest'] = id
56 times[shader]['longestDuration'] = duration
57 else:
58 times[shader] = {'draws': 1, 'duration': duration, 'longest': id, 'longestDuration': duration}
James Bentone38b98a2012-07-25 13:52:14 +010059
José Fonsecab7634e42012-08-06 17:35:06 +010060 times = sorted(times.items(), key=lambda x: x[1]['duration'], reverse=True)
James Bentone38b98a2012-07-25 13:52:14 +010061
José Fonsecab7634e42012-08-06 17:35:06 +010062 print '+------------+--------------+--------------------+--------------+-------------+'
63 print '| Shader[id] | Draws [#] | Duration [ns] v | Per Call[ns] | Longest[id] |'
64 print '+------------+--------------+--------------------+--------------+-------------+'
James Bentone38b98a2012-07-25 13:52:14 +010065
José Fonsecab7634e42012-08-06 17:35:06 +010066 for shader in times:
67 id = str(shader[0]).rjust(10)
68 draw = str(shader[1]['draws']).rjust(12)
69 dura = str(shader[1]['duration']).rjust(18)
70 perCall = str(shader[1]['duration'] / shader[1]['draws']).rjust(12)
71 longest = str(shader[1]['longest']).rjust(11)
72 print "| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest)
James Bentone38b98a2012-07-25 13:52:14 +010073
José Fonsecab7634e42012-08-06 17:35:06 +010074 print '+------------+--------------+--------------------+--------------+-------------+'
75
76
77def main():
78 if len(sys.argv) > 1:
79 for arg in sys.argv[1:]:
80 process(open(arg, 'rt'))
81 else:
82 process(sys.stdin)
83
84
85if __name__ == '__main__':
86 main()