fbs/fontandbitmapserver/utils/fbsgroup.py
author hgs
Fri, 17 Sep 2010 17:25:01 +0300
changeset 179 b50de33648a3
parent 160 969102054596
permissions -rw-r--r--
201037_1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
160
hgs
parents:
diff changeset
     1
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     2
# All rights reserved.
hgs
parents:
diff changeset
     3
# This component and the accompanying materials are made available
hgs
parents:
diff changeset
     4
# under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     5
# which accompanies this distribution, and is available
hgs
parents:
diff changeset
     6
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     7
#
hgs
parents:
diff changeset
     8
# Initial Contributors:
hgs
parents:
diff changeset
     9
# Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    10
#
hgs
parents:
diff changeset
    11
# Contributors:
hgs
parents:
diff changeset
    12
#
hgs
parents:
diff changeset
    13
# Description:
hgs
parents:
diff changeset
    14
# Groups an ASCII TracViewer trace by the contents of a named parameter. 	
hgs
parents:
diff changeset
    15
#
hgs
parents:
diff changeset
    16
hgs
parents:
diff changeset
    17
import fileinput, string, re, sys, threadname
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
# Utility function to group a list by a given regular expression.
hgs
parents:
diff changeset
    20
# returns a dictionary indexed by parameter 1 of the passed in pattern.
hgs
parents:
diff changeset
    21
def groupby(pattern, data):
hgs
parents:
diff changeset
    22
	r = {}
hgs
parents:
diff changeset
    23
	for entry in data:
hgs
parents:
diff changeset
    24
		matched = re.search(pattern, entry)
hgs
parents:
diff changeset
    25
		if matched:
hgs
parents:
diff changeset
    26
			r.setdefault(matched.group(1), []).append(entry)
hgs
parents:
diff changeset
    27
	return r
hgs
parents:
diff changeset
    28
hgs
parents:
diff changeset
    29
# Show the usage if the parameters are not as expected
hgs
parents:
diff changeset
    30
if len(sys.argv) != 3:
hgs
parents:
diff changeset
    31
	print "Usage: fbsgroup <param|-t> <input>"
hgs
parents:
diff changeset
    32
	print "Where:"
hgs
parents:
diff changeset
    33
	print "<param> is a parameter to group by. (-t groups by thread id)"
hgs
parents:
diff changeset
    34
	print "<input> is the ASCII TraceViewer file to be parsed"
hgs
parents:
diff changeset
    35
	sys.exit(1)
hgs
parents:
diff changeset
    36
hgs
parents:
diff changeset
    37
if sys.argv[1] == "-t":
hgs
parents:
diff changeset
    38
	pattern = "(Thread ID:0x.*$)"
hgs
parents:
diff changeset
    39
else:
hgs
parents:
diff changeset
    40
	pattern = "("+sys.argv[1]+"=*\w*);+"
hgs
parents:
diff changeset
    41
	
hgs
parents:
diff changeset
    42
del sys.argv[1]
hgs
parents:
diff changeset
    43
hgs
parents:
diff changeset
    44
# Add thread names to the raw trace
hgs
parents:
diff changeset
    45
rawinput = threadname.addnames(fileinput.input())
hgs
parents:
diff changeset
    46
hgs
parents:
diff changeset
    47
# Group by the parameter supplied on the command line...
hgs
parents:
diff changeset
    48
results = groupby(pattern, rawinput)
hgs
parents:
diff changeset
    49
hgs
parents:
diff changeset
    50
for group, entries in results.items():
hgs
parents:
diff changeset
    51
		print '\n'+group
hgs
parents:
diff changeset
    52
		
hgs
parents:
diff changeset
    53
		# Show a count of the number of CFbsBitmap::xxx function calls
hgs
parents:
diff changeset
    54
		functions = groupby("(CFbsBitmap::\S+:)", entries)
hgs
parents:
diff changeset
    55
		for name, function in functions.items():
hgs
parents:
diff changeset
    56
			print "\t%s %s" % (name, len(function))
hgs
parents:
diff changeset
    57
		
hgs
parents:
diff changeset
    58
		# Show a count of the number of CFbClient::xxx function calls	
hgs
parents:
diff changeset
    59
		functions = groupby("(CFbClient::\S+:)", entries)
hgs
parents:
diff changeset
    60
		for name, function in functions.items():
hgs
parents:
diff changeset
    61
			print "\t%s %s" % (name, len(function))
hgs
parents:
diff changeset
    62
		
hgs
parents:
diff changeset
    63
		# Show a count of the number of RFbsSession::xxx function calls	
hgs
parents:
diff changeset
    64
		functions = groupby("(RFbsSession::\S+:)", entries)
hgs
parents:
diff changeset
    65
		for name, function in functions.items():
hgs
parents:
diff changeset
    66
			print "\t%s %s" % (name, len(function))
hgs
parents:
diff changeset
    67
		
hgs
parents:
diff changeset
    68
		# Show the matching entries for this group
hgs
parents:
diff changeset
    69
		for entry in entries:
hgs
parents:
diff changeset
    70
			print "\t%s" % entry.strip()
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
		
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
		
hgs
parents:
diff changeset
    75
hgs
parents:
diff changeset
    76