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

Commit

Permalink
Remove various superfluous timers and profilers
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamie Snape committed Nov 13, 2014
1 parent 17ed638 commit d77acf6
Show file tree
Hide file tree
Showing 15 changed files with 3 additions and 180 deletions.
1 change: 0 additions & 1 deletion core/AppController.php
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,6 @@ public function postDispatch()
{
parent::postDispatch();
$this->view->json = JsonComponent::encode($this->view->json);
$this->view->generatedTimer = round((microtime(true) - START_TIME), 3);
if (Zend_Registry::get('configGlobal')->environment != 'testing') {
header('Content-Type: text/html; charset=UTF-8');
}
Expand Down
6 changes: 0 additions & 6 deletions core/Bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,7 @@ protected function _initConfig()
}
}

if ($configGlobal->environment == 'production') {
Zend_Loader::loadClass('ProductionDbProfiler', BASE_PATH.'/core/models/profiler');
$params['profiler'] = new ProductionDbProfiler();
}

$db = Zend_Db::factory($configDatabase->database->adapter, $params);
$db->getProfiler()->setEnabled(true);
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('dbAdapter', $db);
Zend_Registry::set('configDatabase', $configDatabase);
Expand Down
71 changes: 0 additions & 71 deletions core/GlobalController.php
Original file line number Diff line number Diff line change
Expand Up @@ -170,23 +170,6 @@ public function preDispatch()
public function postDispatch()
{
parent::postDispatch();
if ($this->isDebug() && $this->getEnvironment() != 'testing') {
$timeEnd = microtime(true);
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
$logger->debug(
"---Timers--- Controller timer:".round(
1000 * ($timeEnd - $this->_controllerTimer),
3
)." ms - Global timer:".round(1000 * ($timeEnd - START_TIME), 3)." ms"
);

$logger->debug("---Memory Usage---".round((memory_get_usage() / (1024 * 1024)), 3)." MB");
}

if (Zend_Registry::get("configDatabase")->database->profiler == 1) {
$this->showProfiler();
}
$this->view->addHelperPath(BASE_PATH."/core/views/helpers", "Zend_View_Helper_");
}

Expand Down Expand Up @@ -253,60 +236,6 @@ public function loadElements()
}
}

/**
* Show profiler in the firebug console
*/
public function showProfiler()
{
$writer = new Zend_Log_Writer_Firebug();
$logger = new Zend_Log($writer);
$configDatabase = Zend_Registry::get('configDatabase');
if ($configDatabase->database->profiler != '1') {
return;
}
$db = Zend_Registry::get('dbAdapter');

if (method_exists($db, "getProfiler")) {
$profiler = $db->getProfiler();
$totalTime = $profiler->getTotalElapsedSecs();
$queryCount = $profiler->getTotalNumQueries();
if ($queryCount == 0) {
return;
}
}

$longestTime = 0;
$longestQuery = null;
if (isset($profiler) && !empty($profiler)) {
$querys = $profiler->getQueryProfiles();
if (!empty($querys)) {
foreach ($profiler->getQueryProfiles() as $query) {
if ($query->getElapsedSecs() > $longestTime) {
$longestTime = $query->getElapsedSecs();
$longestQuery = $query->getQuery();
}
}
$stats = '--- Profiler --- Executed '.$queryCount.' queries in '.round(
1000 * $totalTime,
3
).' ms';
$stats .= ' Longest query length: '.round(1000 * $longestTime, 3).' ms : '.$longestQuery;
$logger->log(str_replace("'", "`", $stats), Zend_Log::INFO);

foreach ($profiler->getQueryProfiles() as $query) {
$logger->log(
str_replace(
"'",
"`",
round(1000 * ($query->getElapsedSecs()), 3)." ms | ".$query->getQuery()
),
Zend_Log::INFO
);
}
}
}
}

/**
* Is Debug mode ON
*
Expand Down
3 changes: 0 additions & 3 deletions core/configs/database.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ database.params.unix_socket = ""
database.params.dbname = "midas"
database.params.username = "root"
database.params.password = ""
database.profiler = "0"
version = ""

[development]
Expand All @@ -19,7 +18,6 @@ database.params.unix_socket = ""
database.params.dbname = "midas"
database.params.username = "root"
database.params.password = ""
database.profiler = "1"
version = ""

[testing]
Expand All @@ -30,5 +28,4 @@ database.params.unix_socket = ""
database.params.dbname = "midas_test"
database.params.username = "root"
database.params.password = ""
database.profiler = "1"
version = ""
7 changes: 1 addition & 6 deletions core/controllers/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,9 @@ public function init()
$session = new Zend_Session_Namespace('Auth_User');
$db = Zend_Registry::get('dbAdapter');

if (method_exists($db, "getProfiler")) {
$profiler = $db->getProfiler();
} else {
$profiler = new Zend_Db_Profiler();
}
$environment = Zend_Registry::get('configGlobal')->environment;
$this->_environment = $environment;
$this->Component->NotifyError->initNotifier($environment, $error, $session, $profiler, $_SERVER);
$this->Component->NotifyError->initNotifier($environment, $error, $session, $_SERVER);

$this->_error = $error;

Expand Down
8 changes: 0 additions & 8 deletions core/controllers/components/NotifyErrorComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,17 @@ class NotifyErrorComponent extends AppComponent
protected $_environment;
protected $_session;
protected $_error;
protected $_profiler;

/** Init */
public function initNotifier(
$environment,
ArrayObject $error,
Zend_Session_Namespace $session,
Zend_Db_Profiler $profiler,
array $server
) {
$this->_environment = $environment;
$this->_error = $error;
$this->_session = $session;
$this->_profiler = $profiler;
$this->_server = $server;
}

Expand Down Expand Up @@ -236,11 +233,6 @@ public function getFullErrorMessage()
}
$message .= "\n";

if ($this->_profiler->getLastQueryProfile() !== false) {
$query = $this->_profiler->getLastQueryProfile()->getQuery();
$message .= "Last database query: ".$query."\n\n";
}

return $message;
}

Expand Down
6 changes: 1 addition & 5 deletions core/layouts/layout.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ echo $this->doctype().PHP_EOL;
<div class="SubMainContent">
<?php
if (isset($this->header)) {
echo "<div class='viewHeader'><span class='headerSpan'>{$this->header} </span></div>";
echo "<div class='viewHeader'><span class='headerSpan'>{$this->header}</span></div>";
}
?>
<div class="viewWrapper">
Expand Down Expand Up @@ -376,10 +376,6 @@ echo $this->doctype().PHP_EOL;
'UTF-8'
); ?> - &copy; <?php echo date('Y'); ?>
<a href="http://www.kitware.com">Kitware</a> -
<?php
echo $this->t('Generated in').' '.$this->generatedTimer.' s';
?>
-
<a href="https://github.com/midasplatform/Midas/issues"><?php echo $this->t('Report bug'); ?></a>
</div>
</div>
Expand Down
55 changes: 0 additions & 55 deletions core/models/profiler/ProductionDbProfiler.php

This file was deleted.

2 changes: 0 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
define('BASE_PATH', realpath(dirname(__FILE__)));
require_once BASE_PATH.'/vendor/autoload.php';
require_once BASE_PATH.'/core/include.php';
require_once 'Zend/Application.php';
define('START_TIME', microtime(true));

if (!is_writable(LOCAL_CONFIGS_PATH)) {
echo '<p>To use Midas Platform, the folder "'.LOCAL_CONFIGS_PATH.'" must be writable by your web server.</p>';
Expand Down
3 changes: 1 addition & 2 deletions tests/ControllerTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,8 @@ public function dispatchUrI($uri, $userDao = null, $withException = false, $asse
$errorComponent = new NotifyErrorComponent();
$session = new Zend_Session_Namespace('Auth_User');
$db = Zend_Registry::get('dbAdapter');
$profiler = $db->getProfiler();
$environment = 'testing';
$errorComponent->initNotifier($environment, $error, $session, $profiler, $_SERVER);
$errorComponent->initNotifier($environment, $error, $session, $_SERVER);

$this->fail($errorComponent->getFullErrorMessage());
}
Expand Down
9 changes: 0 additions & 9 deletions tests/DatabaseSetup.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,6 @@ function loadDbAdapter($testConfigDir, $dbType)
}
}
$db = Zend_Db::factory($configDatabase->database->adapter, $params);
if ($configDatabase->database->profiler == '1') {
$db->getProfiler()->setEnabled(true);
}
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('dbAdapter', $db);
Zend_Registry::set('configDatabase', $configDatabase);
Expand Down Expand Up @@ -220,7 +217,6 @@ function releaseLock($dbType)

require_once BASE_PATH.'/vendor/autoload.php';
require_once BASE_PATH.'/core/include.php';
define('START_TIME', microtime(true));

Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
Expand All @@ -233,11 +229,6 @@ function releaseLock($dbType)
'filterName' => 'Priority',
'filterParams' => array('priority' => Zend_Log::DEBUG),
),
array(
'writerName' => 'Firebug',
'filterName' => 'Priority',
'filterParams' => array('priority' => Zend_Log::DEBUG),
),
)
);

Expand Down
9 changes: 0 additions & 9 deletions tests/TestsBootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@

require_once BASE_PATH.'/vendor/autoload.php';
require_once BASE_PATH.'/core/include.php';
define('START_TIME', microtime(true));

Zend_Session::$_unitTestEnabled = true;
Zend_Session::start();
Expand Down Expand Up @@ -82,9 +81,6 @@
$params['unix_socket'] = $configDatabase->database->params->unix_socket;
}
$db = Zend_Db::factory($configDatabase->database->adapter, $params);
if ($configDatabase->database->profiler == '1') {
$db->getProfiler()->setEnabled(true);
}
Zend_Db_Table::setDefaultAdapter($db);
Zend_Registry::set('dbAdapter', $db);
Zend_Registry::set('configDatabase', $configDatabase);
Expand Down Expand Up @@ -129,11 +125,6 @@
'filterName' => 'Priority',
'filterParams' => array('priority' => Zend_Log::INFO),
),
array(
'writerName' => 'Firebug',
'filterName' => 'Priority',
'filterParams' => array('priority' => Zend_Log::INFO),
),
)
);

Expand Down
1 change: 0 additions & 1 deletion tests/travis/mysql.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ database.params.unix_socket = ""
database.params.dbname = "midas_test"
database.params.username = "root"
database.params.password = ""
database.profiler = "1"
version = ""
1 change: 0 additions & 1 deletion tests/travis/pgsql.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ database.params.unix_socket =
database.params.dbname = "midas_test"
database.params.username = "postgres"
database.params.password = ""
database.profiler = "1"
version = ""
1 change: 0 additions & 1 deletion tests/travis/sqlite.ini
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,4 @@ database.params.unix_socket = ""
database.params.dbname = ${TRAVIS_BUILD_DIR}/midas_test.db
database.params.username = ""
database.params.password = ""
database.profiler = "1"
version = ""

0 comments on commit d77acf6

Please sign in to comment.