/[soft]/build_system/web/index.php
ViewVC logotype

Annotation of /build_system/web/index.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 951 - (hide annotations) (download)
Tue Apr 19 13:13:33 2011 UTC (12 years, 11 months ago) by rda
File size: 13246 byte(s)
show usage time diagram (sort of)
1 pterjan 268 <?php
2 rda 298 /**
3     * Mageia build-system quick status report script.
4     *
5 blino 615 * @copyright Copyright (C) 2011 Mageia.Org
6 rda 298 *
7 blino 615 * @author Olivier Blin
8 rda 298 * @author Pascal Terjan
9     * @author Romain d'Alverny
10     *
11     * @license http://www.gnu.org/licenses/gpl-2.0.html GNU GPL v2
12     *
13     * This program is free software; you can redistribute it and/or modify it
14     * under the terms of the GNU General Public License aspublished by the
15     * Free Software Foundation; either version 2 of the License, or (at your
16     * option) any later version.
17     *
18     *
19     * Shows submitted packages in the past $max_modified 24 hours and their
20     * status (built & uploaded, failed build, rejected, etc.).
21     *
22     * This was written anew in Jan. 2011 because existing Mandriva build-system
23     * web report code was not clearly licensed at this very time.
24     */
25 pterjan 268
26     error_reporting(E_ALL);
27    
28 pterjan 333 /**
29     * @param array $pkg
30     *
31     * @return string
32     */
33     function pkg_gettype($pkg) {
34     if (array_key_exists("rejected", $pkg["status"]))
35     return "rejected";
36     if (array_key_exists("youri", $pkg["status"])) {
37     if (array_key_exists("src", $pkg["status"]))
38     return "youri";
39     else
40     return "uploaded";
41     }
42     if (array_key_exists("failure", $pkg["status"]))
43     return "failure";
44     if (array_key_exists("done", $pkg["status"]))
45     return "partial";
46     if (array_key_exists("build", $pkg["status"]))
47     return "building";
48     if (array_key_exists("todo", $pkg["status"]))
49     return "todo";
50     return "unknown";
51     }
52    
53     /**
54     * @param integer $num
55     *
56     * @return string
57     */
58     function plural($num) {
59     if ($num > 1)
60     return "s";
61     }
62    
63     /**
64     * Return timestamp from package key
65     * @param string $key package submission key
66     *
67     * @return integer
68     */
69    
70     function key2timestamp($key) {
71     global $tz;
72    
73     $date = DateTime::createFromFormat("YmdHis", $key+0, $tz);
74     if ($date <= 0)
75     return null;
76    
77     return $date->getTimestamp();
78     }
79    
80     function timediff($start, $end) {
81     /**
82     * Return human-readable time difference
83     *
84     * @param integer $start timestamp
85     * @param integer $end timestamp, defaults to now
86     *
87     * @return string
88     */
89     if (is_null($end)) {
90 rda 929 $end = time();
91 pterjan 333 }
92     $diff = $end - $start;
93     if ($diff<60)
94     return $diff . " second" . plural($diff);
95     $diff = round($diff/60);
96     if ($diff<60)
97     return $diff . " minute" . plural($diff);
98     $diff = round($diff/60);
99     if ($diff<24)
100     return $diff . " hour" . plural($diff);
101     $diff = round($diff/24);
102    
103     return $diff . " day" . plural($diff);
104     }
105    
106 rda 284 $g_user = isset($_GET['user']) ? htmlentities(strip_tags($_GET['user'])) : null;
107    
108 rda 283 $upload_dir = '/home/schedbot/uploads';
109 pterjan 268 $max_modified = 2;
110 rda 283 $title = '<a href="http://mageia.org/">Mageia</a> build system status';
111 rda 284 $robots = 'index,nofollow,nosnippet,noarchive';
112     if ($g_user) {
113     $title .= ' for ' . $g_user . "'s packages";
114     $robots = 'no' . $robots;
115     }
116 rda 283 $tz = new DateTimeZone('UTC');
117 rda 292 $date_gen = date('c');
118 pterjan 268
119 pterjan 269 # Temporary until initial mirror is ready
120 pterjan 270 chdir("data");
121 pterjan 472 $missing_deps = file("missing-deps.i586.txt");
122 pterjan 269 #########################################
123    
124 pterjan 268 chdir($upload_dir);
125    
126 pterjan 317 $all_files = shell_exec("find \( -name '*.rpm' -o -name '*.src.rpm.info' -o -name '*.youri' -o -name '*.lock' -o -name '*.done' \) -ctime -$max_modified -printf \"%p\t%T@\\n\"");
127 pterjan 614 $re = "!^\./(\w+)/((\w+)/(\w+)/(\w+)/(\d+)\.(\w+)\.(\w+)\.(\d+))_?(.*)(\.src\.rpm(?:\.info)?|\.youri|\.lock|\.done)\s+(\d+\.\d+)$!m";
128 rda 301 $r = preg_match_all($re,
129     $all_files,
130     $matches,
131     PREG_SET_ORDER);
132 pterjan 268
133     $pkgs = array();
134 rda 945
135 rda 950 $buildtime_total = array();
136 rda 951 $buid_dates = array();
137 rda 945
138 pterjan 268 foreach ($matches as $val) {
139 rda 283
140     if ($_GET['user'] && ($_GET['user'] != $val[7])) {
141     continue;
142 pterjan 269 }
143     $key = $val[6] . $val[7];
144 pterjan 268 if (!is_array($pkgs[$key])) {
145 rda 283
146     $pkgs[$key] = array(
147     'status' => array(),
148     'path' => $val[2],
149     'version' => $val[3],
150     'media' => $val[4],
151     'section' => $val[5],
152     'user' => $val[7],
153     'host' => $val[8],
154     'job' => $val[9]
155     );
156 pterjan 268 }
157     $status = $val[1];
158     $data = $val[10];
159 pterjan 374 if (preg_match("/@(\d+):/", $data, $revision)) {
160     $pkgs[$key]['revision'] = $revision[1];
161     }
162 rda 283 $pkgs[$key]['status'][$status] = 1;
163 pterjan 268 $ext = $val[11];
164 rda 283 if ($ext == '.src.rpm.info') {
165 pterjan 268 preg_match("!^(?:@\d+:)?(.*)!", $data, $name);
166 rda 283 $pkgs[$key]['package'] = $name[1];
167     } else if ($ext == '.src') {
168     $pkgs[$key]['status']['src'] = 1;
169     } else if ($ext == '.youri') {
170     $pkgs[$key]['status']['youri'] = 1;
171     } else if ($ext == '.lock') {
172 pterjan 268 // parse build bot from $data
173 rda 283 $pkgs[$key]['status']['build'] = 1;
174 rda 301 } else if ($ext == '.done') {
175 rda 951 // beware! this block is called twice for a given $key
176    
177 pterjan 313 $pkgs[$key]['buildtime']['start'] = key2timestamp($val[6]);
178 rda 301 $pkgs[$key]['buildtime']['end'] = round($val[12]);
179     $pkgs[$key]['buildtime']['diff'] = $pkgs[$key]['buildtime']['end'] - $pkgs[$key]['buildtime']['start'];
180 rda 948
181 rda 951 @$build_dates[date('H', $pkgs[$key]['buildtime']['start'])] += 1;
182    
183 rda 948 // keep obviously dubious values out of there
184     // 12 hours is be an acceptable threshold given current BS global perfs
185     // as of April 2011
186     if ($pkgs[$key]['buildtime']['diff'] < 43200) {
187 rda 950 $buildtime_total[$key] = $pkgs[$key]['buildtime']['diff'];
188 rda 948 }
189 pterjan 268 }
190     }
191     // sort by key in reverse order to have more recent pkgs first
192     krsort($pkgs);
193 rda 951 ksort($build_dates);
194 rda 283
195 rda 950 $build_count = count($buildtime_total);
196     $buildtime_total = array_sum($buildtime_total);
197    
198 pterjan 333 // count all packages statuses
199     $stats = array(
200     'uploaded' => 0,
201     'failure' => 0,
202     'todo' => 0,
203     'building' => 0,
204     'partial' => 0,
205     'built' => 0,
206     );
207     $total = count($pkgs);
208 rda 283
209 pterjan 333 // count users' packages
210     $users = array();
211 rda 283
212 pterjan 333 if ($total > 0) {
213     foreach ($pkgs as $key => $p) {
214     $pkgs[$key]['type'] = pkg_gettype($p);
215 pterjan 313
216 pterjan 333 $stats[$pkgs[$key]['type']] += 1;
217 pterjan 313
218 pterjan 333 if (!array_key_exists($p['user'], $users))
219     $users[$p['user']] = 1;
220     else
221     $users[$p['user']] += 1;
222     }
223 pterjan 313 }
224    
225 pterjan 333 foreach ($stats as $k => $v) {
226     Header("X-BS-Queue-$k: $v");
227 rda 283 }
228 rda 301
229 pterjan 333 $w = $stats['todo'] - 10;
230     if($w < 0)
231     $w = 0;
232     $w = $w * 60;
233     Header("X-BS-Throttle: $w");
234 rda 945
235 rda 946 $buildtime_total = $buildtime_total / 60;
236     header(sprintf('X-BS-Buildtime: %d', round($buildtime_total)));
237 rda 945 $buildtime_avg = round($buildtime_total / $build_count, 2);
238     header(sprintf('X-BS-Buildtime-Average: %5.2f', $buildtime_avg));
239 pterjan 268 ?>
240 rda 284 <!DOCTYPE html>
241 rda 281 <html lang="en">
242 pterjan 268 <head>
243 rda 284 <meta charset="utf-8">
244 rda 290 <title><?php echo strip_tags($title); ?></title>
245 rda 284 <meta name="robots" content="<?php echo $robots; ?>">
246 dmorgan 645 <link rel="icon" type="image/png" href="favicon.png" />
247 rda 284 <style type="text/css">
248 rda 288 .clear { clear: both; }
249 rda 281 table {
250     border-spacing: 0;
251 rda 293 font-family: Helvetica, Verdana, Arial, sans-serif; font-size: 80%;
252 rda 281 border: 1px solid #ccc;
253 rda 288 float: left;
254 rda 281 }
255     table tr { padding: 0; margin: 0; }
256     table th { padding: 0.2em 0.5em; margin: 0; border-bottom: 2px solid #ccc; border-right: 1px solid #ccc; }
257     table td { padding: 0; margin: 0; padding: 0.2em 0.5em; border-bottom: 1px solid #ccc; }
258 pterjan 269
259 rda 281 tr { background: transparent; }
260 rda 282 tr.uploaded { background: #bbffbb; }
261     tr.failure, tr.rejected { background: #ffbbbb; }
262 rda 281 tr.todo { background: white; }
263 rda 282 tr.building { background: #ffff99; }
264     tr.partial { background: #bbbbff; }
265     tr.built { background: #cceeff; }
266     tr.youri { background: #aacc66; }
267 rda 281
268     td.status-box { width: 1em; height: 1em; }
269     tr.uploaded td.status-box { background: green; }
270     tr.failure td.status-box, tr.rejected td.status-box { background: red; }
271     tr.todo td.status-box { background: white; }
272     tr.building td.status-box { background: yellow; }
273     tr.partial td.status-box { background: blue; }
274 rda 282 tr.built td.status-box { background: #00ccff; }
275 rda 281 tr.youri td.status-box { background: olive; }
276 rda 285
277     #stats { float: right; }
278 rda 293 #score { margin-bottom: 2em; font-family: Helvetica, Verdana, Arial, sans-serif; }
279     #score-box { width: 100px; height: 100px; background: #faa; }
280     #score-meter { width: 100px; background: #afa; }
281 rda 284 </style>
282 pterjan 268 </head>
283     <body>
284 rda 281 <h1><?php echo $title ?></h1>
285 pterjan 268
286 rda 281 <?php
287 rda 289 if (!is_null($g_user))
288     echo '<a href="/">&laquo;&nbsp;Back to full list</a>';
289 pterjan 268
290 pterjan 269 # Temporary until initial mirror is ready
291 rda 281 echo sprintf(
292 pterjan 472 '<p><a href="%s">%d broken dependencies</a>. <strong><a href="%s">You can help!</a></strong></p>',
293     'data/missing-deps.i586.txt', count($missing_deps),
294 rda 321 'http://www.mageia.org/wiki/doku.php?id=packaging#starting_package_import'
295 rda 281 );
296    
297 pterjan 269 #########################################
298    
299 rda 929 $buildtime_stats = array();
300    
301 rda 283 $s = '';
302     $tmpl = <<<T
303     <tr class="%s">
304     <td>%s</td>
305     <td><a href="?user=%s">%s</a></td>
306 rda 936 <td><a href="http://svnweb.mageia.org/packages?view=revision&revision=%d" title="%s">%s</a></td>
307 rda 283 <td>%s</td>
308     <td>%s/%s</td>
309     <td class="status-box"></td>
310     T;
311 rda 285
312 rda 292 if ($total > 0) {
313     foreach ($pkgs as $key => $p) {
314     $s .= sprintf($tmpl,
315     $p['type'],
316 pterjan 314 timediff(key2timestamp($key)) . ' ago',
317 rda 292 $p['user'], $p['user'],
318 pterjan 374 $p['revision'],
319 rda 936 addslashes($p['summary']),
320 rda 292 $p['package'],
321     $p['version'],
322     $p['media'], $p['section']
323     );
324 rda 283
325 rda 292 $typelink = '';
326     if ($p['type'] == 'failure') {
327     $typelink = '/uploads/' . $p['type'] . '/' . $p['path'];
328     } elseif ($p['type'] == 'rejected') {
329     $typelink = '/uploads/' . $p['type'] . '/' . $p['path'] . '.youri';
330     }
331    
332     $s .= '<td>';
333     $s .= ($typelink != '') ?
334     sprintf('<a href="%s">%s</a>', $typelink, $p['type']) :
335     $p['type'];
336    
337 rda 301 $s .= '</td><td>';
338 rda 929 if ($p['type'] == 'uploaded') {
339 rda 945 $tdiff = timediff($p['buildtime']['start'], $p['buildtime']['end']); // use $p['buildtime']['diff']; instead?
340 rda 929 $s .= $tdiff;
341     @$buildtime_stats[$tdiff] += 1;
342     }
343 rda 292 $s .= '</td>';
344     $s .= '</tr>';
345 pterjan 268 }
346 rda 292 // Table
347     echo '<table>',
348 rda 316 '<caption>', $total, ' packages submitted in the past ', $max_modified * 24, '&nbsp;hours.</caption>',
349     '<tr><th>Submitted</th><th>User</th>
350     <th>Package</th><th>Target</th><th>Media</th>
351     <th colspan="2">Status</th><th>Build time</th></tr>',
352 rda 292 $s,
353     '</table>';
354 rda 283
355 rda 292 // Stats
356     $s = '<div id="stats">';
357     $score = round($stats['uploaded']/$total * 100);
358     $s .= sprintf('<div id="score"><h3>Score: %d/100</h3>
359     <div id="score-box"><div id="score-meter" style="height: %dpx;"></div></div></div>',
360     $score, $score);
361 rda 283
362 rda 932 $s .= '<table style="width: 100%"><caption>Stats.</caption><tr><th colspan="2">Status</th><th>Count</th><th>%</th></tr>';
363 rda 292 foreach ($stats as $k => $v) {
364     $s .= sprintf('<tr class="%s"><td class="status-box"></td><td>%s</td><td>%d</td><td>%d%%</td></tr>',
365     $k, $k, $v, round($v/$total*100));
366     }
367 rda 299
368 rda 316 $s .= '</table><br /><br />';
369 rda 299
370 rda 932 $s .= '<table style="width: 100%"><caption>Packagers</caption><tr><th>User</th><th>Packages</th></tr>';
371 rda 940 arsort($users);
372 rda 299 foreach ($users as $k => $v)
373     $s .= sprintf('<tr><td><a href="/?user=%s">%s</a></td><td>%d</td></tr>',
374     $k, $k, $v);
375    
376 rda 929 $s .= '</table><br /><br />';
377    
378 rda 930 /**
379     */
380     function timesort($a, $b)
381     {
382     $a = explode(' ', trim($a));
383     $b = explode(' ', trim($b));
384    
385     if ($a[1] == 'hour' || $a[1] == 'hours')
386     $a[0] *= 3600;
387    
388     if ($b[1] == 'hour' || $a[1] == 'hours')
389     $b[0] *= 3600;
390    
391     if ($a[0] > $b[0])
392     return 1;
393     elseif ($a[0] < $b[0])
394     return -1;
395    
396     return 0;
397     }
398     uksort($buildtime_stats, "timesort");
399    
400 rda 933 $bts = '';
401 rda 929 foreach ($buildtime_stats as $time => $count) {
402 rda 933 $bts .= sprintf('<tr><td>%s</td><td>%d</td></tr>',
403 rda 929 $time, $count);
404 rda 933
405     $tmp = explode(' ', $time);
406 rda 929 }
407 rda 933
408 rda 941 $s .= '<table style="width: 100%;"><caption>Build time</caption>';
409 rda 935
410 rda 949 $s .= sprintf('<tr><td>Total time</td><td>%s hours</td></tr>
411     <tr><td>Average</td><td>%s minutes</td></tr>
412 rda 937 <tr><td>Builds count</td><td>%s</td></tr>',
413 rda 949 round($buildtime_total / 60, 2),
414 rda 937 $buildtime_avg,
415     $buildtime_cnt);
416 rda 935
417 rda 941 $s .= '<tr><th title="Build time">Duration</th><th title="Packages number">Pack. nb.</th></tr>';
418 rda 933 $s .= $bts;
419 rda 938 $s .= '</table><span style="font-size: 85%;">Does not take<br />build failures<br />into account.</span>';
420 rda 929
421 rda 951 $s .= '<table style="width:100%;"><caption>Build times</caption>';
422     $max = max($build_dates2);
423     foreach ($build_dates2 as $time => $count)
424     $s .= sprintf('<tr><td>%d</td><td><span style="width: %dpx; height: 10px; background: #aaa;" title="%d"></span></td></tr>',
425     $time, round($count / $max * 100), $count);
426     $s .= '</table>';
427    
428 rda 299 $s .= '</div>';
429    
430 rda 292 echo $s;
431 pterjan 268 }
432 rda 292 else
433     {
434     echo sprintf('<p>No package has been submitted in the past %d&nbsp;hours.</p>',
435     $max_modified * 24);
436 rda 285 }
437    
438 pterjan 268 ?>
439 rda 292 <div class="clear"></div>
440     <hr />
441     <p>Generated at <?php echo $date_gen; ?>.</p>
442 pterjan 268 </body>
443     </html>

  ViewVC Help
Powered by ViewVC 1.1.30