diff --git a/includes/database.class.php b/includes/database.class.php index b097750c4..8656cfa48 100644 --- a/includes/database.class.php +++ b/includes/database.class.php @@ -15,6 +15,8 @@ class DB private static $optionsCache = []; private static $connectionCache = []; + private static $logs = []; + private static function createConnectSyntax(&$options) { return 'mysqli://'.$options['user'].':'.$options['pass'].'@'.$options['host'].'/'.$options['db']; @@ -58,6 +60,35 @@ public static function errorHandler($message, $data) exit; } + public static function logger($self, $query, $trace) + { + if ($trace) // actual query + self::$logs[] = [substr(str_replace("\n", ' ', $query), 0, 200)]; + else // the statistics + { + end(self::$logs); + self::$logs[key(self::$logs)][] = substr(explode(';', $query)[0], 5); + } + } + + public static function getLogs() + { + $out = '
';
+        foreach (self::$logs as $i => [$l, $t])
+        {
+            $c = 'inherit';
+            preg_match('/(\d+)/', $t, $m);
+            if ($m[1] > 100)
+                $c = '#FFA0A0';
+            else if ($m[1] > 20)
+                $c = '#FFFFA0';
+
+            $out .= '';
+        }
+
+        return Util::jsEscape($out).'
TimeQuery
'.$i.'.'.$t.''.$l.'
'; + } + public static function getDB($idx) { return self::$interfaceCache[$idx]; diff --git a/includes/kernel.php b/includes/kernel.php index 22d73a373..79a92b222 100644 --- a/includes/kernel.php +++ b/includes/kernel.php @@ -230,6 +230,20 @@ if (!empty($AoWoWconf['aowow']) && User::init()) User::save(); // save user-variables in session + // set up some logging (~10 queries will execute before we init the user and load the config) + if (CFG_DEBUG && User::isInGroup(U_GROUP_DEV | U_GROUP_ADMIN)) + { + DB::Aowow()->setLogger(['DB', 'logger']); + DB::World()->setLogger(['DB', 'logger']); + if (DB::isConnected(DB_AUTH)) + DB::Auth()->setLogger(['DB', 'logger']); + + if (!empty($AoWoWconf['characters'])) + foreach ($AoWoWconf['characters'] as $idx => $__) + if (DB::isConnected(DB_CHARACTERS . $idx)) + DB::Characters($idx)->setLogger(['DB', 'logger']); + } + // hard-override locale for this call (should this be here..?) // all strings attached.. if (!empty($AoWoWconf['aowow'])) diff --git a/template/bricks/footer.tpl.php b/template/bricks/footer.tpl.php index 817e4eab6..58e23688c 100644 --- a/template/bricks/footer.tpl.php +++ b/template/bricks/footer.tpl.php @@ -32,5 +32,14 @@ + + +