From ac006a242018c99e133927b0f23d30f52d5ed53f Mon Sep 17 00:00:00 2001 From: Robert Sesek Date: Tue, 28 May 2013 09:53:48 -0400 Subject: [PATCH] Profile the database using hoplite\data\ProfilingPDO instead of DB_MySQL_PDO. This also refactors includes/init.php and parts of the imported ISSO framework/ to integrate. --- admin/home.php | 1 + framework/db_mysql_pdo.php | 52 ++--------------------- framework/kernel.php | 42 +------------------ framework/printer.php | 16 +------ framework/template.php | 14 +------ includes/hoplite | 2 +- includes/init.php | 85 +++++++++++++++++++++++--------------- 7 files changed, 61 insertions(+), 151 deletions(-) diff --git a/admin/home.php b/admin/home.php index 3b9730e..80bef6d 100644 --- a/admin/home.php +++ b/admin/home.php @@ -31,6 +31,7 @@ class HomeAction extends http\Action public function Invoke(http\Request $request, http\Response $response) { $response->body = 'Hello World'; + $response->body .= Bugdar::$db->ConstructHTMLDebugBlock(); } } diff --git a/framework/db_mysql_pdo.php b/framework/db_mysql_pdo.php index a9608a5..19991fa 100755 --- a/framework/db_mysql_pdo.php +++ b/framework/db_mysql_pdo.php @@ -31,9 +31,6 @@ * * This class wraps PDO-MySQL in the old DB_Abstract ISSO API. * -* Constants: -* ISSO_SHOW_QUERIES_LIVE - Show queries in page output as they are sent -* * @author Blue Static * @copyright Copyright (c)2002 - [#]year[#], Blue Static * @version $Revision$ @@ -91,13 +88,6 @@ class DB_MySQL_PDO */ var $querystr = ''; - /** - * History of all executed queryies - * @var array - * @access protected - */ - var $history = array(); - // ################################################################### /** * Constructor @@ -113,20 +103,16 @@ class DB_MySQL_PDO * * @access public * - * @param string Server name - * @param string User name - * @param string Password - * @param string Database name - * @param bool Use p-connect? + * @param PDO The database link. * * @return bool Result of connect */ - function connect($server, $user, $password, $database, $pconnect) + function connect($dblink) { define('ISSO_DB_LAYER', 'db_mysql_pdo'); if ($this->dblink == false) { - $this->dblink = new PDO("mysql:dbname=$database;host=$server", $user, $password); + $this->dblink = $dblink; if ($this->dblink == false) { $this->error('DB-Link == false, cannot connect'); @@ -158,16 +144,6 @@ class DB_MySQL_PDO $this->error('Invalid SQL query'); } - $this->history[] = $history = array('query' => $string, 'time' => ($this->registry->is_loaded('functions') ? $this->registry->modules['functions']->fetch_microtime_diff($time) : 0), 'trace' => $this->registry->format_debug_trace(debug_backtrace())); - - if (defined('ISSO_SHOW_QUERIES_LIVE')) - { - if (constant('ISSO_SHOW_QUERIES_LIVE')) - { - print($this->construct_query_debug($history)); - } - } - return $this->result; } @@ -320,28 +296,6 @@ class DB_MySQL_PDO return $result->rowCount(); } - // ################################################################### - /** - * Constructs a table of query information output that is used in some - * other modules to display a list of queries. This merely formats - * a DB->history array entry nicely - * - * @access public - * - * @param array An entry from DB->history - * - * @return string A formatted table block - */ - function construct_query_debug($query) - { - $block = "Query:\n\n
" . $this->registry->entity_encode($query['query']) . "
\n"; - $block .= "\n\t\n\t\t"; - $block .= "Time: $query[time]
\n\t\t
\n\t\t"; - $block .= "Backtrace:\n\t\t
" . implode("
\n", $query['trace']) . "
\n\t\n"; - - return $this->registry->message('Query Debug', $block, 1, true, false, 0); - } - // ################################################################### /** * Error wrapper for ISSO->message() diff --git a/framework/kernel.php b/framework/kernel.php index c8b90f8..02ed313 100755 --- a/framework/kernel.php +++ b/framework/kernel.php @@ -1167,45 +1167,7 @@ class ISSO $debug .= "\n\t
  • Uncached Template(s): $sizeof ( " . implode('   ', $optlist) . " )
  • "; } } - - // source control - $scinfo = 'Not Under Source Control'; - if (defined('SVN')) - { - $scinfo = constant('SVN'); - - if (preg_match('#\$Id:?\s*\$#', $scinfo)) - { - $scinfo = 'Not Under Source Control'; - } - else - { - $scinfo = preg_replace('#\$' . '(Head)?URL: (.+?) \$#e', "end(explode('/', '\\2'))", $scinfo); - $scinfo = preg_replace('#\$' . '(LastModified)?Revision: (.+?) \$#', 'SVN \\2', $scinfo); - $scinfo = preg_replace('#\$' . 'Id: (.+?) ([0-9].+?) [0-9]{4}-[0-9]{2}-[0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2}(.+?) (.+?) \$#', '\\1 - SVN \\2', $scinfo); - } - } - - $scinfo = trim($scinfo); - $debug .= "\n\t
  • Source Control: $scinfo
  • "; - - // query information - if (is_object($this->modules[ISSO_DB_LAYER])) - { - $debug .= "\n\t
  • Total Queries: " . sizeof($this->modules[ISSO_DB_LAYER]->history) . " (sanitize($_SERVER['REQUEST_URI']) . ((strpos($_SERVER['REQUEST_URI'], '?') !== false) ? '&query=1' : '?query=1') . "\">?)
  • "; - - $queries = $this->modules[ISSO_DB_LAYER]->history; - $querydebug = "
    \n" . '' . "\n\t" . ''; - foreach ($queries AS $query) - { - $querydebug .= "\n\t"; - $querydebug .= "\n\t\t\n\t"; - } - - $querydebug .= "\n
    Query Debug
    "; - $querydebug .= "\n\t\t\t$query[query]\n\n\t\t\t
    ($query[time])
    \n\n\t\t
    \n\n\n"; - } - + // total execution time if (defined('ISSO_MT_START')) { @@ -1243,7 +1205,7 @@ class ISSO $debug .= "\n"; - $debug = "\n\n\n
    \n\n
    \n" . $this->message('Debug Information', $debug, 1, true, false) . "\n
    $querydebug\n\n\n"; + $debug = "\n\n\n
    \n\n
    \n" . $this->message('Debug Information', $debug, 1, true, false) . "\n
    \n\n\n"; } return $debug; diff --git a/framework/printer.php b/framework/printer.php index 8d9b997..c604567 100755 --- a/framework/printer.php +++ b/framework/printer.php @@ -448,21 +448,6 @@ JS; */ function page_end() { - if ($this->registry->debug AND isset($_GET['query'])) - { - ob_clean(); - ob_end_clean(); - - if (is_array($this->registry->modules[ISSO_DB_LAYER]->history)) - { - foreach ($this->registry->modules[ISSO_DB_LAYER]->history AS $query) - { - echo $this->registry->modules[ISSO_DB_LAYER]->construct_query_debug($query); - } - } - exit; - } - if ($this->registry->is_loaded('printer_navigation') AND (!defined('ISSO_PRINTER_NO_NAVIGATION') OR (defined('ISSO_PRINTER_NO_NAVIGATION') AND constant('ISSO_PRINTER_NO_NAVIGATION') != true))) { echo $this->registry->modules['printer_navigation']->generate_footer_html(); @@ -474,6 +459,7 @@ JS; { echo "\n$copyright"; echo $this->registry->construct_debug_block(false); + echo $this->registry->modules[ISSO_DB_LAYER]->dblink->ConstructHTMLDebugBlock(); } echo "\n\n\n"; diff --git a/framework/template.php b/framework/template.php index 4c6fbad..c5b6a52 100755 --- a/framework/template.php +++ b/framework/template.php @@ -303,25 +303,13 @@ class Template exit; } - if ($this->registry->debug AND isset($_GET['query'])) - { - if (is_array($this->registry->modules[ISSO_DB_LAYER]->history)) - { - foreach ($this->registry->modules[ISSO_DB_LAYER]->history AS $query) - { - echo $this->registry->modules[ISSO_DB_LAYER]->construct_query_debug($query); - } - } - exit; - } - if ($this->doneflush) { trigger_error('A template has already been sent to the output buffer', E_USER_ERROR); exit; } - $template = str_replace('', $this->registry->construct_debug_block(true) . '', $template); + $template = str_replace('', $this->registry->construct_debug_block(true) . $this->registry->modules[ISSO_DB_LAYER]->dblink->ConstructHTMLDebugBlock() . '', $template); print($template); } diff --git a/includes/hoplite b/includes/hoplite index 6320967..27dda14 160000 --- a/includes/hoplite +++ b/includes/hoplite @@ -1 +1 @@ -Subproject commit 632096709e0976f7c1a58dddce4dce9cb1699592 +Subproject commit 27dda14dbe778b3d448ad82218e97611bee9302d diff --git a/includes/init.php b/includes/init.php index 6167efe..9d1b3e2 100755 --- a/includes/init.php +++ b/includes/init.php @@ -27,6 +27,9 @@ error_reporting(E_ALL & ~E_NOTICE); define('ISSO_MT_START', microtime()); define('ISSO_CHECK_POST_REFERER', 1); +// TODO(port): Define this in index.php instead. +define('BUGDAR_ROOT', dirname(dirname(__FILE__))); + require_once('./includes/version.php'); require_once('./framework/kernel.php'); @@ -45,9 +48,54 @@ if (!file_exists('./includes/config.php')) require_once('./includes/config.php'); $bugsys->setDebug($debug); +define('DEVDEBUG', $debug); +unset($debug); + +// ################################################################### +// init the big three +$bugsys->options = array(); +$bugsys->userinfo = array(); + +class Bugdar +{ + /*! @var \PDO The database connection instance. */ + static $db = NULL; + + /*! @var \hoplite\http\Input Input filter for the new stack. */ + static $input = NULL; + + static $options = array(); + static $user = array(); + static $datastore = array(); +} + +// ################################################################### +// Hoplite early initialization. + +define('HOPLITE_ROOT', dirname(__FILE__) . '/hoplite'); + +if (DEVDEBUG) { + require_once HOPLITE_ROOT . '/base/profiling.php'; + \hoplite\base\Profiling::EnableProfiling(); +} + +// ################################################################### +// Connect to the database. + +$pdo_class = '\\PDO'; +if (DEVDEBUG) { + require_once HOPLITE_ROOT . '/data/profiling_pdo.php'; + $pdo_class = '\\hoplite\\data\\ProfilingPDO'; +} +Bugdar::$db = new $pdo_class("mysql:dbname=$database;host=$servername", $username, $password); +unset($database, $servername, $username, $password); +// Let ISSO handle the database connection failure message. $bugsys->load('db_mysql_pdo', 'db', true); -$db->connect($servername, $username, $password, $database, $usepconnect); +$db->connect(Bugdar::$db); + +Bugdar::$db->SetAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); + if ($utf8) { $db->query("SET NAMES utf8"); @@ -62,53 +110,24 @@ $bugsys->load('xml', 'xml', true); // change cookie expiration to one hour $funct->cookieexp = 3600; -define('DEVDEBUG', $debug); define('TABLE_PREFIX', $tableprefix); define('COOKIE_PREFIX', $cookieprefix); -unset($database, $servername, $theuser, $password, $thepass, $usepconnect, $tableprefix, $cookieprefix); +unset($usepconnect, $tableprefix, $cookieprefix); require_once('./includes/functions_datastore.php'); require_once('./includes/functions.php'); require_once('./includes/language.php'); // ################################################################### -// init the big three -$bugsys->options = array(); -$bugsys->userinfo = array(); -Bugdar::$datastore = array(); - -class Bugdar -{ - /*! @var \PDO The database connection instance. */ - static $db = NULL; - - /*! @var \hoplite\http\Input Input filter for the new stack. */ - static $input = NULL; - - static $options = array(); - static $user = array(); - static $datastore = array(); -} - -// TODO(port): Define this in index.php instead. -define('BUGDAR_ROOT', dirname(dirname(__FILE__))); - -// ################################################################### -// Initialize Hoplite concurrently with ISSO 2.x. - -define('HOPLITE_ROOT', dirname(__FILE__) . '/hoplite'); +// Hoplite late initialization. require_once HOPLITE_ROOT . '/data/model.php'; -\hoplite\data\Model::set_db($db->dblink); +\hoplite\data\Model::set_db(Bugdar::$db); require_once HOPLITE_ROOT . '/http/input.php'; Bugdar::$input = new \hoplite\http\Input(\hoplite\http\Input::TYPE_HTML); -Bugdar::$db = $db->dblink; - -Bugdar::$db->SetAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_WARNING); - // ################################################################### // send nocache header("Expires: Mon, 26 Jul 1997 05:00:00 GMT"); -- 2.22.5