index : website | |
Archlinux32 website - obsolete | gitolite user |
summaryrefslogtreecommitdiff |
author | Erich Eckner <git@eckner.net> | 2019-07-16 10:28:45 +0200 |
---|---|---|
committer | Erich Eckner <git@eckner.net> | 2019-07-16 10:28:45 +0200 |
commit | 65eef09eecaa37474424bb9b4ea2b76031c18bbd (patch) | |
tree | 62364da3a522e220c2d5ef860e445dc0ba9163dd | |
parent | 7fecce071cea4c660e30b1e1c845c3459ee082ce (diff) |
-rw-r--r-- | buildmaster/execution-times.php | 168 |
diff --git a/buildmaster/execution-times.php b/buildmaster/execution-times.php new file mode 100644 index 0000000..3ef4f2a --- /dev/null +++ b/buildmaster/execution-times.php @@ -0,0 +1,168 @@ +<?php + +require_once '../init.php'; +require_once BASE . '/lib/mysql.php'; + +$result = mysql_run_query( + 'SELECT' . + ' UNIX_TIMESTAMP(`ssh_log`.`date`) AS `date`,' . + '`ssh_log`.`duration`,' . + '`ssh_log`.`action`,' . + '`ssh_log`.`parameters`' . + ' FROM `ssh_log`' . + ' WHERE `ssh_log`.`duration` IS NOT NULL' . + ' AND `ssh_log`.`action` != "ping-from-slave"' . + ' AND `ssh_log`.`exit_code` = 0' . + ' ORDER BY `ssh_log`.`date`' +); + +$infos = array(); +while ($row = $result -> fetch_assoc()) { + $info = array( + 'date' => $row['date'], + 'duration' => $row['duration'], + 'action' => $row['action'] + ); + if ($row['action'] == 'return-assignment') { + if (substr($row['parameters'], -6) == ' ERROR') + $info['action'] .= ' ERROR'; + elseif (substr($row['parameters'], -6) == ' ABORT') + $info['action'] .= ' ABORT'; + else + $info['action'] .= ' SUCCESS'; + } + $infos[] = $info; +} + +foreach ($infos as $info) + $actions[$info['action']][] = array( + 'date' => $info['date'], + 'duration' => $info['duration'] + ); + +foreach ($actions as $action) + foreach ($action as $event) { + if (isset($min_date)) { + $min_date = min($min_date, $event['date']); + $max_date = max($max_date, $event['date']); + $max_duration = max($max_duration, $event['duration']); + } else { + $min_date = $event['date']; + $max_date = $event['date']; + $max_duration = $event['duration']; + } + } + +$width = 1600; +$height = 600; +$border = 5; +$legend_line_length = 10; +$legend_height = 2*ImageFontHeight(5) + $legend_line_length; +$left_legend_length = strlen($max_duration) * ImageFontWidth(5); + +$im = @ImageCreate ($width + $legend_line_length + $left_legend_length, $height + $legend_height) + or die ('Cannot create new gd-image-stream'); + +$background_color = ImageColorAllocate ($im, 255, 255, 255); +$foreground_color = ImageColorAllocate ($im, 0, 0, 0); +$colors['return-assignment SUCCESS'] = ImageColorAllocate ($im, 0, 255, 0); +$colors['return-assignment ERROR'] = ImageColorAllocate ($im, 255, 0, 0); +$colors['return-assignment ABORT'] = ImageColorAllocate ($im, 255, 0, 0); +$colors['get-assignment'] = ImageColorAllocate ($im, 0, 0, 255); +$colors['undef'] = ImageColorAllocate ($im, 255, 0, 255); + +function scale($x, $x_min, $x_max, $scale, $log) { + if ($log) { + $x = log($x + 10); + $x_min = log($x_min + 10); + $x_max = log($x_max + 10); + }; + if ($x_max == $x_min) + $frac = 0; + else + $frac = ($x - $x_min)/($x_max - $x_min); + if ($scale < 0) + return ($frac-1) * $scale; + else + return $frac * $scale; +}; + +function print_graph($data, $color) { + global $width, $height, $im, $min_date, $max_date, $min_duration, $max_duration, $border, $legend_line_length, $left_legend_length; + foreach ($data as $val) { + ImageFilledEllipse( + $im, + scale($val['date'], $min_date, $max_date, $width - 2*$border - $left_legend_length, false) + $border + $legend_line_length + $left_legend_length, + scale($val['duration'], 0, $max_duration, -$height + 2*$border, array_key_exists('log', $_GET)) + $border, + max(2,pow($val['duration'],0.4)), + max(2,pow($val['duration'],0.4)), + $color + ); + } +/* ImageString( + $im, + 5, + $width + $legend_line_length, + scale($last_val, 0, $val_max, -$height + 2*$border, array_key_exists('log', $_GET)) + $border - ImageFontHeight(5)/2, + ' ' . $data[$t_max], + $color + ); */ +}; + +ImageRectangle($im, $legend_line_length + $left_legend_length, 0, $width-1 + $legend_line_length, $height-1, $foreground_color); + +$xpos = $legend_line_length + $left_legend_length; +foreach ($actions as $action => $data) { + if (array_key_exists($action, $colors)) + $color = $colors[$action]; + else + $color = $colors['undef']; + print_graph($data, $color); + ImageString($im, 5, $xpos, $height + $legend_line_length + ImageFontHeight(5), $action, $color); + $xpos += (strlen($action) + 1.75) * ImageFontWidth(5); +} + +ImageString($im, 5, $legend_line_length+$left_legend_length, $height + $legend_line_length, date('Y-m-d H:i', $min_date), $foreground_color); +$s = date('Y-m-d H:i', $max_date); +ImageString($im, 5, $width+$legend_line_length - strlen($s)*ImageFontWidth(5), $height + $legend_line_length, $s, $foreground_color); + +for ($t=ceil($min_date/24/60/60); $t<=floor($max_date/24/60/60); $t++) + ImageLine( + $im, + scale($t*24*60*60,$min_date,$max_date,$width-2*$border-$left_legend_length,false)+$border+$legend_line_length+$left_legend_length, + $height, + scale($t*24*60*60,$min_date,$max_date,$width-2*$border-$left_legend_length,false)+$border+$legend_line_length+$left_legend_length, + $height+$legend_line_length, + $foreground_color + ); + +for ($val = 0; $val <= $max_duration;) { + ImageLine( + $im, + $left_legend_length, + scale($val, 0, $max_duration, -$height + 2*$border, array_key_exists('log', $_GET)) + $border, + $legend_line_length+$left_legend_length, + scale($val, 0, $max_duration, -$height + 2*$border, array_key_exists('log', $_GET)) + $border, + $foreground_color + ); + ImageString( + $im, + 5, + $left_legend_length - strlen($val)*ImageFontWidth(5), + scale($val, 0, $max_duration, -$height + 2*$border, array_key_exists('log', $_GET)) + $border - 0.5*ImageFontHeight(5), + $val, + $foreground_color + ); + if (! array_key_exists('log', $_GET)) + $val+=pow(10, round(log($max_duration) / log(10)) - 1); + elseif ($val == 0) + $val++; + else + $val = $val*10; +} + +// ImageString ($im, 1, 5, 5, "Test-String ".rand(), $foreground_color); + +header ('Content-type: image/png'); + +ImagePNG ($im); |