Ejemplo n.º 1
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";
}
Ejemplo n.º 2
0
 function GerarGraficoBarra()
 {
     require_once "../biblioteca/jpgraph/jpgraph.php";
     require_once "../biblioteca/jpgraph/jpgraph_bar.php";
     $grafico = new graph($this->largura, $this->altura, "png");
     /* Margem das partes principais do gráfico (dados), o que está
      * fora da margem fica separado para as labels, títulos, etc
      * Este valor ficará como padrão para todos os gráficos
      */
     $grafico->img->SetMargin(40, 30, 20, 40);
     $grafico->SetScale("textlin");
     $grafico->SetShadow();
     //Define Titulo e Subtitulo
     $grafico->title->Set($this->titulo);
     $grafico->subtitle->Set($this->subtitulo);
     // pedir para mostrar os grides no fundo do gráfico,
     // o ygrid é marcado como true por padrão
     $grafico->ygrid->Show(true);
     $grafico->xgrid->Show(true);
     $gBarras = new BarPlot($this->dados_eixoY);
     $gBarras->SetFillColor($this->cor_barra);
     $gBarras->SetShadow($this->cor_sombra);
     $gBarras->SetAbsWidth($this->largura_barra);
     $gBarras->value->Show();
     $gBarras->value->SetFormat('%d');
     $gBarras->SetValuePos('center');
     $gBarras->value->SetFont(FF_FONT1, FS_BOLD);
     // título dos vértices
     $grafico->yaxis->title->Set($this->label_eixoY);
     $grafico->xaxis->title->Set($this->label_eixoX);
     // título das barras
     $grafico->xaxis->SetTickLabels($this->dados_eixoX);
     $grafico->Add($gBarras);
     $grafico->Stroke("imagens/graficos/" . $this->nome);
 }