sbsv2/raptor/python/raptor_timing.py
author srilekhas <srilekhas@symbian.org>
Wed, 18 Aug 2010 11:18:38 +0100
changeset 627 cb3264f4c6e6
parent 591 22486c9c7b15
permissions -rw-r--r--
Merge : re-applies missing part of fix for Bug 2901,Add export for s60ibymacros.pm
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
591
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     1
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     2
# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     3
# All rights reserved.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     4
# This component and the accompanying materials are made available
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     6
# which accompanies this distribution, and is available
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     8
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
     9
# Initial Contributors:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    10
# Nokia Corporation - initial contribution.
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    11
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    12
# Contributors:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    13
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    14
# Description: 
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    15
# timings API
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    16
# This API can be used to start and stop timings in order to measure performance
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    17
#
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    18
import time
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    19
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    20
class Timing(object):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    21
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    22
	@classmethod
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    23
	def discovery_string(cls, object_type, count):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    24
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    25
			Returns a tag that can be used to show what is about to be
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    26
					"processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    27
			Parameters:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    28
				object_type - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    29
					Type of object that is about to be "processed" in this task
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    30
				count - int
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    31
					Number of objects of input "object_type" are about to be
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    32
							"processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    33
			Returns:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    34
				string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    35
					XML tag in the format that can be printed directly to a
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    36
							Raptor log
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    37
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    38
		return "<progress:discovery object_type='" + str(object_type) + \
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    39
				"' count='" + str(count) + "' />\n"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    40
				
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    41
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    42
	@classmethod
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    43
	def start_string(cls, object_type, task, key):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    44
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    45
			Returns a tag that can be used to show what is being "processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    46
					and the time it started
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    47
			Parameters:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    48
				object_type - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    49
					Type of object that is being "processed" in this task
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    50
				task - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    51
					What is being done with the object being "processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    52
				key - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    53
					Unique identifier for the object being "processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    54
			Returns:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    55
				string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    56
					XML tag in the format that can be printed directly to a
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    57
							Raptor log
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    58
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    59
		return "<progress:start object_type='" + str(object_type) + \
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    60
				"' task='" + str(task) + "' key='" + str(key) + \
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    61
				"' time='" + str(time.time()) + "' />\n"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    62
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    63
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    64
	@classmethod
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    65
	def end_string(cls, object_type, task, key):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    66
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    67
			Returns a tag that can be used to show what was being "processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    68
					and the time it finished
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    69
			Parameters:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    70
				object_type - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    71
					Type of object that was being "processed" in this task
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    72
				task - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    73
					What was being done with the object being "processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    74
				key - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    75
					Unique identifier for the object that was "processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    76
			Returns:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    77
				string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    78
					XML tag in the format that can be printed directly to a
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    79
							Raptor log
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    80
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    81
		return "<progress:end object_type='" + str(object_type) + \
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    82
				"' task='" + str(task) + "' key='" + str(key) + \
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    83
				"' time='" + str(time.time()) + "' />\n"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    84
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    85
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    86
	@classmethod
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    87
	def custom_string(cls, tag = "duration", object_type = "all", task = "all",
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    88
			key = "all", time = 0.0):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    89
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    90
			Returns a custom tag in the 'progress' tag format
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    91
			
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    92
			Parameters:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    93
				tag - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    94
					String to be used for the tag 
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    95
				object_type - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    96
					Type of object that was being "processed" in this task
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    97
				task - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    98
					What was being done with the object being "processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
    99
				key - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   100
					Unique identifier for the object that was "processed"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   101
				time - float
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   102
					The time to be included in the tag
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   103
			Returns:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   104
				string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   105
					XML tag in the format that can be printed directly to a
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   106
							Raptor log
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   107
		"""		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   108
		time_string = "time"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   109
		if tag == "duration":
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   110
			time_string = "duration" 
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   111
		return "<progress:" + str(tag) + " object_type='" + str(object_type) + \
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   112
				"' task='" + str(task) + "' key='" + str(key) + \
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   113
				"' " + time_string + "='" + str(time) + "' />\n"
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   114
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   115
	
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   116
	@classmethod
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   117
	def extract_values(cls, source):
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   118
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   119
			Takes, as input, a single tag of the format returned by one of the
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   120
					above progress functions. Will extract the attributes and
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   121
					return them as a dictionary. Returns an empty dictionary {}
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   122
					if the tag name is not recognised or there is a parse error
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   123
			Parameters:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   124
				source - string
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   125
					The input string from which extracted attributes are
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   126
							required
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   127
			Returns:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   128
				dictionary
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   129
					Dictionary containing the attributes extracted from the
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   130
							input string. Returns an empty dictionary {} if the
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   131
							tag name is not recognised or there is a parse error
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   132
			NB: This function will not work correctly if the 'source' variable
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   133
					contains multiple tags
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   134
		"""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   135
		import re
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   136
		
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   137
		attributes = {}
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   138
					
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   139
		try:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   140
			match = re.match(re.compile(".*object_type='(?P<object_type>.*?)'"),
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   141
					source)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   142
			attributes["object_type"] = match.group("object_type")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   143
		except AttributeError, e:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   144
			print e
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   145
			attributes["object_type"] = ""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   146
		try:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   147
			match = re.match(re.compile(".*task='(?P<task>.*?)'"), source)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   148
			attributes["task"] = match.group("task")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   149
		except AttributeError, e:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   150
			print e
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   151
			attributes["task"] = ""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   152
		try:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   153
			match = re.match(re.compile(".*key='(?P<key>.*?)'"), source)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   154
			attributes["key"] = match.group("key")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   155
		except AttributeError:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   156
			attributes["key"] = ""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   157
		try:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   158
			match = re.match(re.compile(".*time='(?P<time>.*?)'"), source)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   159
			attributes["time"] = match.group("time")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   160
		except AttributeError:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   161
			attributes["time"] = ""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   162
		try:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   163
			match = re.match(re.compile(".*count='(?P<count>.*?)'"), source)
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   164
			attributes["count"] = match.group("count")
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   165
		except AttributeError:
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   166
			attributes["count"] = ""
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   167
			
22486c9c7b15 raptor v2.14.0
jjkang
parents:
diff changeset
   168
		return attributes