--- /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 "<progress:discovery " in text:
+ self.out.write(text)
+ elif "<progress:start " in text:
+ attributes = raptor_timing.Timing.extract_values(source = text)
+ self.start_times[(attributes["object_type"] + attributes["task"] +
+ attributes["key"])] = attributes["time"]
+ elif "<progress:end " in text:
+ attributes = raptor_timing.Timing.extract_values(source = text)
+ duration = (float(attributes["time"]) -
+ float(self.start_times[(attributes["object_type"] +
+ attributes["task"] + attributes["key"])]))
+ self.out.write(raptor_timing.Timing.custom_string(tag = "duration",
+ object_type = attributes["object_type"],
+ task = attributes["task"], key = attributes["key"],
+ time = duration))
+ self.all_durations.append(duration)
+ elif text.startswith("<?xml ") and not self.namespace_written:
+ self.out.write(text)
+ self.namespace_written = True
+ elif text.startswith("<buildlog ") and not self.open_written:
+ self.out.write(text)
+ self.open_written = True
+ return True
+
+
+ def summary(self):
+ """
+ Print out extra timing info
+ """
+ total_time = 0.0
+ for duration in self.all_durations:
+ total_time += duration
+ self.out.write(raptor_timing.Timing.custom_string(tag = "duration",
+ object_type = "all", task = "all", key = "all",
+ time = total_time) + "</buildlog>\n")
+
+
+ def close(self):
+ """
+ Close the logfile
+ """
+ try:
+ self.out.close
+ return True
+ except:
+ self.out = None
+ return False
--- /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 "<progress:discovery object_type='" + str(object_type) + \
+ "' count='" + str(count) + "' />\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 "<progress:start object_type='" + str(object_type) + \
+ "' task='" + str(task) + "' key='" + str(key) + \
+ "' time='" + str(time.time()) + "' />\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 "<progress:end object_type='" + str(object_type) + \
+ "' task='" + str(task) + "' key='" + str(key) + \
+ "' time='" + str(time.time()) + "' />\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 "<progress:" + str(tag) + " object_type='" + str(object_type) + \
+ "' task='" + str(task) + "' key='" + str(key) + \
+ "' " + time_string + "='" + str(time) + "' />\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<object_type>.*?)'"),
+ source)
+ attributes["object_type"] = match.group("object_type")
+ except AttributeError, e:
+ print e
+ attributes["object_type"] = ""
+ try:
+ match = re.match(re.compile(".*task='(?P<task>.*?)'"), source)
+ attributes["task"] = match.group("task")
+ except AttributeError, e:
+ print e
+ attributes["task"] = ""
+ try:
+ match = re.match(re.compile(".*key='(?P<key>.*?)'"), source)
+ attributes["key"] = match.group("key")
+ except AttributeError:
+ attributes["key"] = ""
+ try:
+ match = re.match(re.compile(".*time='(?P<time>.*?)'"), source)
+ attributes["time"] = match.group("time")
+ except AttributeError:
+ attributes["time"] = ""
+ try:
+ match = re.match(re.compile(".*count='(?P<count>.*?)'"), source)
+ attributes["count"] = match.group("count")
+ except AttributeError:
+ attributes["count"] = ""
+
+ return attributes
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sbsv2/raptor/test/smoke_suite/timing.py Wed Dec 02 00:38:31 2009 +0000
@@ -0,0 +1,55 @@
+#
+# 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:
+#
+
+from raptor_tests import SmokeTest
+
+def run():
+ t = SmokeTest()
+ t.usebash = True
+
+ t.description = "Test that a timing log is created and contains total parse and build durations"
+
+ t.id = "0103a"
+ t.name = "timing_off"
+ t.command = "sbs -b smoke_suite/test_resources/simple/bld.inf -f-"
+ t.mustnotmatch = [
+ ".*progress:discovery.*",
+ ".*progress:start.*",
+ ".*progress:end.*"
+ ]
+ t.run()
+
+
+ t.id = "0103b"
+ t.name = "timing_on"
+ t.command = "sbs -b smoke_suite/test_resources/simple/bld.inf --timing " + \
+ "--filters=FilterLogfile,FilterTiming -f ${SBSLOGFILE} && " + \
+ "grep progress:duration ${SBSLOGFILE}.timings"
+ t.mustmatch = [
+ "^<progress:duration object_type='layer' task='parse' key='.*' duration='\d+.\d+' />$",
+ "^<progress:duration object_type='layer' task='build' key='.*' duration='\d+.\d+' />$",
+ "^<progress:duration object_type='all' task='all' key='all' duration='\d+.\d+' />$"
+ ]
+ t.mustnotmatch = []
+ t.run()
+
+
+ t.id = "103"
+ t.name = "timing"
+ t.print_result()
+
+ return t
+