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