James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 1 | #!/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é Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 27 | |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 28 | import sys |
| 29 | |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 30 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 31 | def process(stream): |
| 32 | times = {} |
James Benton | 91aed52 | 2012-07-31 14:11:14 +0100 | [diff] [blame] | 33 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 34 | # call no gpu_start gpu_dura cpu_start cpu_dura pixels program name |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 35 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 36 | for line in stream: |
| 37 | words = line.split(' ') |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 38 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 39 | if line.startswith('#'): |
| 40 | continue |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 41 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 42 | if words[0] == 'call': |
| 43 | id = long(words[1]) |
| 44 | duration = long(words[3]) |
| 45 | shader = long(words[7]) |
| 46 | func = words[8] |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 47 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 48 | if times.has_key(shader): |
| 49 | times[shader]['draws'] += 1 |
| 50 | times[shader]['duration'] += duration |
James Benton | 91aed52 | 2012-07-31 14:11:14 +0100 | [diff] [blame] | 51 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 52 | if duration > times[shader]['longestDuration']: |
| 53 | times[shader]['longest'] = id |
| 54 | times[shader]['longestDuration'] = duration |
| 55 | else: |
| 56 | times[shader] = {'draws': 1, 'duration': duration, 'longest': id, 'longestDuration': duration} |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 57 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 58 | times = sorted(times.items(), key=lambda x: x[1]['duration'], reverse=True) |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 59 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 60 | print '+------------+--------------+--------------------+--------------+-------------+' |
| 61 | print '| Shader[id] | Draws [#] | Duration [ns] v | Per Call[ns] | Longest[id] |' |
| 62 | print '+------------+--------------+--------------------+--------------+-------------+' |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 63 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 64 | for shader in times: |
| 65 | id = str(shader[0]).rjust(10) |
| 66 | draw = str(shader[1]['draws']).rjust(12) |
| 67 | dura = str(shader[1]['duration']).rjust(18) |
| 68 | perCall = str(shader[1]['duration'] / shader[1]['draws']).rjust(12) |
| 69 | longest = str(shader[1]['longest']).rjust(11) |
| 70 | print "| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest) |
James Benton | e38b98a | 2012-07-25 13:52:14 +0100 | [diff] [blame] | 71 | |
José Fonseca | b7634e4 | 2012-08-06 17:35:06 +0100 | [diff] [blame] | 72 | print '+------------+--------------+--------------------+--------------+-------------+' |
| 73 | |
| 74 | |
| 75 | def main(): |
| 76 | if len(sys.argv) > 1: |
| 77 | for arg in sys.argv[1:]: |
| 78 | process(open(arg, 'rt')) |
| 79 | else: |
| 80 | process(sys.stdin) |
| 81 | |
| 82 | |
| 83 | if __name__ == '__main__': |
| 84 | main() |