diff --git a/tools/profiling/Controller.php b/tools/profiling/Controller.php
index 846248e32..90494dd3f 100644
--- a/tools/profiling/Controller.php
+++ b/tools/profiling/Controller.php
@@ -398,6 +398,32 @@ abstract class Controller extends ControllerCore
echo '
';
+ $array_queries = array();
+ $queries = Db::getInstance()->queries;
+ uasort($queries, 'prestashop_querytime_sort');
+ foreach ($queries as $data)
+ {
+ $query_row = array(
+ 'time' => $data['time'],
+ 'query' => $data['query'],
+ 'location' => $data['file'].':'.$data['line'],
+ 'filesort' => false,
+ 'rows' => 1,
+ 'group_by' => false
+ );
+ if (preg_match('/^\s*select\s+/i', $data['query']))
+ {
+ $explain = Db::getInstance()->executeS('explain '.$data['query']);
+ if (stristr($explain[0]['Extra'], 'filesort'))
+ $query_row['filesort'] = true;
+ foreach ($explain as $row)
+ $query_row['rows'] *= $row['rows'];
+ if (stristr($data['query'], 'group by') && !preg_match('/(avg|count|min|max|group_concat|sum)\s*\(/i', $data['query']))
+ $query_row['group_by'] = true;
+ }
+ $array_queries[] = $query_row;
+ }
+
echo '
+
+
+ | Time (ms) | Rows | Query | Location | Filesort | Group By |
';
+ foreach ($array_queries as $data)
+ {
+ $data['location'] = str_replace('\\', '/', substr($data['location'], strlen(_PS_ROOT_DIR_)));
+ $data['query'] = str_replace('SQL_NO_CACHE ', '', $data['query']);
+ echo '| '.round(1000 * $data['time'], 3).' | '.$data['rows'].' | '.$data['query'].' | '.$data['location'].' | '.($data['filesort'] ? 'Yes' : '').' | '.($data['group_by'] ? 'Yes' : '').' |
';
+ }
+ echo '
+
+
';
- $queries = Db::getInstance()->queries;
- uasort($queries, 'prestashop_querytime_sort');
- foreach ($queries as $data)
+ foreach ($array_queries as $data)
{
- echo $hr.'
getTimeColor($data['time'] * 1000).'>'.round($data['time'] * 1000, 3).' ms '.htmlspecialchars($data['query'], ENT_NOQUOTES, 'utf-8', false).'
in '.$data['file'].':'.$data['line'].'
';
+ echo $hr.'
getTimeColor($data['time'] * 1000).'>'.round($data['time'] * 1000, 3).' ms '.htmlspecialchars($data['query'], ENT_NOQUOTES, 'utf-8', false).'
in '.$data['location'].'
';
if (preg_match('/^\s*select\s+/i', $data['query']))
{
- $explain = Db::getInstance()->executeS('explain '.$data['query']);
- if (stristr($explain[0]['Extra'], 'filesort'))
+ if ($data['filesort'])
echo '
getTimeColor($data['time'] * 1000).'>USING FILESORT - ';
- $browsed_rows = 1;
- foreach ($explain as $row)
- $browsed_rows *= $row['rows'];
- echo $this->displayRowsBrowsed($browsed_rows);
- if (stristr($data['query'], 'group by') && !preg_match('/(avg|count|min|max|group_concat|sum)\s*\(/i', $data['query']))
+ echo $this->displayRowsBrowsed($data['rows']);
+ if ($data['group_by'])
echo '
Useless GROUP BY need to be removed';
}
}