Skip to content
This repository has been archived by the owner on Sep 10, 2021. It is now read-only.

Commit

Permalink
Merge pull request #212 from midasplatform/analysis-X0g5Qw
Browse files Browse the repository at this point in the history
Applied fixes from StyleCI
  • Loading branch information
mgrauer committed Mar 12, 2016
2 parents b7e219a + 5eb29f3 commit f2c57d3
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,26 +38,29 @@
$application = new Zend_Application('global', CORE_CONFIG);
$application->bootstrap()->run();


if (array_key_exists('profiler', $_GET)) {
Zend_Registry::get('logger')->info('Profiler for '.$_SERVER['REQUEST_URI']);
$db = Zend_Db_Table::getDefaultAdapter();
$profiler = $db -> getProfiler();
$profiler = $db->getProfiler();
$profile = '';
$queryCounts = array();
$queryTimes = array();
foreach($profiler -> getQueryProfiles() as $query) {
if (array_key_exists($query->getQuery(), $queryCounts)) {
$queryCounts[$query->getQuery()] += 1;
} else {
$queryCounts[$query->getQuery()] = 1;
}
$queryTimes[] = array('query' => $query->getQuery(), 'time_seconds' => $query->getElapsedSecs());
foreach ($profiler->getQueryProfiles() as $query) {
if (array_key_exists($query->getQuery(), $queryCounts)) {
$queryCounts[$query->getQuery()] += 1;
} else {
$queryCounts[$query->getQuery()] = 1;
}
$queryTimes[] = array('query' => $query->getQuery(), 'time_seconds' => $query->getElapsedSecs());
}
// Sort queries by count and time
arsort($queryCounts, SORT_NUMERIC);
function cmp($a, $b) {
if ($a['time_seconds'] == $b['time_seconds']) { return 0; }
function cmp($a, $b)
{
if ($a['time_seconds'] == $b['time_seconds']) {
return 0;
}

return ($a['time_seconds'] < $b['time_seconds']) ? 1 : -1;
}
uasort($queryTimes, 'cmp');
Expand All @@ -66,9 +69,11 @@ function cmp($a, $b) {
// Logs much less info, only the five slowest queries.
$fiveSlowest = array();
$count = 0;
foreach($queryTimes as $query => $time) {
foreach ($queryTimes as $query => $time) {
$fiveSlowest[$query] = $time;
if ($count++ == 4) { break; }
if ($count++ == 4) {
break;
}
}
Zend_Registry::get('logger')->info(print_r($fiveSlowest, true));
} else {
Expand Down

0 comments on commit f2c57d3

Please sign in to comment.