Added a setting that allows the admin to enable/disable the benchmark
authorMarcel Werk <burntime@woltlab.com>
Fri, 25 Nov 2011 18:21:36 +0000 (19:21 +0100)
committerMarcel Werk <burntime@woltlab.com>
Fri, 25 Nov 2011 18:21:36 +0000 (19:21 +0100)
Also changed the behavior of the debug_mode setting

15 files changed:
com.woltlab.wcf/option.xml
com.woltlab.wcf/template/benchmark.tpl [new file with mode: 0644]
com.woltlab.wcf/template/footer.tpl
com.woltlab.wcf/template/userException.tpl
wcfsetup/install/files/acp/style/style.css
wcfsetup/install/files/acp/templates/benchmark.tpl [new file with mode: 0644]
wcfsetup/install/files/acp/templates/footer.tpl
wcfsetup/install/files/lib/system/WCF.class.php
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/database/statement/PreparedStatement.class.php
wcfsetup/install/files/lib/system/exception/AJAXException.class.php
wcfsetup/install/files/lib/system/exception/LoggedException.class.php
wcfsetup/install/files/lib/system/exception/SystemException.class.php
wcfsetup/install/files/lib/system/exception/UserException.class.php
wcfsetup/install/files/options.inc.php

index f696db3416004480dc36226b8c272243ee77c96b..306eceaffef120cdd7756d650b557036589d3002 100644 (file)
                                <defaultvalue>0</defaultvalue>
                        </option>
 
-                       <option name="debug_mode">
+                       <option name="enable_debug_mode">
                                <categoryname>module.system</categoryname>
-                               <optiontype>radiobuttons</optiontype>
-                               <!-- TODO: change to 'production' later -->
-                               <defaultvalue><![CDATA[debug]]></defaultvalue>
-                               <selectoptions>
-                                       <![CDATA[debug:wcf.acp.option.debug_mode.debug
-production:wcf.acp.option.debug_mode.production]]>
-                               </selectoptions>
+                               <optiontype>boolean</optiontype>
+                               <!-- TODO: change to '0' (production mode) later -->
+                               <defaultvalue>1</defaultvalue>
+                       </option>
+                       
+                       <option name="enable_benchmark">
+                               <categoryname>module.system</categoryname>
+                               <optiontype>boolean</optiontype>
+                               <!-- TODO: change to '0' (production mode) later -->
+                               <defaultvalue>1</defaultvalue>
                        </option>
                        
                        <!-- general.page -->
diff --git a/com.woltlab.wcf/template/benchmark.tpl b/com.woltlab.wcf/template/benchmark.tpl
new file mode 100644 (file)
index 0000000..09c8e1a
--- /dev/null
@@ -0,0 +1,20 @@
+<p style="margin-top: 10px; font-size: .85em" id="benchmark">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()}</p>
+
+{if ENABLE_DEBUG_MODE} 
+       <ul id="benchmarkDetails" style="display: none; max-height: 500px; overflow: auto">
+               {foreach from=$__wcf->getBenchmark()->getItems() item=item}
+                       <li style="margin-bottom: 8px;"{if $item.use >= 0.01} class="hot"{/if}>{if $item.type == 1}(SQL Query) {/if}{$item.text}<br /><small style="font-size: .85em">Execution time: {@$item.use}s</small></li>
+               {/foreach}
+       </ul>
+       
+       <script type="text/javascript">
+               //<![CDATA[
+               $(function() {
+                       $('#benchmark').click(function() {
+                               WCF.showDialog('benchmarkDetails', true);
+                               return false;
+                       });
+               });
+               //]]>
+       </script>
+{/if}
\ No newline at end of file
index 51ca1ca5a951e59e05efb9ee50a81b9a96fc616a..533a1258bdd36dcf902d05d307d0b1e1084a51df 100644 (file)
@@ -9,27 +9,10 @@
        <!-- FOOTER -->
        <footer id="pageFooter" class="pageFooter">
                <div>
-                       {include file=footerMenu}
+                       {include file='footerMenu'}
                </div>
                
-               <p style="margin-top: 10px; font-size: .85em" id="benchmark">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()}</p>
-               
-               <ul id="benchmarkDetails" style="display: none; max-height: 500px; overflow: auto">
-                       {foreach from=$__wcf->getBenchmark()->getItems() item=item}
-                               <li style="margin-bottom: 8px;{if $item.use >= 0.01} color: #b00{/if}">{if $item.type == 1}(SQL Query) {/if}{$item.text}<br /><small style="font-size: .85em">Execution time: {@$item.use}s</small></li>
-                       {/foreach}
-               </ul>
-               
-               <script type="text/javascript">
-                       //<![CDATA[
-                       $(function() {
-                               $('#benchmark').click(function() {
-                                       WCF.showDialog('benchmarkDetails', true);
-                                       return false;
-                               });
-                       });
-                       //]]>
-               </script>
+               {if ENABLE_BENCHMARK}{include file='benchmark'}{/if}
                
                {event name='copyright'}
        </footer>
index 4a852d9e5dea18e79038d3ab946cc9a422c74a6e..253a566994ec9ef7d527fd7af99d01169fc97fc9 100644 (file)
@@ -19,7 +19,7 @@
        //]]>
 </script>
 
-{if DEBUG_MODE == 'debug'}
+{if ENABLE_DEBUG_MODE}
        <!-- 
        {$name} thrown in {$file} ({@$line})
        Stracktrace:
index 95e191b74c69ea9ec0851e366d3a2e1087f066d8..535b3687fc3ddbe2d6e44e076111d18982fb9adc 100644 (file)
@@ -111,6 +111,10 @@ hr {
        background-color: rgba(255, 170, 34, .7);
 }
 
+.hot {
+       color: #b00; 
+}
+
 
 /* ############## Body ############## */
 
diff --git a/wcfsetup/install/files/acp/templates/benchmark.tpl b/wcfsetup/install/files/acp/templates/benchmark.tpl
new file mode 100644 (file)
index 0000000..09c8e1a
--- /dev/null
@@ -0,0 +1,20 @@
+<p style="margin-top: 10px; font-size: .85em" id="benchmark">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()}</p>
+
+{if ENABLE_DEBUG_MODE} 
+       <ul id="benchmarkDetails" style="display: none; max-height: 500px; overflow: auto">
+               {foreach from=$__wcf->getBenchmark()->getItems() item=item}
+                       <li style="margin-bottom: 8px;"{if $item.use >= 0.01} class="hot"{/if}>{if $item.type == 1}(SQL Query) {/if}{$item.text}<br /><small style="font-size: .85em">Execution time: {@$item.use}s</small></li>
+               {/foreach}
+       </ul>
+       
+       <script type="text/javascript">
+               //<![CDATA[
+               $(function() {
+                       $('#benchmark').click(function() {
+                               WCF.showDialog('benchmarkDetails', true);
+                               return false;
+                       });
+               });
+               //]]>
+       </script>
+{/if}
\ No newline at end of file
index 8581f90719ca65f0cc6dd968ca06a01f1b0707aa..567e2f13fc1f951bdadab65e3ad2f05bf1494319 100644 (file)
                                </ul>
                        </nav>
                </div>
-               <adress class="copyright"><a href="http://www.woltlab.com" title="Go to the WoltLab website">Copyright &copy; 2001-2011 WoltLab&reg; GmbH</a></adress>
+               
+               {if ENABLE_BENCHMARK}{include file='benchmark' sandbox=false}{/if}
+               
+               <address class="copyright"><a href="http://www.woltlab.com" title="Go to the WoltLab website">Copyright &copy; 2001-2011 WoltLab&reg; GmbH</a></address>
        </footer>
        <!-- /FOOTER -->
        <a id="bottom"></a>
index 52e7366b042836cf7caebdead6b9c0a2e6ae6fca..83e61d027a93ceae4e129fa7209bb031efb5db2c 100644 (file)
@@ -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;
+       }
 }
index 8b9593cd41824352c4505056bed01ede67f1eed4..0188a839f289de597635c1c31cffbceb03125706 100644 (file)
@@ -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.
index 8d649b1cf1d148e3cf3b4d9744cdf10a8f36c773..d979a9865f003b08f273beb020a978df137265a8 100644 (file)
@@ -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;
                }
index 92a459755abeca74438b44c18e352a4bc3a93403..c67afd64cc18e41e6c936caa2d5e58a2adc47247 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\exception;
+use wcf\system\WCF;
 use wcf\util\JSON;
 
 /**
@@ -22,7 +23,7 @@ class AJAXException extends LoggedException {
        public function __construct($message, $stacktrace = null) {
                if ($stacktrace === null) $stacktrace = $this->getTraceAsString();
                
-               if (DEBUG_MODE == 'debug') {
+               if (WCF::debugModeIsEnabled()) {
                        $responseData = array(
                                'message' => $message,
                                'stacktrace' => nl2br($stacktrace)
index ba30ae9fda17b8f053e6ac8cd5b187cb8c138a63..b04573424c2698f5341fdcc9268c6c1737398e47 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\exception;
+use wcf\system\WCF;
 
 /**
  * A logged exceptions prevents information disclosures and provides an easy
@@ -19,7 +20,7 @@ class LoggedException extends \Exception {
         * @see         \Exception::getMessage()
         */
        public function _getMessage() {
-               if (DEBUG_MODE == 'production') {
+               if (!WCF::debugModeIsEnabled()) {
                        return 'An error occured. Sorry.';
                }
                
index 312c2469966448f232dbc94593a33fa0d345191f..0e90cae4cfa9a3bd0e2d1a352cdcf62eca097ff9 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\exception;
+use wcf\system\WCF;
 use wcf\util\StringUtil;
 
 /**
@@ -141,7 +142,7 @@ class SystemException extends LoggedException implements IPrintableException {
                                <div class="systemException">
                                        <h1>Fatal error: <?php echo StringUtil::encodeHTML($this->_getMessage()); ?></h1>
                                        
-                                       <?php if (DEBUG_MODE == 'debug') { ?>
+                                       <?php if (WCF::debugModeIsEnabled()) { ?>
                                                <div>
                                                        <p><?php echo $this->getDescription(); ?></p>
                                                
index b4de6d89be730329e89d22c2010e1dfb7ad4f53a..675b54dc673b330114be423386a6fd19ace75c14 100644 (file)
@@ -1,5 +1,6 @@
 <?php
 namespace wcf\system\exception;
+use wcf\system\WCF;
 
 /**
  * A UserException is thrown when a user gives invalid input data.
@@ -16,7 +17,7 @@ abstract class UserException extends LoggedException implements IPrintableExcept
         * @see wcf\system\exception\IPrintableException::show()
         */
        public function show() {
-               if (DEBUG_MODE == 'debug') {
+               if (WCF::debugModeIsEnabled()) {
                        echo '<pre>' . $this->getTraceAsString() . '</pre>';
                }
                else {
index 9f336507950d1c92ba7b9b99bd178d487c02d290..5051b9c84d28d150ce7c2507841450ce11cfe56a 100644 (file)
@@ -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);