sl@0: # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
sl@0: # All rights reserved.
sl@0: # This component and the accompanying materials are made available
sl@0: # under the terms of "Eclipse Public License v1.0"
sl@0: # which accompanies this distribution, and is available
sl@0: # at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0: #
sl@0: # Initial Contributors:
sl@0: # Nokia Corporation - initial contribution.
sl@0: #
sl@0: # Contributors:
sl@0: #
sl@0: # Description:
sl@0: # Groups an ASCII TracViewer trace by the contents of a named parameter.
sl@0: #
sl@0:
sl@0: import fileinput, string, re, sys, threadname
sl@0:
sl@0: # Utility function to group a list by a given regular expression.
sl@0: # returns a dictionary indexed by parameter 1 of the passed in pattern.
sl@0: def groupby(pattern, data):
sl@0: r = {}
sl@0: for entry in data:
sl@0: matched = re.search(pattern, entry)
sl@0: if matched:
sl@0: r.setdefault(matched.group(1), []).append(entry)
sl@0: return r
sl@0:
sl@0: # Show the usage if the parameters are not as expected
sl@0: if len(sys.argv) != 3:
sl@0: print "Usage: fbsgroup "
sl@0: print "Where:"
sl@0: print " is a parameter to group by. (-t groups by thread id)"
sl@0: print " is the ASCII TraceViewer file to be parsed"
sl@0: sys.exit(1)
sl@0:
sl@0: if sys.argv[1] == "-t":
sl@0: pattern = "(Thread ID:0x.*$)"
sl@0: else:
sl@0: pattern = "("+sys.argv[1]+"=*\w*);+"
sl@0:
sl@0: del sys.argv[1]
sl@0:
sl@0: # Add thread names to the raw trace
sl@0: rawinput = threadname.addnames(fileinput.input())
sl@0:
sl@0: # Group by the parameter supplied on the command line...
sl@0: results = groupby(pattern, rawinput)
sl@0:
sl@0: for group, entries in results.items():
sl@0: print '\n'+group
sl@0:
sl@0: # Show a count of the number of CFbsBitmap::xxx function calls
sl@0: functions = groupby("(CFbsBitmap::\S+:)", entries)
sl@0: for name, function in functions.items():
sl@0: print "\t%s %s" % (name, len(function))
sl@0:
sl@0: # Show a count of the number of CFbClient::xxx function calls
sl@0: functions = groupby("(CFbClient::\S+:)", entries)
sl@0: for name, function in functions.items():
sl@0: print "\t%s %s" % (name, len(function))
sl@0:
sl@0: # Show a count of the number of RFbsSession::xxx function calls
sl@0: functions = groupby("(RFbsSession::\S+:)", entries)
sl@0: for name, function in functions.items():
sl@0: print "\t%s %s" % (name, len(function))
sl@0:
sl@0: # Show the matching entries for this group
sl@0: for entry in entries:
sl@0: print "\t%s" % entry.strip()
sl@0:
sl@0:
sl@0:
sl@0:
sl@0:
sl@0: