First public contribution.
1 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
3 # This component and the accompanying materials are made available
4 # under the terms of "Eclipse Public License v1.0"
5 # which accompanies this distribution, and is available
6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 # Initial Contributors:
9 # Nokia Corporation - initial contribution.
14 # Groups an ASCII TracViewer trace by the contents of a named parameter.
17 import fileinput, string, re, sys, threadname
19 # Utility function to group a list by a given regular expression.
20 # returns a dictionary indexed by parameter 1 of the passed in pattern.
21 def groupby(pattern, data):
24 matched = re.search(pattern, entry)
26 r.setdefault(matched.group(1), []).append(entry)
29 # Show the usage if the parameters are not as expected
30 if len(sys.argv) != 3:
31 print "Usage: fbsgroup <param|-t> <input>"
33 print "<param> is a parameter to group by. (-t groups by thread id)"
34 print "<input> is the ASCII TraceViewer file to be parsed"
37 if sys.argv[1] == "-t":
38 pattern = "(Thread ID:0x.*$)"
40 pattern = "("+sys.argv[1]+"=*\w*);+"
44 # Add thread names to the raw trace
45 rawinput = threadname.addnames(fileinput.input())
47 # Group by the parameter supplied on the command line...
48 results = groupby(pattern, rawinput)
50 for group, entries in results.items():
53 # Show a count of the number of CFbsBitmap::xxx function calls
54 functions = groupby("(CFbsBitmap::\S+:)", entries)
55 for name, function in functions.items():
56 print "\t%s %s" % (name, len(function))
58 # Show a count of the number of CFbClient::xxx function calls
59 functions = groupby("(CFbClient::\S+:)", entries)
60 for name, function in functions.items():
61 print "\t%s %s" % (name, len(function))
63 # Show a count of the number of RFbsSession::xxx function calls
64 functions = groupby("(RFbsSession::\S+:)", entries)
65 for name, function in functions.items():
66 print "\t%s %s" % (name, len(function))
68 # Show the matching entries for this group
70 print "\t%s" % entry.strip()