|
1 # Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
2 # All rights reserved. |
|
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". |
|
7 # |
|
8 # Initial Contributors: |
|
9 # Nokia Corporation - initial contribution. |
|
10 # |
|
11 # Contributors: |
|
12 # |
|
13 # Description: |
|
14 # Groups an ASCII TracViewer trace by the contents of a named parameter. |
|
15 # |
|
16 |
|
17 import fileinput, string, re, sys, threadname |
|
18 |
|
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): |
|
22 r = {} |
|
23 for entry in data: |
|
24 matched = re.search(pattern, entry) |
|
25 if matched: |
|
26 r.setdefault(matched.group(1), []).append(entry) |
|
27 return r |
|
28 |
|
29 # Show the usage if the parameters are not as expected |
|
30 if len(sys.argv) != 3: |
|
31 print "Usage: fbsgroup <param|-t> <input>" |
|
32 print "Where:" |
|
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" |
|
35 sys.exit(1) |
|
36 |
|
37 if sys.argv[1] == "-t": |
|
38 pattern = "(Thread ID:0x.*$)" |
|
39 else: |
|
40 pattern = "("+sys.argv[1]+"=*\w*);+" |
|
41 |
|
42 del sys.argv[1] |
|
43 |
|
44 # Add thread names to the raw trace |
|
45 rawinput = threadname.addnames(fileinput.input()) |
|
46 |
|
47 # Group by the parameter supplied on the command line... |
|
48 results = groupby(pattern, rawinput) |
|
49 |
|
50 for group, entries in results.items(): |
|
51 print '\n'+group |
|
52 |
|
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)) |
|
57 |
|
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)) |
|
62 |
|
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)) |
|
67 |
|
68 # Show the matching entries for this group |
|
69 for entry in entries: |
|
70 print "\t%s" % entry.strip() |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |