blob: 04e219d38c8c82ddd28ae9dc986b3bd12a260d85 [file] [log] [blame]
James Bentone38b98a2012-07-25 13:52:14 +01001#!/usr/bin/env python
2##########################################################################
3#
José Fonseca5df4a3e2013-10-18 17:31:21 -07004# Copyright 2012-2013 VMware, Inc.
James Bentone38b98a2012-07-25 13:52:14 +01005# 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
José Fonseca5df4a3e2013-10-18 17:31:21 -070028import optparse
James Bentone38b98a2012-07-25 13:52:14 +010029import sys
30
James Bentone38b98a2012-07-25 13:52:14 +010031
José Fonsecab7634e42012-08-06 17:35:06 +010032def process(stream):
33 times = {}
James Benton91aed522012-07-31 14:11:14 +010034
José Fonseca5df4a3e2013-10-18 17:31:21 -070035 # Read header describing fields
36 header = stream.readline()
37 assert header.startswith('#')
38 header = header.rstrip('\r\n')
39
40 fields = header.split(' ')[1:]
41 columns = {}
42 for column in range(len(fields)):
43 columns[fields[column]] = column
44
45 callCol = columns['call']
46 callIdCol = columns['no']
47 gpuDuraCol = columns['gpu_dura']
48 programCol = columns['program']
49 funcNameCol = columns['name']
James Bentone38b98a2012-07-25 13:52:14 +010050
José Fonsecab7634e42012-08-06 17:35:06 +010051 for line in stream:
José Fonseca5df4a3e2013-10-18 17:31:21 -070052 fields = line.split(' ')
James Bentone38b98a2012-07-25 13:52:14 +010053
José Fonsecab7634e42012-08-06 17:35:06 +010054 if line.startswith('#'):
55 continue
James Bentone38b98a2012-07-25 13:52:14 +010056
José Fonseca5df4a3e2013-10-18 17:31:21 -070057 if fields[callCol] == 'call':
58 callId = long(fields[callIdCol])
59 duration = long(fields[gpuDuraCol])
60 shader = long(fields[programCol])
61 func = fields[funcNameCol]
James Bentone38b98a2012-07-25 13:52:14 +010062
José Fonsecab7634e42012-08-06 17:35:06 +010063 if times.has_key(shader):
64 times[shader]['draws'] += 1
65 times[shader]['duration'] += duration
James Benton91aed522012-07-31 14:11:14 +010066
José Fonsecab7634e42012-08-06 17:35:06 +010067 if duration > times[shader]['longestDuration']:
José Fonseca5df4a3e2013-10-18 17:31:21 -070068 times[shader]['longest'] = callId
José Fonsecab7634e42012-08-06 17:35:06 +010069 times[shader]['longestDuration'] = duration
70 else:
José Fonseca5df4a3e2013-10-18 17:31:21 -070071 times[shader] = {'draws': 1, 'duration': duration, 'longest': callId, 'longestDuration': duration}
James Bentone38b98a2012-07-25 13:52:14 +010072
José Fonsecab7634e42012-08-06 17:35:06 +010073 times = sorted(times.items(), key=lambda x: x[1]['duration'], reverse=True)
James Bentone38b98a2012-07-25 13:52:14 +010074
José Fonsecab7634e42012-08-06 17:35:06 +010075 print '+------------+--------------+--------------------+--------------+-------------+'
76 print '| Shader[id] | Draws [#] | Duration [ns] v | Per Call[ns] | Longest[id] |'
77 print '+------------+--------------+--------------------+--------------+-------------+'
James Bentone38b98a2012-07-25 13:52:14 +010078
José Fonsecab7634e42012-08-06 17:35:06 +010079 for shader in times:
80 id = str(shader[0]).rjust(10)
81 draw = str(shader[1]['draws']).rjust(12)
82 dura = str(shader[1]['duration']).rjust(18)
83 perCall = str(shader[1]['duration'] / shader[1]['draws']).rjust(12)
84 longest = str(shader[1]['longest']).rjust(11)
85 print "| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest)
James Bentone38b98a2012-07-25 13:52:14 +010086
José Fonsecab7634e42012-08-06 17:35:06 +010087 print '+------------+--------------+--------------------+--------------+-------------+'
88
89
90def main():
José Fonseca5df4a3e2013-10-18 17:31:21 -070091
92 # Parse command line options
93 optparser = optparse.OptionParser(
94 usage='\n\t%prog [options] <profile_input>',
95 version='%%prog')
96
97 (options, args) = optparser.parse_args(sys.argv[1:])
98
99 if len(args):
100 for arg in args:
José Fonsecab7634e42012-08-06 17:35:06 +0100101 process(open(arg, 'rt'))
102 else:
103 process(sys.stdin)
104
105
106if __name__ == '__main__':
107 main()