From fa65e08029fab152626ed2d5ef7a573b405a456a Mon Sep 17 00:00:00 2001 From: nuxsmin Date: Thu, 20 Apr 2017 13:31:49 +0200 Subject: [PATCH] * [MOD] Improve elapsed time calc and code refactoring. --- inc/Base.php | 3 +-- inc/BaseFunctions.php | 5 ++--- inc/SP/Controller/ControllerBase.class.php | 6 ++---- inc/SP/Core/Upgrade/Crypt.class.php | 4 +--- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/inc/Base.php b/inc/Base.php index cb0027bd..dc7d074c 100644 --- a/inc/Base.php +++ b/inc/Base.php @@ -61,9 +61,8 @@ $ClassLoader->register(); require __DIR__ . DIRECTORY_SEPARATOR . 'BaseFunctions.php'; -// Empezar a calcular el tiempo y memoria utilizados +// Empezar a calcular la memoria utilizada $memInit = memory_get_usage(); -$timeStart = microtime_float(); // Inicializar sysPass Init::start(); diff --git a/inc/BaseFunctions.php b/inc/BaseFunctions.php index d4815c0c..83b928d2 100644 --- a/inc/BaseFunctions.php +++ b/inc/BaseFunctions.php @@ -97,8 +97,7 @@ function mb_ucfirst($string) * * @returns float con el tiempo actual */ -function microtime_float() +function getElapsedTime() { - list($usec, $sec) = explode(' ', microtime()); - return ((float)$usec + (float)$sec); + return microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']; } \ No newline at end of file diff --git a/inc/SP/Controller/ControllerBase.class.php b/inc/SP/Controller/ControllerBase.class.php index e9665f6e..5449f81c 100644 --- a/inc/SP/Controller/ControllerBase.class.php +++ b/inc/SP/Controller/ControllerBase.class.php @@ -131,12 +131,10 @@ abstract class ControllerBase private function setViewVars() { - global $timeStart; - $this->UserData = Session::getUserData(); $this->UserProfileData = Session::getUserProfile(); - $this->view->assign('timeStart', $timeStart); + $this->view->assign('timeStart', $_SERVER['REQUEST_TIME_FLOAT']); $this->view->assign('icons', $this->icons); $this->view->assign('SessionUserData', $this->UserData); } @@ -192,7 +190,7 @@ abstract class ControllerBase $this->view->addTemplate('debug', 'common'); - $this->view->assign('time', microtime_float() - $this->view->timeStart); + $this->view->assign('time', getElapsedTime()); $this->view->assign('memInit', $memInit / 1000); $this->view->assign('memEnd', memory_get_usage() / 1000); } diff --git a/inc/SP/Core/Upgrade/Crypt.class.php b/inc/SP/Core/Upgrade/Crypt.class.php index 9be05e19..dd460a8f 100644 --- a/inc/SP/Core/Upgrade/Crypt.class.php +++ b/inc/SP/Core/Upgrade/Crypt.class.php @@ -52,8 +52,6 @@ class Crypt */ public static function migrate(&$masterPass) { - global $timeStart; - try { AccountHistoryCrypt::$currentMPassHash = ConfigDB::getValue('masterPwd'); @@ -73,7 +71,7 @@ class Crypt throw new SPException(SPException::SP_ERROR, __('No es posible finalizar una transacción', false)); } - debugLog('Total time: ' . (microtime_float() - $timeStart)); + debugLog('Total time: ' . getElapsedTime()); return true; } catch (\Exception $e) {