]> git.cworth.org Git - apitrace/blobdiff - scripts/profileshader.py
Use skiplist-based FastCallSet within trace::CallSet
[apitrace] / scripts / profileshader.py
index 6d693f4d51a00c602682d64710f84c6b8237d167..d31130e2896ffa933cd10fa5b194e6c20ac83d68 100755 (executable)
 #
 ##########################################################################/
 
+
 import sys
 
-if len(sys.argv) <= 1:
-       print 'Please specify a file to read'
-       sys.exit()
-
-shaderTimes = {}
-activeShader = 0
-
-for line in open(sys.argv[1], 'r'):
-    words = line.split(' ')
-
-    if line.startswith('#'):
-        continue
-
-    if words[0:3] == ['use','shader','program']:
-        activeShader = long(words[3])
-    elif words[0] == 'call':
-        id = long(words[1])
-        func = words[-1]
-        duration = long(words[3])
-
-        if shaderTimes.has_key(activeShader):
-            shaderTimes[activeShader]['draws'] += 1
-            shaderTimes[activeShader]['duration'] += duration
-            if duration > shaderTimes[activeShader]['longestDuration']:
-                shaderTimes[activeShader]['longest'] = id
-                shaderTimes[activeShader]['longestDuration'] = duration
-        else:
-            shaderTimes[activeShader] = {'draws': 1, 'duration': duration, 'longest': id, 'longestDuration': duration}
-
-sortedShaderTimes = sorted(shaderTimes.items(), key=lambda x: x[1]['duration'], reverse=True)
-
-print '+------------+--------------+--------------------+--------------+-------------+'
-print '| Shader[id] |   Draws [#]  |   Duration [ns]  v | Per Call[ns] | Longest[id] |'
-print '+------------+--------------+--------------------+--------------+-------------+'
-
-for shader in sortedShaderTimes:
-    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 '+------------+--------------+--------------------+--------------+-------------+'
+
+def process(stream):
+    times = {}
+
+    # 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]
+
+            if times.has_key(shader):
+                times[shader]['draws'] += 1
+                times[shader]['duration'] += duration
+
+                if duration > times[shader]['longestDuration']:
+                    times[shader]['longest'] = id
+                    times[shader]['longestDuration'] = duration
+            else:
+                times[shader] = {'draws': 1, 'duration': duration, 'longest': id, 'longestDuration': duration}
+
+    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 '+------------+--------------+--------------------+--------------+-------------+'
+
+    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 '+------------+--------------+--------------------+--------------+-------------+'
+
+
+def main():
+    if len(sys.argv) > 1:
+        for arg in sys.argv[1:]:
+            process(open(arg, 'rt'))
+    else:
+        process(sys.stdin)
+
+
+if __name__ == '__main__':
+    main()