James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python |
| 2 | ########################################################################## |
| 3 | # |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame^] | 4 | # Copyright 2012-2013 VMware, Inc. |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 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é Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 27 | |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame^] | 28 | import optparse |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 29 | import sys |
| 30 | |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 31 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 32 | def process(stream): |
| 33 | times = {} |
James Benton | 91aed52 | 2012-07-31 14:11:14 +0100 | [diff] [blame] | 34 | |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame^] | 35 | # 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 Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 50 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 51 | for line in stream: |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame^] | 52 | fields = line.split(' ') |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 53 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 54 | if line.startswith('#'): |
| 55 | continue |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 56 | |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame^] | 57 | if fields[callCol] == 'call': |
| 58 | callId = long(fields[callIdCol]) |
| 59 | duration = long(fields[gpuDuraCol]) |
| 60 | shader = long(fields[programCol]) |
| 61 | func = fields[funcNameCol] |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 62 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 63 | if times.has_key(shader): |
| 64 | times[shader]['draws'] += 1 |
| 65 | times[shader]['duration'] += duration |
James Benton | 91aed52 | 2012-07-31 14:11:14 +0100 | [diff] [blame] | 66 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 67 | if duration > times[shader]['longestDuration']: |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame^] | 68 | times[shader]['longest'] = callId |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 69 | times[shader]['longestDuration'] = duration |
| 70 | else: |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame^] | 71 | times[shader] = {'draws': 1, 'duration': duration, 'longest': callId, 'longestDuration': duration} |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 72 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 73 | times = sorted(times.items(), key=lambda x: x[1]['duration'], reverse=True) |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 74 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 75 | print '+------------+--------------+--------------------+--------------+-------------+' |
| 76 | print '| Shader[id] | Draws [#] | Duration [ns] v | Per Call[ns] | Longest[id] |' |
| 77 | print '+------------+--------------+--------------------+--------------+-------------+' |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 78 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 79 | 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 Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 86 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 87 | print '+------------+--------------+--------------------+--------------+-------------+' |
| 88 | |
| 89 | |
| 90 | def main(): |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame^] | 91 | |
| 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é Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 101 | process(open(arg, 'rt')) |
| 102 | else: |
| 103 | process(sys.stdin) |
| 104 | |
| 105 | |
| 106 | if __name__ == '__main__': |
| 107 | main() |