# HG changeset patch # User timothy.murphy@nokia.com # Date 1259714311 0 # Node ID 01c962c3f6318e10f1a271ee54bb434f5bf61520 # Parent ee00c00df0738ab7d675eea0be5a9758999cd5ee correction: left out timing files in previous commit diff -r ee00c00df073 -r 01c962c3f631 sbsv2/raptor/python/plugins/filter_timing.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sbsv2/raptor/python/plugins/filter_timing.py Wed Dec 02 00:38:31 2009 +0000 @@ -0,0 +1,121 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of the License "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# Base Class for defining filter classes +# All filter classes that get defined should derive from this base class +# + +import errno +import filter_interface +import os +import raptor +import raptor_timing +import sys + +class FilterTiming(filter_interface.Filter): + """ + Writes a logfile containing the timings for each Raptor process + """ + + def open(self, raptor_instance): + """ + Open a log file with the same name as the Raptor log file, with + '.timings' appended. This will contain only 'progress' + timing tags from the Raptor output + Parameters: + raptor_instance - Raptor + Instance of Raptor. FilterList usually passes in a cut-down + version of Raptor containing only a few attributes + """ + self.raptor = raptor_instance + self.logFileName = self.raptor.logFileName + # insert the time into the log file name + if self.logFileName: + self.path = (self.logFileName.path.replace("%TIME", + self.raptor.timestring) + ".timings") + + try: + dirname = str(self.raptor.logFileName.Dir()) + if dirname and not os.path.isdir(dirname): + os.makedirs(dirname) + except os.error, e: + if e.errno != errno.EEXIST: + sys.stderr.write("%s : error: cannot create directory " + + "%s\n" % (raptor.name, dirname)) + return False + try: + self.out = open(str(self.path), "w") + except: + self.out = None + sys.stderr.write("%s : error: cannot write log %s\n" %\ + (raptor.name, self.path)) + return False + self.start_times = {} + self.all_durations = [] + self.namespace_written = False + self.open_written = False + return True + + + def write(self, text): + """ + Write out any tags with a 'progress_' tagName + """ + if "\n") + + + def close(self): + """ + Close the logfile + """ + try: + self.out.close + return True + except: + self.out = None + return False diff -r ee00c00df073 -r 01c962c3f631 sbsv2/raptor/python/raptor_timing.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sbsv2/raptor/python/raptor_timing.py Wed Dec 02 00:38:31 2009 +0000 @@ -0,0 +1,168 @@ +# +# Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). +# All rights reserved. +# This component and the accompanying materials are made available +# under the terms of the License "Eclipse Public License v1.0" +# which accompanies this distribution, and is available +# at the URL "http://www.eclipse.org/legal/epl-v10.html". +# +# Initial Contributors: +# Nokia Corporation - initial contribution. +# +# Contributors: +# +# Description: +# timings API +# This API can be used to start and stop timings in order to measure performance +# +import time + +class Timing(object): + + @classmethod + def discovery_string(cls, object_type, count): + """ + Returns a tag that can be used to show what is about to be + "processed" + Parameters: + object_type - string + Type of object that is about to be "processed" in this task + count - int + Number of objects of input "object_type" are about to be + "processed" + Returns: + string + XML tag in the format that can be printed directly to a + Raptor log + """ + return "\n" + + + @classmethod + def start_string(cls, object_type, task, key): + """ + Returns a tag that can be used to show what is being "processed" + and the time it started + Parameters: + object_type - string + Type of object that is being "processed" in this task + task - string + What is being done with the object being "processed" + key - string + Unique identifier for the object being "processed" + Returns: + string + XML tag in the format that can be printed directly to a + Raptor log + """ + return "\n" + + + @classmethod + def end_string(cls, object_type, task, key): + """ + Returns a tag that can be used to show what was being "processed" + and the time it finished + Parameters: + object_type - string + Type of object that was being "processed" in this task + task - string + What was being done with the object being "processed" + key - string + Unique identifier for the object that was "processed" + Returns: + string + XML tag in the format that can be printed directly to a + Raptor log + """ + return "\n" + + + @classmethod + def custom_string(cls, tag = "duration", object_type = "all", task = "all", + key = "all", time = 0.0): + """ + Returns a custom tag in the 'progress' tag format + + Parameters: + tag - string + String to be used for the tag + object_type - string + Type of object that was being "processed" in this task + task - string + What was being done with the object being "processed" + key - string + Unique identifier for the object that was "processed" + time - float + The time to be included in the tag + Returns: + string + XML tag in the format that can be printed directly to a + Raptor log + """ + time_string = "time" + if tag == "duration": + time_string = "duration" + return "\n" + + + @classmethod + def extract_values(cls, source): + """ + Takes, as input, a single tag of the format returned by one of the + above progress functions. Will extract the attributes and + return them as a dictionary. Returns an empty dictionary {} + if the tag name is not recognised or there is a parse error + Parameters: + source - string + The input string from which extracted attributes are + required + Returns: + dictionary + Dictionary containing the attributes extracted from the + input string. Returns an empty dictionary {} if the + tag name is not recognised or there is a parse error + NB: This function will not work correctly if the 'source' variable + contains multiple tags + """ + import re + + attributes = {} + + try: + match = re.match(re.compile(".*object_type='(?P.*?)'"), + source) + attributes["object_type"] = match.group("object_type") + except AttributeError, e: + print e + attributes["object_type"] = "" + try: + match = re.match(re.compile(".*task='(?P.*?)'"), source) + attributes["task"] = match.group("task") + except AttributeError, e: + print e + attributes["task"] = "" + try: + match = re.match(re.compile(".*key='(?P.*?)'"), source) + attributes["key"] = match.group("key") + except AttributeError: + attributes["key"] = "" + try: + match = re.match(re.compile(".*time='(?P