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