-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathcfbot_web_statistics.py
executable file
·306 lines (287 loc) · 8.7 KB
/
cfbot_web_statistics.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
#!/usr/bin/env python3
import cfbot_config
import cfbot_util
import os
def header(f):
f.write("""<html>
<head>
<meta charset="UTF-8"/>
<title>PostgreSQL Patch Tester</title>
<style type="text/css">
body {
margin: 1rem auto;
font-family: -apple-system,BlinkMacSystemFont,avenir next,avenir,helvetica neue,helvetica,ubuntu,roboto,noto,segoe ui,arial,sans-serif;
color: #444;
max-width: 920px;
}
h1 {
font-size: 3rem;
}
h2 {
font-size: 2rem;
}
table {
border-collapse: collapse;
font-size: 0.875rem;
width: 100%%;
}
td {
padding: 1rem 1rem 1rem 0;
border-bottom: solid 1px rgba(0,0,0,.2);
}
</style>
</head>
<body>
<h1>PostgreSQL Patch Tester</h1>
<p>
<a href="index.html">Current commitfest</a> |
<a href="next.html">Next commitfest</a> |
<a href="https://wiki.postgresql.org/wiki/Cfbot">FAQ</a> |
<b>Statistics</b> |
<a href="highlights/all.html">Highlights</a>
</p>
""")
def per_day(f, conn):
f.write("""
<h2>Per day</h2>
<p>
Resources consumed per UTC day over the past month, according to Cirrus's reported "duration" value.
Also average and stddev, but these only count successful runs because otherwise fast failures would make the data hard to interpret.
</p>
<table>
<tr>
<td width="20%">Task</td>
<td width="10%">Date</td>
<td width="20%" align="center">Total time</td>
<td width="20%" align="center">Avg (success)</td>
<td width="20%" align="center">Stddev (success)</td>
<td width="10%" align="center">Count</td>
</tr>
""")
cursor = conn.cursor()
cursor.execute("""
with subtotals as (
select t.created::date date,
t.task_name,
t.task_id,
t.status,
sum(c.duration) duration
from task t join task_command c using (task_id)
where t.created between date_trunc('day', now() - interval '30 days') and
date_trunc('day', now())
and t.status not in ('CREATED', 'ABORTED')
group by 1, 2, 3)
select task_name, date,
sum(duration),
avg(duration) filter (where status = 'COMPLETED') avg_success,
stddev(extract(epoch from duration)) filter (where status = 'COMPLETED') stddev_success,
count(*)
from subtotals
group by date, task_name
order by task_name collate "en_US", date
""")
last_task = None
for task, date, s, avg, stddev, count in cursor.fetchall():
if task == last_task:
task = ""
else:
last_task = task
if stddev is None:
stddev = 0
f.write(
"""
<tr>
<td>%s</td>
<td>%s</td>
<td align="right">%s</td>
<td align="right">%s</td>
<td align="right">%.2f</td>
<td align="right">%d</td>
</tr>
"""
% (task, date, s, avg, stddev, count)
)
f.write("""
</table>
""")
def per_task(f, conn):
f.write("""
<h2>Per task</h2>
<p>
Time taken, in seconds, for successfully completed task steps. Showing
only configure, build and test. All numbers are shown as 7-day, 30-day
and 90-day windows. Perhaps we can see (very crudely) if it's speeding
up or slowing down.
</p>
<table>
<tr>
<td width="20%">Task</td>
<td width="20%">Step</td>
<td width="20%" align="center">Avg.</td>
<td width="20%" align="center">Std. dev.</td>
<td width="20%" align="center">Count</td>
</tr>
""")
cursor = conn.cursor()
cursor.execute("""
select t.task_name,
c.name,
count(*) filter (where created > now() - interval '7 days') as count_7,
avg(extract(epoch from duration)) filter (where created > now() - interval '7 days') as avg_7,
stddev(extract(epoch from duration)) filter (where created > now() - interval '7 days') as stddev_7,
count(*) filter (where created > now() - interval '30 days') as count_30,
avg(extract(epoch from duration)) filter (where created > now() - interval '30 days') as avg_30,
stddev(extract(epoch from duration)) filter (where created > now() - interval '30 days') as stddev_30,
count(*) filter (where created > now() - interval '90 days') as count_90,
avg(extract(epoch from duration)) filter (where created > now() - interval '90 days') as avg_90,
stddev(extract(epoch from duration)) filter (where created > now() - interval '90 days') as stddev_90
from task t
join task_command c using (task_id)
where c.name in ('configure', 'configure_32', 'build', 'build_32', 'test_world', 'test_world_32', 'check_world')
and t.status = 'COMPLETED'
group by 1, 2
order by 1, 2
""")
last_task = ""
for task, command, c7, a7, d7, c30, a30, d30, c90, a90, d90 in cursor.fetchall():
if task == last_task:
task = ""
else:
last_task = task
if not a7:
a7 = 0
if not d7:
d7 = 0
if not a30:
a30 = 0
if not d30:
d30 = 0
if not a90:
a90 = 0
if not d90:
d90 = 0
f.write(
"""
<tr>
<td>%s</td>
<td>%s</td>
<td align="right">%.2f, %.2f, %.2f</td>
<td align="right">%.2f, %.2f, %.2f</td>
<td align="right">%d, %d, %d</td>
</tr>
"""
% (task, command, a7, a30, a90, d7, d30, d90, c7, c30, c90)
)
f.write("""
</table>
""")
def per_test(f, conn):
cursor = conn.cursor()
f.write("""
<h2>Per test</h2>
<p>
Time taken for individual tests (Meson builds only, successful tasks
only). Again, numbers are 7-day, 30-day, 90-day.
</p>
<table>
<tr>
<td width="20%">Task</td>
<td width="10%">Suite</td>
<td width="10%">Test</td>
<td width="20%" align="center">Avg.</td>
<td width="20%" align="center">Std. dev.</td>
<td width="20%" align="center">Count</td>
</tr>
""")
cursor.execute("""
select task.task_name,
test.command,
test.suite,
test.name,
count(*) filter (where created > now() - interval '7 days') as count_7,
avg(extract(epoch from duration)) filter (where created > now() - interval '7 days') as avg_7,
stddev(extract(epoch from duration)) filter (where created > now() - interval '7 days') as stddev_7,
count(*) filter (where created > now() - interval '30 days') as count_30,
avg(extract(epoch from duration)) filter (where created > now() - interval '30 days') as avg_30,
stddev(extract(epoch from duration)) filter (where created > now() - interval '30 days') as stddev_30,
count(*) filter (where created > now() - interval '90 days') as count_90,
avg(extract(epoch from duration)) filter (where created > now() - interval '90 days') as avg_90,
stddev(extract(epoch from duration)) filter (where created > now() - interval '90 days') as stddev_90
from task
join test using (task_id)
where task.status = 'COMPLETED'
and test.result = 'OK'
group by 1, 2, 3, 4
order by 1, 2, 3, 4
""")
last_task = ""
last_suite = ""
for (
task,
command,
suite,
test,
c7,
a7,
d7,
c30,
a30,
d30,
c90,
a90,
d90,
) in cursor.fetchall():
if command.endswith("32"):
task += "/32" # rather than wasting a whole column on "command"
if task == last_task:
task = ""
else:
last_task = task
if suite == last_suite:
suite = ""
else:
last_suite = suite
if not a7:
a7 = 0
if not d7:
d7 = 0
if not a30:
a30 = 0
if not d30:
d30 = 0
if not a90:
a90 = 0
if not d90:
d90 = 0
f.write(
"""
<tr>
<td>%s</td>
<td>%s</td>
<td>%s</td>
<td align="right">%.2f, %.2f, %.2f</td>
<td align="right">%.2f, %.2f, %.2f</td>
<td align="right">%d, %d, %d</td>
</tr>
"""
% (task, suite, test, a7, a30, a90, d7, d30, d90, c7, c30, c90)
)
f.write("""
</table>
""")
def footer(f):
f.write("""
</body>
</html>
""")
def build_page(conn, path):
with open(path + ".tmp", "w") as f:
header(f)
per_day(f, conn)
per_task(f, conn)
per_test(f, conn)
footer(f)
os.rename(path + ".tmp", path)
if __name__ == "__main__":
with cfbot_util.db() as conn:
build_page(conn, os.path.join(cfbot_config.WEB_ROOT, "statistics.html"))