sbsv2/raptor/bin/recipestats.py
author yiluzhu
Tue, 23 Feb 2010 14:22:19 +0000
branchfix
changeset 247 8426d4dedf84
parent 100 55250667c668
child 485 926e968477c6
permissions -rwxr-xr-x
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
88
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
     1
#!/usr/bin/env python
87
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
     2
#
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
     3
# Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
     4
# All rights reserved.
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
     5
# This component and the accompanying materials are made available
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
     6
# under the terms of the License "Eclipse Public License v1.0"
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
     7
# which accompanies this distribution, and is available
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
     8
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
     9
#
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    10
# Initial Contributors:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    11
# Nokia Corporation - initial contribution.
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    12
#
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    13
# Contributors:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    14
#
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    15
# Description: 
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    16
# 
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    17
# display summary information about recipes from raptor logs
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    18
# e.g. total times and so on.
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    19
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    20
import time
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    21
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    22
class RecipeStats(object):
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    23
	STAT_OK = 0
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    24
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    25
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    26
	def __init__(self):
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    27
		self.stats = {}
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    28
		self.failcount = 0
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    29
		self.failtime = 0.0
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    30
		self.failtypes = {}
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    31
		self.retryfails = 0
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    32
		
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    33
	def add(self, starttime, duration, name, status):
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    34
		if status != RecipeStats.STAT_OK:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    35
			self.failcount += 1
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    36
			if name in self.failtypes:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    37
				self.failtypes[name] += 1
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    38
			else:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    39
				self.failtypes[name] = 1
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    40
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    41
			if status == 128:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    42
				self.retryfails += 1
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    43
			return
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    44
			
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    45
		if name in self.stats:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    46
			(count, time) = self.stats[name]
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    47
			self.stats[name] = (count + 1, time + duration)
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    48
		else:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    49
			self.stats[name] = (1,duration)
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    50
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    51
	def recipe_csv(self):
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    52
		s = "# name, time, count\n"
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    53
		for (name,(count,time)) in self.stats.iteritems():
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    54
			s += '"%s",%s,%d\n' % (name, str(time), count)
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    55
		return s
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    56
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    57
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    58
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    59
import sys
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    60
import re
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    61
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    62
def main():
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    63
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    64
	f = sys.stdin
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    65
	st = RecipeStats()
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    66
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    67
	recipe_re = re.compile(".*<recipe name='([^']+)'.*")
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    68
	time_re = re.compile(".*<time start='([0-9]+\.[0-9]+)' *elapsed='([0-9]+\.[0-9]+)'.*")
88
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    69
	status_re = re.compile(".*<status exit='(?P<exit>(ok|failed))'( *code='(?P<code>[0-9]+)')?.*")
87
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    70
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    71
	alternating = 0
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    72
	start_time = 0.0
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    73
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    74
	
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    75
	for l in f.xreadlines():
88
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    76
		l2 = l.rstrip("\n\r")
87
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    77
		rm = recipe_re.match(l2)
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    78
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    79
		if rm is not None:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    80
			rname = rm.groups()[0]
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    81
			continue
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    82
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    83
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    84
		tm = time_re.match(l2)
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    85
		if tm is not None:
88
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    86
			try:
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    87
				s = float(tm.groups()[0])
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    88
				elapsed = float(tm.groups()[1])
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    89
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    90
				if start_time == 0.0:
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    91
					start_time = s
87
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    92
88
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    93
				s -= start_time
87
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
    94
88
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    95
				continue
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    96
			except ValueError, e:
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    97
				raise Exception("Parse problem: float conversion on these groups: %s\n%s" %(str(tm.groups()), str(e)))
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    98
		else:
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
    99
			if l2.find("<time") is not -1:
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
   100
				raise Exception("unparsed timing status: %s\n"%l2)
87
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   101
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   102
		sm = status_re.match(l2)
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   103
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   104
		if sm is None:
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   105
			continue
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   106
88
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
   107
		if sm.groupdict()['exit'] == 'ok':
87
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   108
			status = 0
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   109
		else:
88
b5820d0f3a1c Fix errors with parsing exit codes in status tags
timothy.murphy@nokia.com
parents: 87
diff changeset
   110
			status = int(sm.groupdict()['code'])
87
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   111
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   112
		st.add(s, elapsed, rname, status)
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   113
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   114
	print st.recipe_csv()
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   115
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   116
01cb4707f979 Added a script for finding out how time each class of recipes took in the build
timothy.murphy@nokia.com
parents:
diff changeset
   117
if __name__ == '__main__': main()