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