summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2013-10-18 17:45:49 -0700
committerJosé Fonseca <jfonseca@vmware.com>2013-10-18 17:45:49 -0700
commitf8b8ba6982bd8bb73f85fcba176d4ccf7b91db7b (patch)
treeb1308189ea5450e9fccd2087c7c251539a27d3c8 /scripts
parent5df4a3eeac664537e05644f76b455edf27775c16 (diff)
profileshader: Allow to specify which field to group on.
It allows, for example, to group results by function name, instead of program.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/profileshader.py69
1 files changed, 43 insertions, 26 deletions
diff --git a/scripts/profileshader.py b/scripts/profileshader.py
index 04e219d3..3c490a0e 100755
--- a/scripts/profileshader.py
+++ b/scripts/profileshader.py
@@ -29,15 +29,14 @@ import optparse
import sys
-def process(stream):
+def process(stream, groupField):
times = {}
# Read header describing fields
header = stream.readline()
assert header.startswith('#')
- header = header.rstrip('\r\n')
- fields = header.split(' ')[1:]
+ fields = header.rstrip('\r\n').split(' ')[1:]
columns = {}
for column in range(len(fields)):
columns[fields[column]] = column
@@ -48,8 +47,12 @@ def process(stream):
programCol = columns['program']
funcNameCol = columns['name']
+ groupCol = columns[groupField]
+
+ maxGroupLen = 0
+
for line in stream:
- fields = line.split(' ')
+ fields = line.rstrip('\r\n').split(' ')
if line.startswith('#'):
continue
@@ -57,34 +60,43 @@ def process(stream):
if fields[callCol] == 'call':
callId = long(fields[callIdCol])
duration = long(fields[gpuDuraCol])
- shader = long(fields[programCol])
- func = fields[funcNameCol]
+ group = fields[groupCol]
+
+ maxGroupLen = max(maxGroupLen, len(group))
- if times.has_key(shader):
- times[shader]['draws'] += 1
- times[shader]['duration'] += duration
+ if times.has_key(group):
+ times[group]['draws'] += 1
+ times[group]['duration'] += duration
- if duration > times[shader]['longestDuration']:
- times[shader]['longest'] = callId
- times[shader]['longestDuration'] = duration
+ if duration > times[group]['longestDuration']:
+ times[group]['longest'] = callId
+ times[group]['longestDuration'] = duration
else:
- times[shader] = {'draws': 1, 'duration': duration, 'longest': callId, 'longestDuration': duration}
+ times[group] = {'draws': 1, 'duration': duration, 'longest': callId, '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)
+ if groupField == 'program':
+ groupTitle = 'Shader[id]'
+ else:
+ groupTitle = groupField
+ maxGroupLen = max(maxGroupLen, len(groupTitle))
+ groupTitle = groupField.center(maxGroupLen)
+ groupLine = '-' * maxGroupLen
+
+ print '+-%s-+--------------+--------------------+--------------+-------------+' % groupLine
+ print '| %s | Draws [#] | Duration [ns] v | Per Call[ns] | Longest[id] |' % groupTitle
+ print '+-%s-+--------------+--------------------+--------------+-------------+' % groupLine
+
+ for group in times:
+ id = str(group[0]).rjust(maxGroupLen)
+ draw = str(group[1]['draws']).rjust(12)
+ dura = str(group[1]['duration']).rjust(18)
+ perCall = str(group[1]['duration'] / group[1]['draws']).rjust(12)
+ longest = str(group[1]['longest']).rjust(11)
print "| %s | %s | %s | %s | %s |" % (id, draw, dura, perCall, longest)
- print '+------------+--------------+--------------------+--------------+-------------+'
+ print '+-%s-+--------------+--------------------+--------------+-------------+' % groupLine
def main():
@@ -93,14 +105,19 @@ def main():
optparser = optparse.OptionParser(
usage='\n\t%prog [options] <profile_input>',
version='%%prog')
+
+ optparser.add_option(
+ '-g', '--group', metavar='FIELD',
+ type="string", dest="group", default='program',
+ help="group by specified field [default: %default]")
(options, args) = optparser.parse_args(sys.argv[1:])
if len(args):
for arg in args:
- process(open(arg, 'rt'))
+ process(open(arg, 'rt'), options.group)
else:
- process(sys.stdin)
+ process(sys.stdin, options.group)
if __name__ == '__main__':