sbsv2/raptor/bin/grokbuild.py
author Mike Kinghan <mikek@symbian.org>
Mon, 15 Nov 2010 10:57:53 +0000
changeset 39 fa9d7d89d3d6
parent 28 b8fa7dfeeaa1
permissions -rw-r--r--
A couple more small Windows compatibility fixes for romnibus.pl
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
28
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     1
#!/usr/bin/env python
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     2
#
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     4
# All rights reserved.
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     5
# This component and the accompanying materials are made available
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     6
# under the terms of the License "Eclipse Public License v1.0"
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     7
# which accompanies this distribution, and is available
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     8
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
     9
#
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    10
# Initial Contributors:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    11
# Nokia Corporation - initial contribution.
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    12
#
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    13
# Contributors:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    14
#
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    15
# Description: 
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    16
# grokbuild
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    17
#
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    18
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    19
"""
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    20
Gathers performance metrics from the logs of a complex multi-step build.
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    21
Supports Helium 9 at the moment but is adaptable.
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    22
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    23
Can read from emake annotation files.  
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    24
"""
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    25
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    26
import sys
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    27
import os
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    28
import re
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    29
from  optparse import OptionParser
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    30
import annofile
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    31
import datetime
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    32
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    33
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    34
class UndeterminedBuildID(Exception):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    35
	pass
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    36
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    37
class LogfileNotFound(Exception):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    38
	pass
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    39
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    40
class HeliumLog(object):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    41
	""" Some common properties of any log file in a helium build """
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    42
	filenamesuffix = None
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    43
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    44
	def __init__(self, logpath, buildid, options=None):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    45
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    46
		self.logfilename = os.path.join(logpath, buildid + self.filenamesuffix)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    47
		self.buildid = buildid
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    48
		self.options = options
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    49
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    50
	@classmethod
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    51
	def findall(c, logpath):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    52
		""" Find all the logs that are of this type - essentially also finds all builds 
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    53
		    which dumped their output in the same place """
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    54
		filename_re = re.compile('(.*/)?(?P<buildid>[^\\\/]*)' + c.filenamesuffix)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    55
		logs = {}
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    56
		for f in os.listdir(logpath):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    57
			m = filename_re.match(f)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    58
			if m:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    59
				file_buildid = m.groupdict()['buildid']
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    60
				logs[file_buildid] = os.path.join(logpath,f)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    61
		return logs
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    62
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    63
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    64
	def __str__(self):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    65
		return "<metric name='buildid'  value='%s'>\n" % self.buildid
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    66
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    67
class MainAntLog(HeliumLog):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    68
	""" This is the primary log of the helium build.  Useful for obtaining the total build time. Not good for this if the build failed. """
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    69
	# output/logs/92_7952_201020_003_main.ant.log
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    70
	filenamesuffix = "_main.ant.log"
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    71
	timeformat = "%Y/%m/%d %H:%M:%S:%f" # e.g. Thu 2010/06/24 09:15:42:625 AM
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    72
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    73
	def __init__(self, logpath, buildid, options=None):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    74
		super(MainAntLog,self).__init__(logpath, buildid, options)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    75
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    76
		# Starting logging into y:\output\logs\mcl_7901_201024_20100623181534_main.ant.log at Wed 2010/06/23 21:16:12:972 PM
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    77
		# Stopping logging into y:\output\logs\mcl_7901_201024_20100623181534_main.ant.log from hlm:record task at Thu 2010/06/24 09:15:42:625 AM
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    78
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    79
		start_re = re.compile("Starting logging into [^ ]+ at ... ([^ ]+ +[^ ]+) .*")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    80
		stop_re = re.compile("Stopping logging into [^ ]+ from [^ ]+ task at ... ([^ ]+ +[^ ]+) (AM)|(PM).*")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    81
		start_time = None
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    82
		stop_time = None
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    83
		with open(self.logfilename) as f:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    84
			for l in f:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    85
				if start_time is None:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    86
					m = start_re.match(l)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    87
					if m:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    88
						#sys.stderr.write("start TIME: %s\n" %m.groups()[0])
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    89
						start_time = datetime.datetime.strptime(m.groups()[0], self.timeformat)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    90
						
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    91
				else: # if there are many stop lines then make sure the last one overrides the others
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    92
					m = stop_re.match(l)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    93
					if m:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    94
						stop_time = datetime.datetime.strptime(m.groups()[0], self.timeformat)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    95
						#sys.stderr.write("stop TIME: %s\n" %m.groups()[0])
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    96
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    97
		#sys.stderr.write("build start/stop: %s / %s  from %s\n" % (start_time, stop_time, self.logfilename))
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    98
		build_duration = stop_time - start_time  # returns a timedelta object
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
    99
		self.build_duration = build_duration.seconds +  86400 * build_duration.days  # seconds
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   100
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   101
	def __str__(self):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   102
		return "<metric name='build_duration'  value='%d'>\n" % self.build_duration
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   103
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   104
class AntEnvLog(HeliumLog):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   105
	# output/logs/92_7952_201020_003_ant_env.log
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   106
	filenamesuffix = "_ant_env.log"
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   107
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   108
	def __init__(self, logpath, buildid):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   109
		super(AntEnvLog,self).__init__(logpath, buildid)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   110
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   111
class TargetTimesLog(HeliumLog):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   112
	"""Very useful timing data from Ant but does not get created in all builds by default (must be configured"""
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   113
	# output/logs/92_7952_custom_dilbert_201022_dilbert_targetTimesLog.csv
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   114
	filenamesuffix = "_targetTimesLog.csv"
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   115
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   116
	def __init__(self, logpath, buildid):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   117
		super(TargetTimesLog,self).__init__(logpath, buildid)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   118
		self.raptorsecs = 0
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   119
		self.totalsecs = 0
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   120
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   121
		with open(self.logfilename) as f:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   122
			for ll in f:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   123
				l = ll.rstrip("\n")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   124
				#print self.logfilename
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   125
				#print "L:",l
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   126
				(rname, rsecs) = l.split(",")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   127
				rsecs = int(rsecs)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   128
				#print "rname, rsecs: %s %d"%(rname,rsecs)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   129
				self.totalsecs += rsecs
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   130
				if rname == "compile-sbs":
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   131
					self.raptorsecs += rsecs
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   132
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   133
	def __str__(self):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   134
		s = "<metric name='build_duration'  value='%s'>" % self.totalsecs  \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   135
			+ "\n<metric name='raptor_duration'  value='%s'>\n" % self.raptorsecs
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   136
		return s
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   137
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   138
class RaptorAnnofile(object):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   139
	"""Thin wrapper around the annofile class to make it relevant to this utility."""
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   140
	# Examples:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   141
	# 92_7952_custom_dilbert_201022_dilbert_dfs_build_sf_tools_all.resource.emake.anno
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   142
	# 92_7952_custom_dilbert_201022_dilbert_dfs_build_sf_dfs_variants.default.emake.anno
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   143
	# 92_7952_201022_003_dfs_build_ncp_dfs_variants.resource_deps.emake.anno
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   144
	def __init__(self, filename, buildid, maxagents):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   145
		self.phase = ""
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   146
		self.filename = filename
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   147
		self.buildid = buildid
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   148
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   149
		self.annofile = annofile.Annofile(self.filename, maxagents)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   150
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   151
	def __str__(self):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   152
		return "<annofile name='%s' phase='%s'>\n%s</annofile>\n" \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   153
	         % (os.path.basename(self.filename), self.phase, str(self.annofile))
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   154
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   155
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   156
class RaptorBuild(HeliumLog):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   157
	"""Any Raptor logfile.  Mainly used for getting the names of the 
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   158
	annotation files which the annofile parser will use. Also gets
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   159
	the version of raptor and the total time taken by this particular
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   160
	invocation of Raptor"""
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   161
	def __init__(self, logpath, buildid, build, options=None):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   162
		self.filenamesuffix = '_%s' % build
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   163
		super(RaptorBuild,self).__init__(os.path.join(logpath, "compile"), buildid, options)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   164
		self.build = build
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   165
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   166
		if not os.path.isfile(self.logfilename):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   167
			raise LogfileNotFound("missing log file: %s\n" % self.logfilename)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   168
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   169
		self.annofile_refs = []	
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   170
		self.build_duration = None
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   171
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   172
		status_re = re.compile("<status exit='([a-z]+)'")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   173
		emake_invocation_re = re.compile("<info>Executing.*--emake-annofile=([^ ]+)")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   174
		emake_maxagents_re = re.compile("--emake-maxagents=(\d+)")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   175
		sbs_version_re = re.compile("<info>sbs: version ([^\n\r]*)")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   176
		run_time_re = re.compile("<info>Run time ([0-9]+) seconds</info>")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   177
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   178
		self.recipes = { 'TOTAL':0, 'ok':0, 'failed':0, 'retry':0 }
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   179
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   180
		with open(self.logfilename) as f:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   181
			sys.stderr.write("      parsing build log %s\n" % os.path.split(self.logfilename)[1])
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   182
			for l in f:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   183
				# match in order of likelihood (most probable first)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   184
				
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   185
				m = status_re.match(l)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   186
				if m:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   187
					self.recipes['TOTAL'] += 1
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   188
					status = m.group(1)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   189
					try:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   190
						self.recipes[status] += 1
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   191
					except KeyError:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   192
						sys.stderr.write("unknown recipe status '%s'" % status)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   193
					continue
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   194
				
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   195
				m = emake_invocation_re.match(l)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   196
				if m:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   197
					(adir, aname) = os.path.split(m.group(1))
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   198
					if aname.find("pp")==-1: # no parallel parsing ones preferably
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   199
						sys.stderr.write("        found annotation file %s\n" % aname)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   200
						
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   201
						# if --emake-maxagents is present then use that, otherwise use
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   202
						# the value passed in through the options.
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   203
						m = emake_maxagents_re.match(l)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   204
						if m:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   205
							maxagents = int(m.group(1))
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   206
						else:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   207
							maxagents = options.maxagents
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   208
							sys.stderr.write("          using maxagents %d as there is no record in the logs\n" % maxagents)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   209
							
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   210
						self.annofile_refs.append( (os.path.join(logpath, "makefile", aname), maxagents) )
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   211
					continue
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   212
				
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   213
				m = run_time_re.match(l)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   214
				if m:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   215
					self.build_duration = int(m.group(1))
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   216
					continue
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   217
					
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   218
				m = sbs_version_re.match(l)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   219
				if m:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   220
					self.version = m.group(1)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   221
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   222
		self.annofiles = []
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   223
		for p in self.annofile_refs:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   224
			self.annofiles.append(RaptorAnnofile(p[0], buildid, p[1]))
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   225
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   226
	def __str__(self):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   227
		recipes = [" <metric name='raptor_%s_recipes' value='%d'/>\n" % x for x in self.recipes.items()]
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   228
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   229
		return 	"<raptorbuild logfile='%s'>\n" % os.path.split(self.logfilename)[-1] + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   230
			" <metric name='raptor_version'  value='%s' />\n" % (self.version) + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   231
			" <metric name='raptor_duration_%s'  value='%d' />\n" % (self.build, self.build_duration) + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   232
			"".join(recipes) + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   233
			"".join([str(a) for a in self.annofiles]) + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   234
			"</raptorbuild>\n"
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   235
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   236
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   237
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   238
class HeliumBuild(object):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   239
	"""A build with any version of Helium"""
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   240
	def __init__(self, logpath, buildid, options=None):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   241
		self.options = options
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   242
		self.buildid = buildid
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   243
		self.logpath = logpath
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   244
		self.logfiles=[]
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   245
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   246
	def __str__(self):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   247
		return  self.buildid + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   248
			"\n"+[str(a) for a in self.annofiles] + "\n"
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   249
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   250
class Helium9Build(HeliumBuild):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   251
	""" Filenames, structure etc conform to Helium 9 """
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   252
	def __init__(self, logpath, buildid, options=None):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   253
		super(Helium9Build,self).__init__(logpath, buildid, options)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   254
		self.mainantlog = MainAntLog(logpath, buildid, options)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   255
		self.raptorbuilds = []
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   256
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   257
		# mcl_7901_201024_20100623181534_dfs_build_ncp_variants.build_input_compile.log
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   258
		# mcl_7901_201024_20100623181534_dfs_build_sf_variants.build_input_compile.log
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   259
		# mcl_7901_201024_20100623181534_dfs_build_winscw_dfs_build_winscw_input_compile.log
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   260
		#
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   261
		# ....but the problem is that the anno files have a slightly differing convention:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   262
		#        92_7952_201022_003_dfs_build_ncp_dfs_variants.resource_deps.emake.anno
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   263
		#  _dfs_build_ncp_variants
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   264
		#  _dfs_build_ncp_dfs_variants
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   265
                # read the annofile names from inside the raptor log output
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   266
		for r in ["dfs_build_ncp_variants.build_input_compile.log","dfs_build_sf_variants.build_input_compile.log","dfs_build_winscw_dfs_build_winscw_input_compile.log", "ncp_symbian_build_symtb_input_compile.log"]:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   267
			try:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   268
				self.raptorbuilds.append(RaptorBuild(logpath, buildid, r, options))
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   269
			except LogfileNotFound, ex:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   270
				sys.stderr.write(str(ex))
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   271
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   272
	def __str__(self):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   273
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   274
		raptor_duration = reduce(lambda x, y: x + y,[y.build_duration for y in self.raptorbuilds],0)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   275
		return "<heliumbuild ver='9' id='%s'>\n" % (self.buildid) + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   276
			"<metric name='total_duration'  value='%d' />\n" % (self.mainantlog.build_duration) + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   277
			"<metric name='raptor_duration'  value='%d' />\n" % (raptor_duration) + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   278
	 		"".join([str(a) for a in self.raptorbuilds ]) + \
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   279
	 		"</heliumbuild>\n"
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   280
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   281
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   282
class HeliumLogDir(object):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   283
	"""Multiple builds can be done one after another (usually when rebuilding 
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   284
	   things that failed, apparently) and their logs left in the output dir.
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   285
	   The naming convention ensures that they don't overwrite each other.
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   286
	   This class identifies each build and tries to analyse them one by one."""
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   287
	def __init__(self, epocroot, options=None):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   288
		self.logpath = os.path.join(epocroot, "output/logs")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   289
		logs = MainAntLog.findall(self.logpath)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   290
		self.builds = []
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   291
		
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   292
		for b in logs.keys():
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   293
			try:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   294
				sys.stderr.write("  Found build with id %s\n" % b)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   295
				build = Helium9Build(self.logpath, b, options)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   296
				self.builds.append(build)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   297
			except IOError,e:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   298
				sys.stderr.write("  Buildid %s found but does not refer to a complete build\n" % b)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   299
				sys.stderr.write(str(e)+"\n")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   300
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   301
	def write(self, stream):
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   302
		for b in self.builds:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   303
			stream.write(str(b)+"\n")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   304
 
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   305
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   306
parser = OptionParser(prog = "grokbuild",
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   307
                      usage = """%prog [-h | options] path_to_EPOCROOT 
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   308
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   309
The build logs are usually in $EPOCROOT/output/logs""")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   310
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   311
parser.add_option("--maxagents", type="int", dest="maxagents", default=30,
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   312
				 help="The number of simultaneous agents used in the build. You need to supply this if --emake-class was used rather than --emake-maxagents since this is then a property of the build cluster and is not usually recorded in the logs. The default is %default."
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   313
				 )
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   314
(options, args) = parser.parse_args()
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   315
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   316
if len(args) == 0:
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   317
	sys.stderr.write("Need at least one argument: a path to the logs.\n")
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   318
	sys.exit(-1)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   319
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   320
epocroot = args[0]
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   321
sys.stderr.write("Gathering Performance Metrics for %s\n" % epocroot)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   322
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   323
b = HeliumLogDir(epocroot, options)
b8fa7dfeeaa1 Update Raptor to v2.15.2
Mike Kinghan <mikek@symbian.org>
parents:
diff changeset
   324
b.write(sys.stdout)