From 0c07c50ca369dab91570d54725dbfe302fd6aae1 Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 25 Nov 2011 19:21:36 +0100 Subject: [PATCH] Added a setting that allows the admin to enable/disable the benchmark Also changed the behavior of the debug_mode setting --- com.woltlab.wcf/option.xml | 19 ++++++++++------- com.woltlab.wcf/template/benchmark.tpl | 20 ++++++++++++++++++ com.woltlab.wcf/template/footer.tpl | 21 ++----------------- com.woltlab.wcf/template/userException.tpl | 2 +- wcfsetup/install/files/acp/style/style.css | 4 ++++ .../install/files/acp/templates/benchmark.tpl | 20 ++++++++++++++++++ .../install/files/acp/templates/footer.tpl | 5 ++++- .../install/files/lib/system/WCF.class.php | 21 +++++++++++++++++++ .../files/lib/system/WCFSetup.class.php | 3 ++- .../statement/PreparedStatement.class.php | 5 +++-- .../system/exception/AJAXException.class.php | 3 ++- .../exception/LoggedException.class.php | 3 ++- .../exception/SystemException.class.php | 3 ++- .../system/exception/UserException.class.php | 3 ++- wcfsetup/install/files/options.inc.php | 6 +++--- 15 files changed, 99 insertions(+), 39 deletions(-) create mode 100644 com.woltlab.wcf/template/benchmark.tpl create mode 100644 wcfsetup/install/files/acp/templates/benchmark.tpl diff --git a/com.woltlab.wcf/option.xml b/com.woltlab.wcf/option.xml index f696db3416..306eceaffe 100644 --- a/com.woltlab.wcf/option.xml +++ b/com.woltlab.wcf/option.xml @@ -109,15 +109,18 @@ 0 - + + diff --git a/com.woltlab.wcf/template/benchmark.tpl b/com.woltlab.wcf/template/benchmark.tpl new file mode 100644 index 0000000000..09c8e1ad6e --- /dev/null +++ b/com.woltlab.wcf/template/benchmark.tpl @@ -0,0 +1,20 @@ +

Execution time: {@$__wcf->getBenchmark()->getExecutionTime()}s ({#($__wcf->getBenchmark()->getExecutionTime()-$__wcf->getBenchmark()->getQueryExecutionTime())/$__wcf->getBenchmark()->getExecutionTime()*100}% PHP, {#$__wcf->getBenchmark()->getQueryExecutionTime()/$__wcf->getBenchmark()->getExecutionTime()*100}% SQL) | SQL queries: {#$__wcf->getBenchmark()->getQueryCount()}

+ +{if ENABLE_DEBUG_MODE} + + + +{/if} \ No newline at end of file diff --git a/com.woltlab.wcf/template/footer.tpl b/com.woltlab.wcf/template/footer.tpl index 51ca1ca5a9..533a1258bd 100644 --- a/com.woltlab.wcf/template/footer.tpl +++ b/com.woltlab.wcf/template/footer.tpl @@ -9,27 +9,10 @@ diff --git a/com.woltlab.wcf/template/userException.tpl b/com.woltlab.wcf/template/userException.tpl index 4a852d9e5d..253a566994 100644 --- a/com.woltlab.wcf/template/userException.tpl +++ b/com.woltlab.wcf/template/userException.tpl @@ -19,7 +19,7 @@ //]]> -{if DEBUG_MODE == 'debug'} +{if ENABLE_DEBUG_MODE} diff --git a/wcfsetup/install/files/lib/system/WCF.class.php b/wcfsetup/install/files/lib/system/WCF.class.php index 52e7366b04..83e61d027a 100644 --- a/wcfsetup/install/files/lib/system/WCF.class.php +++ b/wcfsetup/install/files/lib/system/WCF.class.php @@ -573,4 +573,25 @@ class WCF { return null; } + + /** + * Returns true if the debug mode is enabled, otherwise false. + * + * @return boolean + */ + public static function debugModeIsEnabled() { + if (defined('ENABLE_DEBUG_MODE') && ENABLE_DEBUG_MODE) return true; + return false; + } + + /** + * Returns true if benchmarking is enabled, otherwise false. + * + * @return boolean + */ + public static function benchmarkIsEnabled() { + // benchmarking is enabled by default + if (!defined('ENABLE_BENCHMARK') || ENABLE_BENCHMARK) return true; + return false; + } } diff --git a/wcfsetup/install/files/lib/system/WCFSetup.class.php b/wcfsetup/install/files/lib/system/WCFSetup.class.php index 8b9593cd41..0188a839f2 100644 --- a/wcfsetup/install/files/lib/system/WCFSetup.class.php +++ b/wcfsetup/install/files/lib/system/WCFSetup.class.php @@ -31,7 +31,8 @@ define('HTTP_ENABLE_GZIP', 0); define('HTTP_GZIP_LEVEL', 0); define('CACHE_SOURCE_TYPE', 'disk'); define('MODULE_MASTER_PASSWORD', 1); -define('DEBUG_MODE', 'debug'); +define('ENABLE_DEBUG_MODE', 1); +define('ENABLE_BENCHMARK', 1); /** * WCFSetup executes the installation of the basic wcf systems. diff --git a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php index 8d649b1cf1..d979a9865f 100644 --- a/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php +++ b/wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php @@ -4,6 +4,7 @@ use wcf\data\DatabaseObject; use wcf\system\benchmark\Benchmark; use wcf\system\database\Database; use wcf\system\database\DatabaseException; +use wcf\system\WCF; /** * This is an implementation of prepared statements based upon pdo statements. @@ -79,12 +80,12 @@ class PreparedStatement { $this->database->incrementQueryCount(); try { - Benchmark::getInstance()->start($this->query, Benchmark::TYPE_SQL_QUERY); + if (WCF::benchmarkIsEnabled()) Benchmark::getInstance()->start($this->query, Benchmark::TYPE_SQL_QUERY); if (!count($parameters)) $result = $this->pdoStatement->execute(); else $result = $this->pdoStatement->execute($parameters); - Benchmark::getInstance()->stop(); + if (WCF::benchmarkIsEnabled()) Benchmark::getInstance()->stop(); return $result; } diff --git a/wcfsetup/install/files/lib/system/exception/AJAXException.class.php b/wcfsetup/install/files/lib/system/exception/AJAXException.class.php index 92a459755a..c67afd64cc 100644 --- a/wcfsetup/install/files/lib/system/exception/AJAXException.class.php +++ b/wcfsetup/install/files/lib/system/exception/AJAXException.class.php @@ -1,5 +1,6 @@ getTraceAsString(); - if (DEBUG_MODE == 'debug') { + if (WCF::debugModeIsEnabled()) { $responseData = array( 'message' => $message, 'stacktrace' => nl2br($stacktrace) diff --git a/wcfsetup/install/files/lib/system/exception/LoggedException.class.php b/wcfsetup/install/files/lib/system/exception/LoggedException.class.php index ba30ae9fda..b04573424c 100644 --- a/wcfsetup/install/files/lib/system/exception/LoggedException.class.php +++ b/wcfsetup/install/files/lib/system/exception/LoggedException.class.php @@ -1,5 +1,6 @@

Fatal error: _getMessage()); ?>

- +

getDescription(); ?>

diff --git a/wcfsetup/install/files/lib/system/exception/UserException.class.php b/wcfsetup/install/files/lib/system/exception/UserException.class.php index b4de6d89be..675b54dc67 100644 --- a/wcfsetup/install/files/lib/system/exception/UserException.class.php +++ b/wcfsetup/install/files/lib/system/exception/UserException.class.php @@ -1,5 +1,6 @@ ' . $this->getTraceAsString() . ''; } else { diff --git a/wcfsetup/install/files/options.inc.php b/wcfsetup/install/files/options.inc.php index 9f33650795..5051b9c84d 100644 --- a/wcfsetup/install/files/options.inc.php +++ b/wcfsetup/install/files/options.inc.php @@ -23,8 +23,8 @@ define('SESSION_VALIDATE_IP_ADDRESS', 0); define('SESSION_VALIDATE_USER_AGENT', 0); define('CACHE_SOURCE_TYPE', 'disk'); -define('MODULE_MASTER_PASSWORD', 1); +define('MODULE_MASTER_PASSWORD', 0); define('TIMEZONE', 'Europe/Berlin'); -// TODO: Change to 'production' later -define('DEBUG_MODE', 'debug'); +define('ENABLE_DEBUG_MODE', 1); +define('ENABLE_BENCHMARK', 1); -- 2.20.1