Skip to content

Commit

Permalink
Merge pull request #16 from rakibabu/master
Browse files Browse the repository at this point in the history
When profiler is disabled, sql tab is returning php warnings
  • Loading branch information
vpietri authored Jan 18, 2017
2 parents d7dc3bb + c8b2760 commit 71d3df5
Showing 1 changed file with 17 additions and 11 deletions.
28 changes: 17 additions & 11 deletions Block/Tab/Content/Sql.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ public function _initSqlProfilerData()
$this->_sql_profiler = new \Zend_Db_Profiler();
if(!is_null($this->_resource)) {
$this->_sql_profiler = $this->_resource->getConnection('read')->getProfiler();
foreach($this->_sql_profiler->getQueryProfiles() as $query) {
if ($query->getElapsedSecs() > $this->_longestQueryTime) {
$this->_longestQueryTime = $query->getElapsedSecs();
$this->_longestQuery = $query->getQuery();
if ($this->_sql_profiler->getQueryProfiles() && is_array($this->_sql_profiler->getQueryProfiles())) {
foreach ($this->_sql_profiler->getQueryProfiles() as $query) {
if ($query->getElapsedSecs() > $this->_longestQueryTime) {
$this->_longestQueryTime = $query->getElapsedSecs();
$this->_longestQuery = $query->getQuery();
}
if ($query->getElapsedSecs() < $this->_shortestQueryTime) {
$this->_shortestQueryTime = $query->getElapsedSecs();
}

$this->_all_queries[] = ['sql' => $query->getQuery(), 'time' => $query->getElapsedSecs(), 'grade' => 'medium'];
}
if ($query->getElapsedSecs() < $this->_shortestQueryTime) {
$this->_shortestQueryTime = $query->getElapsedSecs();
}

$this->_all_queries[] = ['sql'=>$query->getQuery(), 'time'=>$query->getElapsedSecs(), 'grade'=>'medium'];
}
}
}
Expand Down Expand Up @@ -110,7 +112,11 @@ public function getAllQueries()
$squareSum = pow($query['time'] - $average, 2);
}

$standardDeviation = sqrt($squareSum/$this->getTotalNumQueries());
$standardDeviation = sqrt(0);

if ($squareSum) {
$standardDeviation = sqrt($squareSum/$this->getTotalNumQueries());
}

foreach ($this->_all_queries as $index=>$query) {
if($query['time']<($this->_shortestQueryTime+2*$standardDeviation)) {
Expand Down Expand Up @@ -153,4 +159,4 @@ public function formatSqlTime($time)
return $formatedTime . 'ms';
}

}
}

0 comments on commit 71d3df5

Please sign in to comment.