fbs/fontandbitmapserver/utils/threadname.py
author hgs
Wed, 25 Aug 2010 08:17:25 +0300
changeset 160 969102054596
permissions -rw-r--r--
201032
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
# Utility function to append thread names where the Thread Id maps to a known thread/process name.
hgs
parents:
diff changeset
    15
hgs
parents:
diff changeset
    16
import re
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
# Takes as input list <data> which contains OST traces from the SYMBIAN_KERNEL_THREAD_IDENTIFICATION trace group in Symbian
hgs
parents:
diff changeset
    19
# BTrace Hooks OST dictionary. Returns a list with the same content as <data> with thread names appended.
hgs
parents:
diff changeset
    20
def addnames(data):
hgs
parents:
diff changeset
    21
	result = []
hgs
parents:
diff changeset
    22
	processNames = {}
hgs
parents:
diff changeset
    23
	threadNames = {}
hgs
parents:
diff changeset
    24
	rthreadIds = {}
hgs
parents:
diff changeset
    25
	
hgs
parents:
diff changeset
    26
	for line in data:		
hgs
parents:
diff changeset
    27
		pattern = "^.*Thread:Process name assigned;NThread:(.*);DProcess:(.*);Name:(.*)$"
hgs
parents:
diff changeset
    28
		matched = re.search(pattern, line)
hgs
parents:
diff changeset
    29
		if matched:
hgs
parents:
diff changeset
    30
			processNames[matched.group(2)] = matched.group(3)	
hgs
parents:
diff changeset
    31
			
hgs
parents:
diff changeset
    32
		pattern = "^.*Thread:Thread created;NThread:(.*);DProcess:(.*);Name:(.*)$"
hgs
parents:
diff changeset
    33
		matched = re.search(pattern, line)
hgs
parents:
diff changeset
    34
		if matched:
hgs
parents:
diff changeset
    35
			threadNames[matched.group(1)] = processNames[matched.group(2)]+":"+matched.group(3)
hgs
parents:
diff changeset
    36
		
hgs
parents:
diff changeset
    37
		pattern = "^.*Thread:Thread name assigned;NThread:(.*);DProcess:(.*);Name:(.*)$"
hgs
parents:
diff changeset
    38
		matched = re.search(pattern, line)
hgs
parents:
diff changeset
    39
		if matched:
hgs
parents:
diff changeset
    40
			threadNames[matched.group(1)] = processNames[matched.group(2)]+":"+matched.group(3)
hgs
parents:
diff changeset
    41
hgs
parents:
diff changeset
    42
		pattern = "^.*Thread:Thread ID assigned;NThread:(.*);DProcess:(.*);RThread ID:(\d*)$"
hgs
parents:
diff changeset
    43
		matched = re.search(pattern, line)
hgs
parents:
diff changeset
    44
		if matched:
hgs
parents:
diff changeset
    45
			rthreadIds[matched.group(3)] = matched.group(1)
hgs
parents:
diff changeset
    46
			
hgs
parents:
diff changeset
    47
		pattern = "(^.*Thread ID:)(\w*)(.*)$"
hgs
parents:
diff changeset
    48
		matched = re.search(pattern, line)
hgs
parents:
diff changeset
    49
		if matched:
hgs
parents:
diff changeset
    50
			threadId = matched.group(2)
hgs
parents:
diff changeset
    51
			if threadNames.has_key(threadId):
hgs
parents:
diff changeset
    52
				line = matched.group(1)+threadId+":"+threadNames[threadId]+matched.group(3)
hgs
parents:
diff changeset
    53
	
hgs
parents:
diff changeset
    54
		pattern = "(^.*clientThreadId )(\w*)(.*)$"
hgs
parents:
diff changeset
    55
		matched = re.search(pattern, line)
hgs
parents:
diff changeset
    56
		if matched:
hgs
parents:
diff changeset
    57
			rthreadIdHex = matched.group(2)
hgs
parents:
diff changeset
    58
			rthreadId = hex(rthreadIdHex)
hgs
parents:
diff changeset
    59
			if rthreadIds.has_key(rthreadId):
hgs
parents:
diff changeset
    60
				threadId = rthreadIds[rthreadId]
hgs
parents:
diff changeset
    61
				threadName = threadNames[threadId]
hgs
parents:
diff changeset
    62
				line = matched.group(1)+rthreadId+":"+threadName+matched.group(3)
hgs
parents:
diff changeset
    63
				
hgs
parents:
diff changeset
    64
		pattern = "(^.*threadId )(\w*)(.*)$"
hgs
parents:
diff changeset
    65
		matched = re.search(pattern, line)
hgs
parents:
diff changeset
    66
		if matched:
hgs
parents:
diff changeset
    67
			rthreadIdHex = matched.group(2)
hgs
parents:
diff changeset
    68
			rthreadId = hex(rthreadIdHex)
hgs
parents:
diff changeset
    69
			if rthreadIds.has_key(rthreadId):
hgs
parents:
diff changeset
    70
				threadId = rthreadIds[rthreadId]
hgs
parents:
diff changeset
    71
				threadName = threadNames[threadId]
hgs
parents:
diff changeset
    72
				line = matched.group(1)+rthreadId+":"+threadName+matched.group(3)
hgs
parents:
diff changeset
    73
				
hgs
parents:
diff changeset
    74
		result.append(line)
hgs
parents:
diff changeset
    75
				
hgs
parents:
diff changeset
    76
	return result