]> git.cworth.org Git - apitrace/commitdiff
Allow to pipe profile output directly to profileshader.py
authorJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 6 Aug 2012 16:35:06 +0000 (17:35 +0100)
committerJosé Fonseca <jose.r.fonseca@gmail.com>
Mon, 6 Aug 2012 16:35:06 +0000 (17:35 +0100)
For example

  ./glretrace -pgpu foo.trace | ./scripts/profileshader.py

scripts/profileshader.py

index 3cfa850deeb139bddc5929322778adb03b185373..bcb661c581297bd3ed11add4d3d54f09b00b5433 100755 (executable)
 #
 ##########################################################################/
 
+
 import sys
 
-if len(sys.argv) <= 1:
-       print 'Please specify a file to read'
-       sys.exit()
 
-times = {}
+def process(stream):
+    times = {}
+
+    # frame_begin no gpu_start cpu_start
+    # frame_end no gpu_end gpu_dura cpu_end cpu_dura
+    # call no gpu_start gpu_dura cpu_start cpu_dura pixels program name
+
+    for line in stream:
+        words = line.split(' ')
+
+        if line.startswith('#'):
+            continue
+
+        if words[0] == 'call':
+            id = long(words[1])
+            duration = long(words[3])
+            shader = long(words[7])
+            func = words[8]
 
-# frame_begin no gpu_start cpu_start
-# frame_end no gpu_end gpu_dura cpu_end cpu_dura
-# call no gpu_start gpu_dura cpu_start cpu_dura pixels program name
+            if times.has_key(shader):
+                times[shader]['draws'] += 1
+                times[shader]['duration'] += duration
 
-for line in open(sys.argv[1], 'r'):
-    words = line.split(' ')
+                if duration > times[shader]['longestDuration']:
+                    times[shader]['longest'] = id
+                    times[shader]['longestDuration'] = duration
+            else:
+                times[shader] = {'draws': 1, 'duration': duration, 'longest': id, 'longestDuration': duration}
 
-    if line.startswith('#'):
-        continue
+    times = sorted(times.items(), key=lambda x: x[1]['duration'], reverse=True)
 
-    if words[0] == 'call':
-        id = long(words[1])
-        duration = long(words[3])
-        shader = long(words[7])
-        func = words[8]
+    print '+------------+--------------+--------------------+--------------+-------------+'
+    print '| Shader[id] |   Draws [#]  |   Duration [ns]  v | Per Call[ns] | Longest[id] |'
+    print '+------------+--------------+--------------------+--------------+-------------+'
 
-        if times.has_key(shader):
-            times[shader]['draws'] += 1
-            times[shader]['duration'] += duration
+    for shader in times:
+        id = str(shader[0]).rjust(10)
+        draw = str(shader[1]['draws']).rjust(12)
+        dura = str(shader[1]['duration']).rjust(18)
+        perCall = str(shader[1]['duration'] / shader[1]['draws']).rjust(12)
+        longest = str(shader[1]['longest']).rjust(11)
+        print "| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest)
 
-            if duration > times[shader]['longestDuration']:
-                times[shader]['longest'] = id
-                times[shader]['longestDuration'] = duration
-        else:
-            times[shader] = {'draws': 1, 'duration': duration, 'longest': id, 'longestDuration': duration}
+    print '+------------+--------------+--------------------+--------------+-------------+'
 
-times = sorted(times.items(), key=lambda x: x[1]['duration'], reverse=True)
 
-print '+------------+--------------+--------------------+--------------+-------------+'
-print '| Shader[id] |   Draws [#]  |   Duration [ns]  v | Per Call[ns] | Longest[id] |'
-print '+------------+--------------+--------------------+--------------+-------------+'
+def main():
+    if len(sys.argv) > 1:
+        for arg in sys.argv[1:]:
+            process(open(arg, 'rt'))
+    else:
+        process(sys.stdin)
 
-for shader in times:
-    id = str(shader[0]).rjust(10)
-    draw = str(shader[1]['draws']).rjust(12)
-    dura = str(shader[1]['duration']).rjust(18)
-    perCall = str(shader[1]['duration'] / shader[1]['draws']).rjust(12)
-    longest = str(shader[1]['longest']).rjust(11)
-    print "| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest)
 
-print '+------------+--------------+--------------------+--------------+-------------+'
+if __name__ == '__main__':
+    main()