# HG changeset patch # User timothy.murphy@nokia.com # Date 1260095660 0 # Node ID 32f524d09c94e72ff0c638b94ab61a4a5a20e2f0 # Parent d82b03c7df17c7db0dacc857910e06dac0a49735# Parent 24ef68259f6c38134facc163a826986f0494966e catchup to wip diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/RELEASE-NOTES.txt --- a/sbsv2/raptor/RELEASE-NOTES.txt Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/RELEASE-NOTES.txt Sun Dec 06 10:34:20 2009 +0000 @@ -1,6 +1,21 @@ Release Notes for Symbian Build System v2 +version 2.11.1 + +Other Changes: +GCCE 4.4.1 variant added +Restored python 2.4 compatibility +Minor TOOLS2 --what corrections +Retain Linux execute permissions on unpacked :zip archives +Prototype of extended timing API added +Option --noexport added for parallel parsing +Made --noexport and --export-only mutually exclusive +SBS_PYTHONPATH insulates sbs from the global PYTHONPATH +Removed spurious bracket in e32abiv2textnotifier2 +More robust to multiple import library definitions + + version 2.11.0 New Features: diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/bin/sbs --- a/sbsv2/raptor/bin/sbs Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/bin/sbs Sun Dec 06 10:34:20 2009 +0000 @@ -68,6 +68,7 @@ __MINGW__=${SBS_MINGW:-$SBS_HOME/$HOSTPLATFORM_DIR/mingw} __CYGWIN__=${SBS_CYGWIN:-$SBS_HOME/$HOSTPLATFORM_DIR/cygwin} __PYTHON__=${SBS_PYTHON:-$SBS_HOME/$HOSTPLATFORM_DIR/python252/python.exe} + export PYTHONPATH=${SBS_PYTHONPATH:-$SBS_HOME/$HOSTPLATFORM_DIR/python252} # Command for unifying path strings. For example, "c:\some\path" and # "/cygdrive/c/some/path" will both be converted into "c:/some/path". @@ -87,6 +88,7 @@ export CYGWIN='nontsec nosmbntsec' else + export PYTHONPATH=${SBS_PYTHONPATH:-$SBS_HOME/$HOSTPLATFORM_DIR/python262/lib} PATH=$SBS_HOME/$HOSTPLATFORM_DIR/python262/bin:$SBS_HOME/$HOSTPLATFORM_DIR/bin:$PATH LD_LIBRARY_PATH=$SBS_HOME/$HOSTPLATFORM_DIR/python262/lib:$SBS_HOME/$HOSTPLATFORM_DIR/bv/lib:$LD_LIBRARY_PATH diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/lib/flm/e32abiv2textnotifier2.flm --- a/sbsv2/raptor/lib/flm/e32abiv2textnotifier2.flm Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/lib/flm/e32abiv2textnotifier2.flm Sun Dec 06 10:34:20 2009 +0000 @@ -28,7 +28,7 @@ AUTOEXPORTS:=_Z13NotifierArrayv,1; # Determine what kind of entrypoint option to set LINKER_ENTRYPOINT_LIBDEP:=$(STATIC_RUNTIME_DIR)/edll.lib -LINKER_ENTRYPOINT_SETTING:=$(LINKER_ENTRY_OPTION)=_E32Dll $(LINKER_ENTRYPOINT_DECORATION))$(LINKER_SEPARATOR)$(call dblquote,$(STATIC_RUNTIME_DIR)/edll.lib$(LINKER_ENTRYPOINT_ADORNMENT)) +LINKER_ENTRYPOINT_SETTING:=$(LINKER_ENTRY_OPTION)=_E32Dll $(LINKER_ENTRYPOINT_DECORATION)$(LINKER_SEPARATOR)$(call dblquote,$(STATIC_RUNTIME_DIR)/edll.lib$(LINKER_ENTRYPOINT_ADORNMENT)) ifeq ("$(NEED_ENTRYPOINT_LIBRARY)","True") LINKER_ENTRYPOINT_SETTING:=$(LINKER_ENTRYPOINT_SETTING) $(LINKER_ENTRYPOINT_LIBDEP) diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/lib/flm/tools2common.flm --- a/sbsv2/raptor/lib/flm/tools2common.flm Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/lib/flm/tools2common.flm Sun Dec 06 10:34:20 2009 +0000 @@ -102,6 +102,6 @@ ## Clean up $(call raptor_clean,$(CLEANTARGETS) $(OBJECTFILES)) ## for the --what option and the log file -$(call raptor_release,$(RELEASEABLES)) +$(call raptor_release,$(RELEASABLES)) ## The End diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/lib/flm/tools2exe.flm --- a/sbsv2/raptor/lib/flm/tools2exe.flm Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/lib/flm/tools2exe.flm Sun Dec 06 10:34:20 2009 +0000 @@ -24,12 +24,13 @@ EXETARGET:=$(RELEASEPATH)/$(TARGET)$(DOTEXE) +INSTALLED:= ifneq ($(TOOLSPATH),) INSTALLED:=$(TOOLSPATH)/$(TARGET)$(DOTEXE) endif ## Target groups -RELEASEABLES:=$(INSTALLED) +RELEASABLES:=$(INSTALLED) TARGETS:=$(EXETARGET) $(INSTALLED) ## Common build steps (compiling and cleaning) diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/lib/flm/tools2lib.flm --- a/sbsv2/raptor/lib/flm/tools2lib.flm Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/lib/flm/tools2lib.flm Sun Dec 06 10:34:20 2009 +0000 @@ -19,7 +19,7 @@ LIBTARGET:=$(RELEASEPATH)/$(TARGET).a ## Target groups -RELEASEABLES:=$(LIBTARGET) +RELEASABLES:=$(LIBTARGET) TARGETS:=$(LIBTARGET) ## Common build steps (compiling) diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/filter_utils.py --- a/sbsv2/raptor/python/filter_utils.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/filter_utils.py Sun Dec 06 10:34:20 2009 +0000 @@ -198,12 +198,16 @@ def isError(self, aLine): """Convenience matcher for basic errors. Override in sub-classes to specialise.""" - return True if Recipe.error.match(aLine) else False + if Recipe.error.match(aLine): + return True + return False def isWarning(self, aLine): """Convenience matcher for basic warnings. Override in sub-classes to specialise.""" - return True if Recipe.warning.match(aLine) else False + if Recipe.warning.match(aLine): + return True + return False def getOutput(self): """"Return a list of all output that isn't an error or a warning. @@ -234,16 +238,17 @@ def isSuccess(self): "Convenience method to get overall recipe status." - return True if self.getDetail(Recipe.exit) == "ok" else False + return (self.getDetail(Recipe.exit) == "ok") class Win32Recipe(Recipe): "Win32 tailored recipe class." def isError(self, aLine): - return True if mwError.match(aLine) else False + if mwError.match(aLine): + return True + return False def isWarning(self, aLine): - return True if mwWarning.match(aLine) else False - - - + if mwWarning.match(aLine): + return True + return False diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/plugins/filter_carbide.py --- a/sbsv2/raptor/python/plugins/filter_carbide.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/plugins/filter_carbide.py Sun Dec 06 10:34:20 2009 +0000 @@ -129,5 +129,4 @@ FilterCarbide.stdout.write("Overall Errors: %d\n" % self.__errors) FilterCarbide.stdout.write("Overall Warnings: %d\n\n" % self.__warnings) - return True if self.__errors == 0 else False - + return (self.__errors == 0) diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/plugins/filter_checksource.py --- a/sbsv2/raptor/python/plugins/filter_checksource.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/plugins/filter_checksource.py Sun Dec 06 10:34:20 2009 +0000 @@ -221,8 +221,8 @@ # so we only check each one once depset = set(deps) deplistnodups = list(depset) + # Do the check for each file - for dep in deplistnodups: dep = os.path.abspath(dep).replace('\\', '/') self.checksource(dep) diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/plugins/filter_logfile.py --- a/sbsv2/raptor/python/plugins/filter_logfile.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/plugins/filter_logfile.py Sun Dec 06 10:34:20 2009 +0000 @@ -16,6 +16,7 @@ # Will ultimately do everything that scanlog does # +import errno import os import sys import raptor @@ -38,7 +39,7 @@ if dirname and not os.path.isdir(dirname): os.makedirs(dirname) except os.error, e: - if e.errno != os.errno.EEXIST: + if e.errno != errno.EEXIST: sys.stderr.write("%s : error: cannot create directory %s\n" % \ (str(raptor.name), dirname)) return False diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/plugins/filter_splitlog.py --- a/sbsv2/raptor/python/plugins/filter_splitlog.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/plugins/filter_splitlog.py Sun Dec 06 10:34:20 2009 +0000 @@ -16,6 +16,7 @@ # Will ultimately do everything that scanlog does # +import errno import os import sys import raptor @@ -38,7 +39,7 @@ if dirname and not os.path.isdir(dirname): os.makedirs(dirname) except os.error, e: - if e.errno != os.errno.EEXIST: + if e.errno != errno.EEXIST: sys.stderr.write("%s : error: cannot create directory " + "%s\n" % (raptor.name, dirname)) return False diff -r d82b03c7df17 -r 32f524d09c94 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 Sun Dec 06 10:34:20 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 d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/raptor.py --- a/sbsv2/raptor/python/raptor.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/raptor.py Sun Dec 06 10:34:20 2009 +0000 @@ -34,6 +34,7 @@ import raptor_make import raptor_makefile import raptor_meta +import raptor_timing import raptor_utilities import raptor_version import raptor_xml @@ -181,11 +182,17 @@ # insert the start time into the Makefile name? makefile.path = makefile.path.replace("%TIME", build.timestring) + build.InfoDiscovery(object_type = "layers", count = 1) + build.InfoStartTime(object_type = "layer", task = "parse", + key = str(makefile.path)) makefileset = build.maker.Write(makefile, specs, build.buildUnitsToBuild) + build.InfoEndTime(object_type = "layer", task = "parse", + key = str(makefile.path)) return makefileset + def realise(self, build): """Give the spec trees to the make engine and actually "build" the product represented by this model node""" @@ -198,7 +205,15 @@ m = self.realise_makefile(build, sp) - return build.Make(m) + build.InfoStartTime(object_type = "layer", task = "build", + key = (str(m.directory) + "/" + str(m.filenamebase))) + result = build.Make(m) + build.InfoEndTime(object_type = "layer", task = "build", + key = (str(m.directory) + "/" + str(m.filenamebase))) + + + return result + class Project(ModelNode): @@ -307,6 +322,9 @@ if build.quiet == True: cli_options += " -q" + + if build.timing == True: + cli_options += " --timing" nc = len(self.children) @@ -377,20 +395,22 @@ spec_nodes.append(specNode) binding_makefiles.addInclude(str(makefile_path)+"_all") - ppstart = time.time() - build.Info("Parallel Parsing: time: Start %d", int(ppstart)) + build.InfoDiscovery(object_type = "layers", count = 1) + build.InfoStartTime(object_type = "layer", task = "parse", + key = str(build.topMakefile)) m = self.realise_makefile(build, spec_nodes) m.close() gen_result = build.Make(m) - ppfinish = time.time() - build.Info("Parallel Parsing: time: Finish %d", int(ppfinish)) - build.Info("Parallel Parsing: time: Parse Duration %d", int(ppfinish - ppstart)) + build.InfoEndTime(object_type = "layer", task = "parse", + key = str(build.topMakefile)) + build.InfoStartTime(object_type = "layer", task = "build", + key = str(build.topMakefile)) build.Debug("Binding Makefile base name is %s ", binding_makefiles.filenamebase) binding_makefiles.close() b = build.Make(binding_makefiles) - buildfinish = time.time() - build.Info("Parallel Parsing: time: Build Duration %d", int(buildfinish - ppfinish)) + build.InfoEndTime(object_type = "layer", task = "build", + key = str(build.topMakefile)) return b @@ -493,6 +513,7 @@ # what platform and filesystem are we running on? self.filesystem = raptor_utilities.getOSFileSystem() + self.timing = False self.toolset = None self.starttime = time.time() @@ -648,11 +669,17 @@ return False return True + + def SetTiming(self, TrueOrFalse): + self.timing = TrueOrFalse + return True def SetParallelParsing(self, type): type = type.lower() if type == "on": self.doParallelParsing = True + elif type == "slave": + self.isParallelParsingSlave = True elif type == "off": self.doParallelParsing = False else: @@ -1048,10 +1075,11 @@ self.out.write("\n") namespace = "http://symbian.com/xml/build/log" + progress_namespace = "http://symbian.com/xml/build/log/progress" schema = "http://symbian.com/xml/build/log/1_0.xsd" - self.out.write("\n" - % (raptor_version.fullversion(), namespace, namespace, schema)) + self.out.write("\n" + % (raptor_version.fullversion(), namespace, progress_namespace, namespace, schema)) self.logOpen = True except Exception,e: self.out = sys.stdout # make sure that we can actually get errors out. @@ -1088,6 +1116,30 @@ """ self.out.write("" + escape(format % extras) + "\n") + + def InfoDiscovery(self, object_type, count): + if self.timing: + try: + self.out.write(raptor_timing.Timing.discovery_string(object_type = object_type, + count = count)) + except Exception, exception: + Error(exception.Text, function = "InfoDiscoveryTime") + + def InfoStartTime(self, object_type, task, key): + if self.timing: + try: + self.out.write(raptor_timing.Timing.start_string(object_type = object_type, + task = task, key = key)) + except Exception, exception: + Error(exception.Text, function = "InfoStartTime") + + def InfoEndTime(self, object_type, task, key): + if self.timing: + try: + self.out.write(raptor_timing.Timing.end_string(object_type = object_type, + task = task, key = key)) + except Exception, exception: + Error(exception.Text, function = "InfoEndTime") def Debug(self, format, *extras, **attributes): "Send a debugging message to the configured channel" diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/raptor_cli.py --- a/sbsv2/raptor/python/raptor_cli.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/raptor_cli.py Sun Dec 06 10:34:20 2009 +0000 @@ -147,10 +147,15 @@ "forced" - Check all tool versions. Don't use cached results. """) + +parser.add_option("--timing",action="store_true",dest="timing", + help="Show extra timing information for various processes in the build.") + parser.add_option("--pp",action="store",dest="parallel_parsing", help="""Controls how metadata (e.g. bld.infs) are parsed in Parallel. Possible values are: "on" - Parse bld.infs in parallel (should be faster on clusters/multicore machines) + "slave" - used internally by Raptor "off" - Parse bld.infs serially """) @@ -277,6 +282,7 @@ 'what' : Raptor.SetWhat, 'tries' : Raptor.SetTries, 'toolcheck' : Raptor.SetToolCheck, + 'timing' : Raptor.SetTiming, 'source_target' : Raptor.AddSourceTarget, 'command_file' : CommandFile, 'parallel_parsing' : Raptor.SetParallelParsing, diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/raptor_make.py --- a/sbsv2/raptor/python/raptor_make.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/raptor_make.py Sun Dec 06 10:34:20 2009 +0000 @@ -20,6 +20,7 @@ import os import random import raptor +import raptor_timing import raptor_utilities import raptor_version import raptor_data @@ -27,7 +28,6 @@ import subprocess import time from raptor_makefile import * -import raptor_version import traceback import sys @@ -135,9 +135,23 @@ USE_TALON:= """ - + + + timing_start = "$(info " + \ + raptor_timing.Timing.custom_string(tag = "start", + object_type = "makefile", task = "parse", + key = "$(THIS_FILENAME)", + time="$(shell date +%s.%N)").rstrip("\n") + ")" + + timing_end = "$(info " + \ + raptor_timing.Timing.custom_string(tag = "end", + object_type = "makefile", task = "parse", + key = "$(THIS_FILENAME)", + time="$(shell date +%s.%N)").rstrip("\n") + ")" + self.makefile_prologue = """ + # generated by %s %s HOSTPLATFORM:=%s @@ -145,6 +159,7 @@ OSTYPE:=%s FLMHOME:=%s SHELL:=%s +THIS_FILENAME:=$(firstword $(MAKEFILE_LIST)) %s @@ -159,8 +174,18 @@ talon_settings, self.raptor.systemFLM.Append('globals.mk') ) + # Only output timings if requested on CLI + if self.raptor.timing: + self.makefile_prologue += "\n# Print Start-time of Makefile parsing\n" \ + + timing_start + "\n\n" + + + self.makefile_epilogue = "\n\n# Print End-time of Makefile parsing\n" \ + + timing_end + "\n" + else: + self.makefile_epilogue = "" - self.makefile_epilogue = """ + self.makefile_epilogue += """ include %s @@ -365,6 +390,9 @@ if clean_flag: fileName_list.reverse() + # Report number of makefiles to be built + self.raptor.InfoDiscovery(object_type = "makefile", count = len(fileName_list)) + # Process each file in turn for makefile in fileName_list: if not os.path.exists(makefile): @@ -431,6 +459,10 @@ # bufsize=1 means "line buffered" # try: + # Time the build + self.raptor.InfoStartTime(object_type = "makefile", + task = "build", key = str(makefile)) + makeenv=os.environ.copy() if self.usetalon: makeenv['TALON_RECIPEATTRIBUTES']="none" @@ -458,6 +490,9 @@ # should be done now returncode = p.wait() + # Report end-time of the build + self.raptor.InfoEndTime(object_type = "makefile", + task = "build", key = str(makefile)) if returncode != 0 and not self.raptor.keepGoing: self.Tidy() @@ -466,6 +501,9 @@ except Exception,e: self.raptor.Error("Exception '%s' during '%s'", str(e), command) self.Tidy() + # Still report end-time of the build + self.raptor.InfoEnd(object_type = "Building", task = "Makefile", + key = str(makefile)) return False # run any shutdown script diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/raptor_meta.py --- a/sbsv2/raptor/python/raptor_meta.py Sun Dec 06 08:59:11 2009 +0000 +++ b/sbsv2/raptor/python/raptor_meta.py Sun Dec 06 10:34:20 2009 +0000 @@ -297,9 +297,8 @@ def call(self, aArgs, sourcefilename): """ Override call so that we can do our own error handling.""" tool = self._ExternalTool__Tool + commandline = tool + " " + aArgs + " " + str(sourcefilename) try: - commandline = tool + " " + aArgs + " " + str(sourcefilename) - # the actual call differs between Windows and Unix if raptor_utilities.getOSFileSystem() == "unix": p = subprocess.Popen(commandline, \ @@ -345,7 +344,7 @@ raise MetaDataError("Errors in %s" % str(sourcefilename)) except Exception,e: - raise MetaDataError("Preprocessor exception: %s" % str(e)) + raise MetaDataError("Preprocessor exception: '%s' : in command : '%s'" % (str(e), commandline)) return 0 # all OK @@ -2652,8 +2651,8 @@ def LeftPortionOf(pth,sep): """ Internal function to return portion of str that is to the left of sep. - The partition is case-insentive.""" - length = len((pth.lower().partition(sep.lower()))[0]) + The split is case-insensitive.""" + length = len((pth.lower().split(sep.lower()))[0]) return pth[0:length] modulePath = LeftPortionOf(LeftPortionOf(os.path.dirname(aBldInfPath), "group"), "ongoing") @@ -2930,6 +2929,11 @@ expfile = open(expfilename, 'wb') expfile.write(exportzip.read(file)) expfile.close() + + # Resurrect any file execution permissions present in the archived version + if (exportzip.getinfo(file).external_attr >> 16L) & 0100: + os.chmod(expfilename, stat.S_IMODE(os.stat(expfilename).st_mode) | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH) + # Each file keeps its modified time the same as what it was before unzipping accesstime = time.time() datetime = exportzip.getinfo(file).date_time diff -r d82b03c7df17 -r 32f524d09c94 sbsv2/raptor/python/raptor_timing.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/sbsv2/raptor/python/raptor_timing.py Sun Dec 06 10:34:20 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