Exemple #1
0
<?php

$errdatay = array(11, 9, 2, 4, 19, 26, 13, 19, 7, 12);
// Create the graph. These two calls are always required
$graph = new Graph(300, 200);
$graph->SetScale("textlin");
$graph->img->SetMargin(40, 30, 20, 40);
$graph->SetShadow();
// Create the error plot
$errplot = new ErrorPlot($errdatay);
$errplot->SetColor("red");
$errplot->SetWeight(2);
// Add the plot to the graph
$graph->Add($errplot);
$graph->title->Set("Simple error plot");
$graph->xaxis->title->Set("X-title");
$graph->yaxis->title->Set("Y-title");
$graph->title->SetFont(FF_FONT1, FS_BOLD);
$graph->yaxis->title->SetFont(FF_FONT1, FS_BOLD);
$graph->xaxis->title->SetFont(FF_FONT1, FS_BOLD);
//$datax = $gDateLocale->GetShortMonth();
//$graph->xaxis->SetTickLabels($datax);
// Display the graph
$filename = ROOT . DS . "public" . DS . "tmp" . DS . "emp.png";
if (file_exists($filename)) {
    unlink($filename);
}
$graph->Stroke($filename);
 function Stroke(&$img, &$xscale, &$yscale)
 {
     parent::Stroke($img, $xscale, $yscale);
     $this->line->Stroke($img, $xscale, $yscale);
 }
Exemple #3
0
function metric_as_graph($result, $xaxis, $metric, $system, $start_date, $end_date)
{
    set_time_limit(900);
    $myresult = $result;
    $nrows = 0;
    $xmax = 0;
    while ($myresult->fetchInto($row)) {
        $keys = array_keys($row);
        foreach ($keys as $key) {
            $rawdata[$nrows][$key] = $row[$key];
        }
        $nrows++;
    }
    if ($xaxis == 'nproc') {
        for ($i = 0; $i <= nprocs($system); $i++) {
            $x[$i] = "";
            $y[$i] = "";
            $min[$i] = "";
            $max[$i] = "";
            $stddev[$i] = "";
            $max[$i] = "";
            $ysigma[2 * $i] = "";
            $ysigma[2 * $i + 1] = "";
        }
    }
    if ($metric == 'jobcount') {
        for ($i = 0; $i < $nrows; $i++) {
            $x[$i] = $rawdata[$i][0];
            if ($xaxis == 'nproc') {
                if ($x[$i] > $xmax) {
                    $xmax = $x[$i];
                }
                $y[$x[$i]] = $rawdata[$i][1];
            } else {
                $y[$i] = $rawdata[$i][1];
            }
        }
    } elseif ($metric == 'cpuhours' || $metric == 'xfactor' || $metric == 'users' || $metric == 'groups') {
        for ($i = 0; $i < $nrows; $i++) {
            $x[$i] = $rawdata[$i][0];
            if ($xaxis == 'nproc') {
                if ($x[$i] > $xmax) {
                    $xmax = $x[$i];
                }
                $y[$x[$i]] = $rawdata[$i][2];
            } else {
                $y[$i] = $rawdata[$i][2];
            }
        }
    } elseif ($metric == 'backlog') {
        for ($i = 0; $i < $nrows; $i++) {
            $x[$i] = $rawdata[$i][0];
            if ($xaxis == 'nproc') {
                if ($x[$i] > $xmax) {
                    $xmax = $x[$i];
                }
                $y[$x[$i]] = time_to_hrs($rawdata[$i][3]);
                $max[$x[$i]] = time_to_hrs($rawdata[$i][2]);
            } else {
                $y[$i] = time_to_hrs($rawdata[$i][3]);
                $max[$i] = time_to_hrs($rawdata[$i][2]);
            }
        }
    } else {
        for ($i = 0; $i < $nrows; $i++) {
            $x[$i] = $rawdata[$i][0];
            if ($xaxis == 'nproc') {
                if ($x[$i] > $xmax) {
                    $xmax = $x[$i];
                }
                $y[$x[$i]] = $rawdata[$i][4];
                if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $y[$x[$i]])) {
                    $y[$x[$i]] = time_to_hrs($y[$x[$i]]);
                }
                $min[$x[$i]] = $rawdata[$i][2];
                if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $min[$x[$i]])) {
                    $min[$x[$i]] = time_to_hrs($min[$x[$i]]);
                }
                $max[$x[$i]] = $rawdata[$i][3];
                if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $max[$x[$i]])) {
                    $max[$x[$i]] = time_to_hrs($max[$x[$i]]);
                }
                $stddev[$x[$i]] = $rawdata[$i][5];
                if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $stddev[$x[$i]])) {
                    $stddev[$x[$i]] = time_to_hrs($stddev[$x[$i]]);
                }
                $ysigma[2 * $x[$i]] = $y[$x[$i]] - $stddev[$x[$i]];
                if ($ysigma[2 * $x[$i]] < 0.0) {
                    $ysigma[2 * $x[$i]] = 0.0;
                }
                $ysigma[2 * $x[$i] + 1] = $y[$x[$i]] + $stddev[$x[$i]];
            } else {
                $y[$i] = $rawdata[$i][4];
                if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $y[$i])) {
                    $y[$i] = time_to_hrs($y[$i]);
                }
                $min[$i] = $rawdata[$i][2];
                if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $min[$i])) {
                    $min[$i] = time_to_hrs($min[$i]);
                }
                $max[$i] = $rawdata[$i][3];
                if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $max[$i])) {
                    $max[$i] = time_to_hrs($max[$i]);
                }
                $stddev[$i] = $rawdata[$i][5];
                if (preg_match('/^[0-9]+:[0-5][0-9]:[0-5][0-9]$/', $stddev[$i])) {
                    $stddev[$i] = time_to_hrs($stddev[$i]);
                }
                $ysigma[2 * $i] = $y[$i] - $stddev[$i];
                if ($ysigma[2 * $i] < 0.0) {
                    $ysigma[2 * $i] = 0.0;
                }
                $ysigma[2 * $i + 1] = $y[$i] + $stddev[$i];
            }
        }
    }
    $cache = APACHE_CACHE_DIR;
    if (!file_exists("/tmp/" . $cache)) {
        mkdir("/tmp/" . $cache, 0750);
    }
    $plot = $system . "-" . $metric . "_vs_" . $xaxis . "-" . $start_date . "-" . $end_date . ".png";
    //  $graph = new graph(640,480,$plot,2,0);
    $graph = new graph(800, 600, $plot, 2, 0);
    $graph->img->SetMargin(75, 30, 30, 75);
    if ($xaxis == 'nproc') {
        $graph->SetScale("linlin");
        //$graph->xaxis->SetAutoMax(nprocs($system));
    } else {
        $graph->SetScale("textlin");
        $graph->xaxis->SetLabelAngle(90);
        $graph->xaxis->SetTickLabels($x);
    }
    $graph->xaxis->title->Set($xaxis);
    $graph->yaxis->title->Set($metric . units($metric));
    if ($metric == "walltime_acc" || $metric == "cpu_eff") {
        $graph->yscale->SetAutoMax(1.1);
    } elseif ($metric == "xfactor") {
        $graph->yscale->SetAutoMin(1.0);
    }
    if ($metric != "jobcount" && $metric != "cpuhours" && $metric != "backlog" && $metric != "xfactor" && $metric != "users" && $metric != "groups") {
        $maxbar = new BarPlot($max);
        $maxbar->SetWidth(1.0);
        $maxbar->SetFillColor("gray");
        $maxbar->SetLegend("Maximum");
        $graph->Add($maxbar);
    } else {
        if ($metric == "backlog") {
            $maxbar = new BarPlot($max);
            $maxbar->SetWidth(1.0);
            $maxbar->SetFillColor("gray");
            $maxbar->SetLegend("CPU Hours");
            $graph->Add($maxbar);
        }
    }
    $ybar = new BarPlot($y);
    $ybar->SetWidth(1.0);
    if ($metric != "jobcount" && $metric != "cpuhours" && $metric != "backlog" && $metric != "xfactor" && $metric != "users" && $metric != "groups") {
        $ybar->SetLegend("Mean");
    } else {
        if ($metric == "backlog") {
            $ybar->SetLegend("Queue Hours");
        }
    }
    $graph->Add($ybar);
    if ($metric != "jobcount" && $metric != "cpuhours" && $metric != "backlog" && $metric != "xfactor" && $metric != "users" && $metric != "groups") {
        $minbar = new BarPlot($min);
        $minbar->SetWidth(1.0);
        $minbar->SetFillColor("white");
        $minbar->SetLegend("Minimum");
        $graph->Add($minbar);
        $errbars = new ErrorPlot($ysigma);
        $errbars->SetColor("red");
        //$errbars->SetCenter();
        $errbars->SetWeight(2);
        $errbars->SetLegend("Std.Dev.");
        $graph->Add($errbars);
    }
    $graph->Stroke();
    $imgurl = $cache . rawurlencode($plot);
    echo "<img src=\"" . $imgurl . "\">\n";
}