author | Zheng Shen <zheng.shen@nokia.com> |
Wed, 13 Oct 2010 16:27:55 +0800 | |
changeset 647 | 53d1ab72f5bc |
parent 625 | a1925fb7753a |
permissions | -rw-r--r-- |
591 | 1 |
#!/usr/bin/env python |
2 |
# |
|
3 |
# Copyright (c) 2007-2010 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 |
import __future__ |
|
22 |
||
23 |
||
24 |
||
25 |
||
26 |
class RecipeStats(object): |
|
27 |
def __init__(self, name, count, time): |
|
28 |
self.name=name |
|
29 |
self.count=count |
|
30 |
self.time=time |
|
31 |
||
32 |
def add(self, duration): |
|
33 |
self.time += duration |
|
625
a1925fb7753a
sbs version 2.15.0
Richard Taylor <richard.i.taylor@nokia.com>
parents:
591
diff
changeset
|
34 |
self.count += 1 |
591 | 35 |
|
36 |
class BuildStats(object): |
|
37 |
STAT_OK = 0 |
|
38 |
||
39 |
||
40 |
def __init__(self): |
|
41 |
self.stats = {} |
|
42 |
self.failcount = 0 |
|
43 |
self.failtime = 0.0 |
|
44 |
self.failtypes = {} |
|
45 |
self.retryfails = 0 |
|
46 |
self.hosts = {} |
|
47 |
||
48 |
def add(self, starttime, duration, name, status, host, phase): |
|
49 |
if status != BuildStats.STAT_OK: |
|
50 |
self.failcount += 1 |
|
51 |
if name in self.failtypes: |
|
52 |
self.failtypes[name] += 1 |
|
53 |
else: |
|
54 |
self.failtypes[name] = 1 |
|
55 |
||
56 |
if status == 128: |
|
57 |
self.retryfails += 1 |
|
58 |
return |
|
59 |
||
60 |
if name in self.stats: |
|
61 |
r = self.stats[name] |
|
62 |
r.add(duration) |
|
63 |
else: |
|
64 |
self.stats[name] = RecipeStats(name,1,duration) |
|
65 |
||
66 |
hp=host |
|
67 |
if hp in self.hosts: |
|
68 |
self.hosts[hp] += 1 |
|
69 |
else: |
|
70 |
self.hosts[hp] = 1 |
|
71 |
||
72 |
def recipe_csv(self): |
|
73 |
s = '"name", "time", "count"\n' |
|
74 |
l = sorted(self.stats.values(), key= lambda r: r.time, reverse=True) |
|
75 |
for r in l: |
|
76 |
s += '"%s",%s,%d\n' % (r.name, str(r.time), r.count) |
|
77 |
return s |
|
78 |
||
79 |
def hosts_csv(self): |
|
80 |
s='"host","recipecount"\n' |
|
81 |
hs = self.hosts |
|
82 |
for h in sorted(hs.keys()): |
|
83 |
s += '"%s",%d\n' % (h,hs[h]) |
|
84 |
return s |
|
85 |
||
86 |
||
87 |
import sys |
|
88 |
import re |
|
89 |
import os |
|
90 |
from optparse import OptionParser # for parsing command line parameters |
|
91 |
||
92 |
def main(): |
|
93 |
recipe_re = re.compile(".*<recipe name='([^']+)'.*host='([^']+)'.*") |
|
94 |
time_re = re.compile(".*<time start='([0-9]+\.[0-9]+)' *elapsed='([0-9]+\.[0-9]+)'.*") |
|
95 |
status_re = re.compile(".*<status exit='(?P<exit>(ok|failed))'( *code='(?P<code>[0-9]+)')?.*") |
|
96 |
phase_re = re.compile(".*<info>Making.*?([^\.]+\.[^\.]+)</info>") |
|
97 |
||
98 |
parser = OptionParser(prog = "recipestats", |
|
99 |
usage = """%prog --help [-b] [-f <logfilename>]""") |
|
100 |
||
101 |
parser.add_option("-b","--buildhosts",action="store_true",dest="buildhosts_flag", |
|
102 |
help="Lists which build hosts were active in each invocation of the build engine and how many recipes ran on each.", default = False) |
|
103 |
parser.add_option("-f","--logfile",action="store",dest="logfilename", help="Read from the file, not stdin", default = None) |
|
104 |
||
105 |
||
106 |
(options, stuff) = parser.parse_args(sys.argv[1:]) |
|
107 |
||
108 |
if options.logfilename is None: |
|
109 |
f = sys.stdin |
|
110 |
else: |
|
111 |
f = open(options.logfilename,"r") |
|
112 |
||
113 |
st = BuildStats() |
|
114 |
||
115 |
||
116 |
alternating = 0 |
|
117 |
start_time = 0.0 |
|
118 |
||
119 |
phase=None |
|
120 |
for l in f: |
|
121 |
l2 = l.rstrip("\n\r") |
|
122 |
||
123 |
rm = recipe_re.match(l2) |
|
124 |
||
125 |
if rm is not None: |
|
126 |
(rname,host) = rm.groups() |
|
127 |
continue |
|
128 |
||
129 |
pm = phase_re.match(l2) |
|
130 |
||
131 |
if pm is not None: |
|
132 |
if phase is not None: |
|
133 |
if options.buildhosts_flag: |
|
134 |
print('"%s"\n' % phase) |
|
135 |
print(st.hosts_csv()) |
|
136 |
st.hosts = {} |
|
137 |
phase = pm.groups()[0] |
|
138 |
continue |
|
139 |
||
140 |
tm = time_re.match(l2) |
|
141 |
if tm is not None: |
|
142 |
try: |
|
143 |
s = float(tm.groups()[0]) |
|
144 |
elapsed = float(tm.groups()[1]) |
|
145 |
||
146 |
if start_time == 0.0: |
|
147 |
start_time = s |
|
148 |
||
149 |
s -= start_time |
|
150 |
||
151 |
continue |
|
152 |
except ValueError, e: |
|
153 |
raise Exception("Parse problem: float conversion on these groups: %s\n%s" %(str(tm.groups()), str(e))) |
|
154 |
else: |
|
155 |
if l2.find("<time") is not -1: |
|
156 |
raise Exception("unparsed timing status: %s\n"%l2) |
|
157 |
||
158 |
sm = status_re.match(l2) |
|
159 |
||
160 |
if sm is None: |
|
161 |
continue |
|
162 |
||
163 |
if sm.groupdict()['exit'] == 'ok': |
|
164 |
status = 0 |
|
165 |
else: |
|
166 |
status = int(sm.groupdict()['code']) |
|
167 |
||
168 |
st.add(s, elapsed, rname, status, host, phase) |
|
169 |
||
170 |
if options.buildhosts_flag: |
|
171 |
print('"%s"\n' % phase) |
|
172 |
print(st.hosts_csv()) |
|
173 |
else: |
|
174 |
print(st.recipe_csv()) |
|
175 |
||
176 |
||
177 |
if __name__ == '__main__': main() |