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