Merge pull request #501 from laf/scrut-performance

Fixed the performance issues in scrut
This commit is contained in:
Neil Lathwood
2015-02-22 18:16:10 +00:00
3 changed files with 24 additions and 12 deletions

View File

@@ -560,7 +560,8 @@ function collectd_draw_rrd($host, $plugin, $pinst = null, $type, $tinst = null,
$rrd_cmd = array_merge($rrd_cmd, $config['rrd_opts_array'], $opts['rrd_opts'], $graph); $rrd_cmd = array_merge($rrd_cmd, $config['rrd_opts_array'], $opts['rrd_opts'], $graph);
$cmd = RRDTOOL; $cmd = RRDTOOL;
for ($i = 1; $i < count($rrd_cmd); $i++) $count_rrd_cmd = count($rrd_cmd);
for ($i = 1; $i < $count_rrd_cmd; $i++)
$cmd .= ' '.escapeshellarg($rrd_cmd[$i]); $cmd .= ' '.escapeshellarg($rrd_cmd[$i]);
return $cmd; return $cmd;
@@ -611,7 +612,8 @@ function collectd_draw_generic($timespan, $host, $plugin, $pinst = null, $type,
$rrdgraph = array_merge($rrd_cmd, $rrd_args); $rrdgraph = array_merge($rrd_cmd, $rrd_args);
$cmd = RRDTOOL; $cmd = RRDTOOL;
for ($i = 1; $i < count($rrdgraph); $i++) $count_rrdgraph = count($rrdgraph);
for ($i = 1; $i < $count_rrdgraph; $i++)
$cmd .= ' '.escapeshellarg($rrdgraph[$i]); $cmd .= ' '.escapeshellarg($rrdgraph[$i]);
return $cmd; return $cmd;
@@ -712,7 +714,8 @@ function collectd_draw_meta_stack(&$opts, &$sources) {
} }
$rrdcmd = RRDTOOL; $rrdcmd = RRDTOOL;
for ($i = 1; $i < count($cmd); $i++) $count_cmd = count($cmd);
for ($i = 1; $i < $count_cmd; $i++)
$rrdcmd .= ' '.escapeshellarg($cmd[$i]); $rrdcmd .= ' '.escapeshellarg($cmd[$i]);
return $rrdcmd; return $rrdcmd;
} }
@@ -793,7 +796,8 @@ function collectd_draw_meta_line(&$opts, &$sources) {
} }
$rrdcmd = RRDTOOL; $rrdcmd = RRDTOOL;
for ($i = 1; $i < count($cmd); $i++) $count_cmd = count($cmd);
for ($i = 1; $i < $count_cmd; $i++)
$rrdcmd .= ' '.escapeshellarg($cmd[$i]); $rrdcmd .= ' '.escapeshellarg($cmd[$i]);
return $rrdcmd; return $rrdcmd;
} }

View File

@@ -489,7 +489,8 @@ class Console_Table
$this->_splitMultilineRows(); $this->_splitMultilineRows();
// Update cell lengths. // Update cell lengths.
for ($i = 0; $i < count($this->_headers); $i++) { $count_headers = count($this->_headers);
for ($i = 0; $i < $count_headers; $i++) {
$this->_calculateCellLengths($this->_headers[$i]); $this->_calculateCellLengths($this->_headers[$i]);
} }
for ($i = 0; $i < $this->_max_rows; $i++) { for ($i = 0; $i < $this->_max_rows; $i++) {
@@ -570,8 +571,10 @@ class Console_Table
$separator = $this->_getSeparator(); $separator = $this->_getSeparator();
$return = array(); $return = array();
for ($i = 0; $i < count($this->_data); $i++) { $count_data = count($this->_data);
for ($j = 0; $j < count($this->_data[$i]); $j++) { for ($i = 0; $i < $count_data; $i++) {
$count_data_i = count($this->_data[$i]);
for ($j = 0; $j < $count_data_i; $j++) {
if ($this->_data[$i] !== CONSOLE_TABLE_HORIZONTAL_RULE && if ($this->_data[$i] !== CONSOLE_TABLE_HORIZONTAL_RULE &&
$this->_strlen($this->_data[$i][$j]) < $this->_strlen($this->_data[$i][$j]) <
$this->_cell_lengths[$j]) { $this->_cell_lengths[$j]) {
@@ -648,7 +651,8 @@ class Console_Table
function _getHeaderLine() function _getHeaderLine()
{ {
// Make sure column count is correct // Make sure column count is correct
for ($j = 0; $j < count($this->_headers); $j++) { $count_headers = count($this->_headers);
for ($j = 0; $j < $count_headers; $j++) {
for ($i = 0; $i < $this->_max_cols; $i++) { for ($i = 0; $i < $this->_max_cols; $i++) {
if (!isset($this->_headers[$j][$i])) { if (!isset($this->_headers[$j][$i])) {
$this->_headers[$j][$i] = ''; $this->_headers[$j][$i] = '';
@@ -656,8 +660,10 @@ class Console_Table
} }
} }
for ($j = 0; $j < count($this->_headers); $j++) { $count_headers = count($this->_headers);
for ($i = 0; $i < count($this->_headers[$j]); $i++) { for ($j = 0; $j < $count_headers; $j++) {
$count_headers_j = count($this->_headers[$j]);
for ($i = 0; $i < $count_headers_j; $i++) {
if ($this->_strlen($this->_headers[$j][$i]) < if ($this->_strlen($this->_headers[$j][$i]) <
$this->_cell_lengths[$i]) { $this->_cell_lengths[$i]) {
$this->_headers[$j][$i] = $this->_headers[$j][$i] =
@@ -733,7 +739,8 @@ class Console_Table
*/ */
function _calculateCellLengths($row) function _calculateCellLengths($row)
{ {
for ($i = 0; $i < count($row); $i++) { $count_row = count($row);
for ($i = 0; $i < $count_row; $i++) {
if (!isset($this->_cell_lengths[$i])) { if (!isset($this->_cell_lengths[$i])) {
$this->_cell_lengths[$i] = 0; $this->_cell_lengths[$i] = 0;
} }

View File

@@ -313,7 +313,8 @@ function dbMakeQuery($sql, $parameters) {
// every-other item in $result will be the placeholder that was found // every-other item in $result will be the placeholder that was found
$query = ''; $query = '';
for($i = 0; $i < sizeof($result); $i+=2) { $res_size = sizeof($result);
for($i = 0; $i < $res_size; $i+=2) {
$query .= $result[ $i ]; $query .= $result[ $i ];
$j = $i+1; $j = $i+1;