Skip to content

Commit 7834cdf

Browse files
author
Steven Surowiec
committed
Added type checks for query stats so we dont attempt to collect stats and explains on things like SET's and DESCRIBE's
1 parent 4ae3e07 commit 7834cdf

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

Profiler.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,14 @@ class Profiler_Profiler {
1515
* @var array
1616
*/
1717
public $config = array();
18+
19+
/**
20+
* The list of query types we care about for type specific stats
21+
*
22+
* @var array
23+
*
24+
*/
25+
protected $_queryTypes = array('select', 'update', 'delete', 'insert');
1826

1927
/**
2028
* Sets the configuration options for this object and sets the start time.
@@ -148,10 +156,11 @@ public function gatherQueryData() {
148156
'time' => ($log['end_time'] - $log['start_time']),
149157
'duplicate' => $i > 0 ? true : false);
150158

151-
// Lets figure out the type of query for our countes
159+
// Lets figure out the type of query for our counts
152160
$trimmed = trim($log['sql']);
153161
$type = strtolower(substr($trimmed, 0, strpos($trimmed, ' ')));
154-
if (isset($queryTotals['types'][$type])) {
162+
163+
if (isset($this->_queryTypes[$type]) && isset($queryTotals['types'][$type])) {
155164
$queryTotals['types'][$type]['total'] += 1;
156165
$queryTotals['types'][$type]['time'] += $query['time'];
157166
}
@@ -162,7 +171,10 @@ public function gatherQueryData() {
162171
$query['time'] = $this->getReadableTime($query['time']);
163172

164173
// If an explain callback is setup try to get the explain data
165-
if (isset($this->config['query_explain_callback']) && !empty($this->config['query_explain_callback'])) {
174+
if (isset($this->_queryTypes[$type])
175+
&& isset($this->config['query_explain_callback'])
176+
&& !empty($this->config['query_explain_callback'])) {
177+
166178
$query['explain'] = $this->_attemptToExplainQuery($query['sql']);
167179
}
168180

0 commit comments

Comments
 (0)