16 # |
16 # |
17 # display summary information about recipes from raptor logs |
17 # display summary information about recipes from raptor logs |
18 # e.g. total times and so on. |
18 # e.g. total times and so on. |
19 |
19 |
20 import time |
20 import time |
|
21 import __future__ |
21 |
22 |
22 class RecipeStats(object): |
23 class RecipeStats(object): |
|
24 def __init__(self, name, count, time): |
|
25 self.name=name |
|
26 self.count=count |
|
27 self.time=time |
|
28 |
|
29 def add(self, duration): |
|
30 self.time += duration |
|
31 |
|
32 class BuildStats(object): |
23 STAT_OK = 0 |
33 STAT_OK = 0 |
24 |
34 |
25 |
35 |
26 def __init__(self): |
36 def __init__(self): |
27 self.stats = {} |
37 self.stats = {} |
29 self.failtime = 0.0 |
39 self.failtime = 0.0 |
30 self.failtypes = {} |
40 self.failtypes = {} |
31 self.retryfails = 0 |
41 self.retryfails = 0 |
32 |
42 |
33 def add(self, starttime, duration, name, status): |
43 def add(self, starttime, duration, name, status): |
34 if status != RecipeStats.STAT_OK: |
44 if status != BuildStats.STAT_OK: |
35 self.failcount += 1 |
45 self.failcount += 1 |
36 if name in self.failtypes: |
46 if name in self.failtypes: |
37 self.failtypes[name] += 1 |
47 self.failtypes[name] += 1 |
38 else: |
48 else: |
39 self.failtypes[name] = 1 |
49 self.failtypes[name] = 1 |
41 if status == 128: |
51 if status == 128: |
42 self.retryfails += 1 |
52 self.retryfails += 1 |
43 return |
53 return |
44 |
54 |
45 if name in self.stats: |
55 if name in self.stats: |
46 (count, time) = self.stats[name] |
56 r = self.stats[name] |
47 self.stats[name] = (count + 1, time + duration) |
57 r.add(duration) |
48 else: |
58 else: |
49 self.stats[name] = (1,duration) |
59 self.stats[name] = RecipeStats(name,1,duration) |
50 |
60 |
51 def recipe_csv(self): |
61 def recipe_csv(self): |
52 s = "# name, time, count\n" |
62 s = '"name", "time", "count"\n' |
53 for (name,(count,time)) in self.stats.iteritems(): |
63 l = sorted(self.stats.values(), key= lambda r: r.time, reverse=True) |
54 s += '"%s",%s,%d\n' % (name, str(time), count) |
64 for r in l: |
|
65 s += '"%s",%s,%d\n' % (r.name, str(r.time), r.count) |
55 return s |
66 return s |
56 |
67 |
57 |
68 |
58 |
69 |
59 import sys |
70 import sys |
60 import re |
71 import re |
61 |
72 |
62 def main(): |
73 def main(): |
63 |
74 |
64 f = sys.stdin |
75 f = sys.stdin |
65 st = RecipeStats() |
76 st = BuildStats() |
66 |
77 |
67 recipe_re = re.compile(".*<recipe name='([^']+)'.*") |
78 recipe_re = re.compile(".*<recipe name='([^']+)'.*") |
68 time_re = re.compile(".*<time start='([0-9]+\.[0-9]+)' *elapsed='([0-9]+\.[0-9]+)'.*") |
79 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]+)')?.*") |
80 status_re = re.compile(".*<status exit='(?P<exit>(ok|failed))'( *code='(?P<code>[0-9]+)')?.*") |
70 |
81 |
109 else: |
120 else: |
110 status = int(sm.groupdict()['code']) |
121 status = int(sm.groupdict()['code']) |
111 |
122 |
112 st.add(s, elapsed, rname, status) |
123 st.add(s, elapsed, rname, status) |
113 |
124 |
114 print st.recipe_csv() |
125 print(st.recipe_csv()) |
115 |
126 |
116 |
127 |
117 if __name__ == '__main__': main() |
128 if __name__ == '__main__': main() |