blob: 7e8637eb61797c2660f98481488c8523e9aad85e [file] [log] [blame]
Jose Fonseca247e1fa2019-04-28 14:14:44 +01001#!/usr/bin/env python3
James Bentone38b98a2012-07-25 13:52:14 +01002##########################################################################
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é Fonsecaf8b8ba62013-10-18 17:45:49 -070032def process(stream, groupField):
José Fonsecab7634e42012-08-06 17:35:06 +010033 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('#')
José Fonseca5df4a3e2013-10-18 17:31:21 -070038
José Fonsecaf8b8ba62013-10-18 17:45:49 -070039 fields = header.rstrip('\r\n').split(' ')[1:]
José Fonseca5df4a3e2013-10-18 17:31:21 -070040 columns = {}
41 for column in range(len(fields)):
42 columns[fields[column]] = column
43
44 callCol = columns['call']
45 callIdCol = columns['no']
46 gpuDuraCol = columns['gpu_dura']
47 programCol = columns['program']
48 funcNameCol = columns['name']
James Bentone38b98a2012-07-25 13:52:14 +010049
José Fonsecaf8b8ba62013-10-18 17:45:49 -070050 groupCol = columns[groupField]
51
52 maxGroupLen = 0
53
José Fonsecab7634e42012-08-06 17:35:06 +010054 for line in stream:
José Fonsecaf8b8ba62013-10-18 17:45:49 -070055 fields = line.rstrip('\r\n').split(' ')
James Bentone38b98a2012-07-25 13:52:14 +010056
José Fonsecab7634e42012-08-06 17:35:06 +010057 if line.startswith('#'):
58 continue
James Bentone38b98a2012-07-25 13:52:14 +010059
José Fonseca5df4a3e2013-10-18 17:31:21 -070060 if fields[callCol] == 'call':
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010061 callId = int(fields[callIdCol])
62 duration = int(fields[gpuDuraCol])
José Fonsecaf8b8ba62013-10-18 17:45:49 -070063 group = fields[groupCol]
James Bentone38b98a2012-07-25 13:52:14 +010064
José Fonsecaf8b8ba62013-10-18 17:45:49 -070065 maxGroupLen = max(maxGroupLen, len(group))
James Benton91aed522012-07-31 14:11:14 +010066
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010067 if group in times:
José Fonsecaf8b8ba62013-10-18 17:45:49 -070068 times[group]['draws'] += 1
69 times[group]['duration'] += duration
70
71 if duration > times[group]['longestDuration']:
72 times[group]['longest'] = callId
73 times[group]['longestDuration'] = duration
José Fonsecab7634e42012-08-06 17:35:06 +010074 else:
José Fonsecaf8b8ba62013-10-18 17:45:49 -070075 times[group] = {'draws': 1, 'duration': duration, 'longest': callId, 'longestDuration': duration}
James Bentone38b98a2012-07-25 13:52:14 +010076
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010077 times = sorted(list(times.items()), key=lambda x: x[1]['duration'], reverse=True)
James Bentone38b98a2012-07-25 13:52:14 +010078
José Fonsecaf8b8ba62013-10-18 17:45:49 -070079 if groupField == 'program':
80 groupTitle = 'Shader[id]'
81 else:
82 groupTitle = groupField
83 maxGroupLen = max(maxGroupLen, len(groupTitle))
84 groupTitle = groupField.center(maxGroupLen)
85 groupLine = '-' * maxGroupLen
James Bentone38b98a2012-07-25 13:52:14 +010086
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010087 print('+-%s-+--------------+--------------------+--------------+-------------+' % groupLine)
88 print('| %s | Draws [#] | Duration [ns] v | Per Call[ns] | Longest[id] |' % groupTitle)
89 print('+-%s-+--------------+--------------------+--------------+-------------+' % groupLine)
José Fonsecaf8b8ba62013-10-18 17:45:49 -070090
91 for group in times:
92 id = str(group[0]).rjust(maxGroupLen)
93 draw = str(group[1]['draws']).rjust(12)
94 dura = str(group[1]['duration']).rjust(18)
Jose Fonsecaf5279242019-04-29 06:41:49 +010095 perCall = str(group[1]['duration'] // group[1]['draws']).rjust(12)
José Fonsecaf8b8ba62013-10-18 17:45:49 -070096 longest = str(group[1]['longest']).rjust(11)
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010097 print("| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest))
James Bentone38b98a2012-07-25 13:52:14 +010098
Piotr Podsiadły0b8b0192019-01-03 20:39:55 +010099 print('+-%s-+--------------+--------------------+--------------+-------------+' % groupLine)
José Fonsecab7634e42012-08-06 17:35:06 +0100100
101
102def main():
José Fonseca5df4a3e2013-10-18 17:31:21 -0700103
104 # Parse command line options
105 optparser = optparse.OptionParser(
106 usage='\n\t%prog [options] <profile_input>',
107 version='%%prog')
José Fonsecaf8b8ba62013-10-18 17:45:49 -0700108
109 optparser.add_option(
110 '-g', '--group', metavar='FIELD',
111 type="string", dest="group", default='program',
112 help="group by specified field [default: %default]")
José Fonseca5df4a3e2013-10-18 17:31:21 -0700113
114 (options, args) = optparser.parse_args(sys.argv[1:])
115
116 if len(args):
117 for arg in args:
José Fonsecaf8b8ba62013-10-18 17:45:49 -0700118 process(open(arg, 'rt'), options.group)
José Fonsecab7634e42012-08-06 17:35:06 +0100119 else:
José Fonsecaf8b8ba62013-10-18 17:45:49 -0700120 process(sys.stdin, options.group)
José Fonsecab7634e42012-08-06 17:35:06 +0100121
122
123if __name__ == '__main__':
124 main()