Jose Fonseca | 247e1fa | 2019-04-28 14:14:44 +0100 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 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 | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 32 | def process(stream, groupField): |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 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('#') |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame] | 38 | |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 39 | fields = header.rstrip('\r\n').split(' ')[1:] |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame] | 40 | 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 Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 49 | |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 50 | groupCol = columns[groupField] |
| 51 | |
| 52 | maxGroupLen = 0 |
| 53 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 54 | for line in stream: |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 55 | fields = line.rstrip('\r\n').split(' ') |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 56 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 57 | if line.startswith('#'): |
| 58 | continue |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 59 | |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame] | 60 | if fields[callCol] == 'call': |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 61 | callId = int(fields[callIdCol]) |
| 62 | duration = int(fields[gpuDuraCol]) |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 63 | group = fields[groupCol] |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 64 | |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 65 | maxGroupLen = max(maxGroupLen, len(group)) |
James Benton | 91aed52 | 2012-07-31 14:11:14 +0100 | [diff] [blame] | 66 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 67 | if group in times: |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 68 | 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é Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 74 | else: |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 75 | times[group] = {'draws': 1, 'duration': duration, 'longest': callId, 'longestDuration': duration} |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 76 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 77 | times = sorted(list(times.items()), key=lambda x: x[1]['duration'], reverse=True) |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 78 | |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 79 | 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 Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 86 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 87 | print('+-%s-+--------------+--------------------+--------------+-------------+' % groupLine) |
| 88 | print('| %s | Draws [#] | Duration [ns] v | Per Call[ns] | Longest[id] |' % groupTitle) |
| 89 | print('+-%s-+--------------+--------------------+--------------+-------------+' % groupLine) |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 90 | |
| 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 Fonseca | f527924 | 2019-04-29 06:41:49 +0100 | [diff] [blame] | 95 | perCall = str(group[1]['duration'] // group[1]['draws']).rjust(12) |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 96 | longest = str(group[1]['longest']).rjust(11) |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 97 | print("| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest)) |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 98 | |
Piotr Podsiadły | 0b8b019 | 2019-01-03 20:39:55 +0100 | [diff] [blame] | 99 | print('+-%s-+--------------+--------------------+--------------+-------------+' % groupLine) |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 100 | |
| 101 | |
| 102 | def main(): |
José Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame] | 103 | |
| 104 | # Parse command line options |
| 105 | optparser = optparse.OptionParser( |
| 106 | usage='\n\t%prog [options] <profile_input>', |
| 107 | version='%%prog') |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 108 | |
| 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é Fonseca | 5df4a3e | 2013-10-18 17:31:21 -0700 | [diff] [blame] | 113 | |
| 114 | (options, args) = optparser.parse_args(sys.argv[1:]) |
| 115 | |
| 116 | if len(args): |
| 117 | for arg in args: |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 118 | process(open(arg, 'rt'), options.group) |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 119 | else: |
José Fonseca | f8b8ba6 | 2013-10-18 17:45:49 -0700 | [diff] [blame] | 120 | process(sys.stdin, options.group) |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 121 | |
| 122 | |
| 123 | if __name__ == '__main__': |
| 124 | main() |