Added performance logging for initial SQL creation
authorAlexander Ebert <ebert@woltlab.com>
Sun, 2 Jun 2013 19:55:29 +0000 (21:55 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 2 Jun 2013 19:55:29 +0000 (21:55 +0200)
wcfsetup/install/files/lib/system/WCFSetup.class.php
wcfsetup/install/files/lib/system/database/util/SQLParser.class.php

index 8ee2ef5390568df02fd4644fdaf5a9759da1f505..e6045e0eb62ffcb912c63ceec557abdad53237a5 100644 (file)
@@ -727,6 +727,12 @@ class WCFSetup extends WCF {
                // installation number value 'n' (WCF_N) must be reflected in the executed sql queries
                $sql = StringUtil::replace('wcf1_', 'wcf'.WCF_N.'_', $sql);
                
+               $GLOBALS['__db'] = array(
+                       'parse' => 0,
+                       'modify' => 0,
+                       'insert' => 0
+               );
+               
                // execute sql queries
                $parser = new SQLParser($sql);
                $parser->execute();
@@ -735,6 +741,7 @@ class WCFSetup extends WCF {
                preg_match_all("~CREATE\s+TABLE\s+(\w+)~i", $sql, $matches);
                
                if (!empty($matches[1])) {
+                       $s2 = microtime(true);
                        $sql = "INSERT INTO     wcf".WCF_N."_package_installation_sql_log
                                                (sqlTable)
                                VALUES          (?)";
@@ -742,8 +749,11 @@ class WCFSetup extends WCF {
                        foreach ($matches[1] as $tableName) {
                                $statement->execute(array($tableName));
                        }
+                       $GLOBALS['__db']['insert'] = round(microtime(true) - $s2, 3);
                }
                
+               file_put_contents(WCF_DIR.'__sqlPerformance.log', print_r($GLOBALS['__db']));
+               
                /*
                 * Manually install PIPPackageInstallationPlugin since install.sql content is not escaped resulting
                 * in different behaviour in MySQL and MSSQL. You SHOULD NOT move this into install.sql!
index c2d469f38b9328d29849fd5c76c745bb9a3d51c9..48223d794955283f45c5cf85b2a52828005e2d19 100644 (file)
@@ -46,7 +46,11 @@ class SQLParser {
                        if (preg_match('~^(ALTER\s+TABLE|CREATE\s+INDEX|CREATE\s+TABLE|DROP\s+INDEX|DROP\s+TABLE|INSERT|UPDATE|DELETE)~i', $query, $match)) {
                                $statement = strtoupper(preg_replace('~\s+~', ' ', $match[0]));
                                
+                               $GLOBALS['__db']['parse']++;
+                               
+                               $s = microtime(true);
                                $this->executeStatement($statement, $query);
+                               $GLOBALS['__db']['modify'] += round(microtime(true) - $s, 3);
                        }
                }
        }