From 3a9ee07311027e3b1acca7ec5fb04be3ccd3f800 Mon Sep 17 00:00:00 2001 From: mgrauer Date: Thu, 10 Mar 2016 21:56:39 +0000 Subject: [PATCH 1/5] DEBUG: do not merge; log community view query profiles --- core/Bootstrap.php | 1 + core/controllers/CommunityController.php | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/core/Bootstrap.php b/core/Bootstrap.php index 64f3bbc5e..9c70b75e5 100644 --- a/core/Bootstrap.php +++ b/core/Bootstrap.php @@ -87,6 +87,7 @@ protected function _initDatabase() 'username' => $config->database->params->username, 'password' => $config->database->params->password, 'driver_options' => $driverOptions, + 'profiler' => true, ); if (empty($config->database->params->unix_socket)) { diff --git a/core/controllers/CommunityController.php b/core/controllers/CommunityController.php index d0812fb42..36b52c0b5 100644 --- a/core/controllers/CommunityController.php +++ b/core/controllers/CommunityController.php @@ -433,6 +433,15 @@ public function viewAction() 'CALLBACK_CORE_GET_COMMUNITY_VIEW_ADMIN_ACTIONS', array('community' => $communityDao) ); + + $db = Zend_Db_Table::getDefaultAdapter(); + $profiler = $db -> getProfiler(); + $profile = ''; + foreach($profiler -> getQueryProfiles() as $query) { + $profile .= $query -> getQuery() . "\n" + . 'Time: ' . $query -> getElapsedSecs(); + } + $this->getLogger()->info($profile); } /** Delete a community */ From 8781a13d0a9d5fb94e86256f31741ba3c8756f11 Mon Sep 17 00:00:00 2001 From: mgrauer Date: Fri, 11 Mar 2016 14:40:25 +0000 Subject: [PATCH 2/5] Generalized db profiling, with query param 'profiler' --- core/controllers/CommunityController.php | 9 -------- index.php | 27 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/core/controllers/CommunityController.php b/core/controllers/CommunityController.php index 36b52c0b5..d0812fb42 100644 --- a/core/controllers/CommunityController.php +++ b/core/controllers/CommunityController.php @@ -433,15 +433,6 @@ public function viewAction() 'CALLBACK_CORE_GET_COMMUNITY_VIEW_ADMIN_ACTIONS', array('community' => $communityDao) ); - - $db = Zend_Db_Table::getDefaultAdapter(); - $profiler = $db -> getProfiler(); - $profile = ''; - foreach($profiler -> getQueryProfiles() as $query) { - $profile .= $query -> getQuery() . "\n" - . 'Time: ' . $query -> getElapsedSecs(); - } - $this->getLogger()->info($profile); } /** Delete a community */ diff --git a/index.php b/index.php index c9eb2108f..ee3dad31c 100644 --- a/index.php +++ b/index.php @@ -37,3 +37,30 @@ $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(); + $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()); + } + // Sort queries by count and time + arsort($queryCounts, SORT_NUMERIC); + 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'); + Zend_Registry::get('logger')->info(print_r($queryCounts, true)); + Zend_Registry::get('logger')->info(print_r($queryTimes, true)); +} From 059cdd59a51173c0db94bf68ab69acdeaf286bec Mon Sep 17 00:00:00 2001 From: mgrauer Date: Sat, 12 Mar 2016 15:21:32 +0000 Subject: [PATCH 3/5] Enable db profiler upon 'profiler' query param' --- core/Bootstrap.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/Bootstrap.php b/core/Bootstrap.php index 9c70b75e5..15190ef22 100644 --- a/core/Bootstrap.php +++ b/core/Bootstrap.php @@ -87,7 +87,7 @@ protected function _initDatabase() 'username' => $config->database->params->username, 'password' => $config->database->params->password, 'driver_options' => $driverOptions, - 'profiler' => true, + 'profiler' => array_key_exists('profiler', $_GET), ); if (empty($config->database->params->unix_socket)) { From b7e219adc36282c030cd703c5cbb14050df4106d Mon Sep 17 00:00:00 2001 From: mgrauer Date: Sat, 12 Mar 2016 15:21:54 +0000 Subject: [PATCH 4/5] Add query param 'profilerFiveSlowest' --- index.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index ee3dad31c..dbe8f0bb7 100644 --- a/index.php +++ b/index.php @@ -61,6 +61,18 @@ function cmp($a, $b) { return ($a['time_seconds'] < $b['time_seconds']) ? 1 : -1; } uasort($queryTimes, 'cmp'); - Zend_Registry::get('logger')->info(print_r($queryCounts, true)); - Zend_Registry::get('logger')->info(print_r($queryTimes, true)); + + if (array_key_exists('profilerFiveSlowest', $_GET)) { + // Logs much less info, only the five slowest queries. + $fiveSlowest = array(); + $count = 0; + foreach($queryTimes as $query => $time) { + $fiveSlowest[$query] = $time; + if ($count++ == 4) { break; } + } + Zend_Registry::get('logger')->info(print_r($fiveSlowest, true)); + } else { + Zend_Registry::get('logger')->info(print_r($queryCounts, true)); + Zend_Registry::get('logger')->info(print_r($queryTimes, true)); + } } From 5eb29f39aff0f3c7101f96d9266888c7f109932d Mon Sep 17 00:00:00 2001 From: mgrauer Date: Sat, 12 Mar 2016 10:23:15 -0500 Subject: [PATCH 5/5] Applied fixes from StyleCI --- index.php | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/index.php b/index.php index dbe8f0bb7..e0f101c5c 100644 --- a/index.php +++ b/index.php @@ -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'); @@ -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 {