Profile the database using hoplite\data\ProfilingPDO instead of DB_MySQL_PDO.
authorRobert Sesek <rsesek@bluestatic.org>
Tue, 28 May 2013 13:53:48 +0000 (09:53 -0400)
committerRobert Sesek <rsesek@bluestatic.org>
Tue, 28 May 2013 13:59:26 +0000 (09:59 -0400)
This also refactors includes/init.php and parts of the imported ISSO framework/
to integrate.

admin/home.php
framework/db_mysql_pdo.php
framework/kernel.php
framework/printer.php
framework/template.php
includes/hoplite
includes/init.php

index 3b9730e562758f9a92a2d2d764f0146a00dea5d9..80bef6d7fc3aab06ef20055181cab0a5b899906b 100644 (file)
@@ -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();
        }
 }
 
index a9608a538970112a84bd4141be5e0ddd1b1c59bb..19991fa7d54efc9a27984b2ac398f339589c3788 100755 (executable)
@@ -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 = "<strong>Query:</strong>\n\n<div>" . $this->registry->entity_encode($query['query']) . "</div>\n";
-               $block .= "<tr style=\"background-color: #FFFFFF; text-align: left\">\n\t<td>\n\t\t";
-               $block .= "<strong>Time:</strong> $query[time]<br />\n\t\t<br />\n\t\t";
-               $block .= "<strong>Backtrace:</strong>\n\t\t<div>" . implode("<br />\n", $query['trace']) . "</div>\n\t</td>\n</tr>";
-
-               return $this->registry->message('Query Debug', $block, 1, true, false, 0);
-       }
-
        // ###################################################################
        /**
        * Error wrapper for ISSO->message()
index c8b90f8fe2fe043ef7153ee3523c4366cc48d95f..02ed313910879defee0d475045a3a71152ec4e90 100755 (executable)
@@ -1167,45 +1167,7 @@ class ISSO
                                        $debug .= "\n\t<li><strong style=\"color: red\">Uncached Template(s):</strong> $sizeof ( " . implode(' &nbsp; ', $optlist) . " )</li>";
                                }
                        }
-                       
-                       // 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<li><strong>Source Control:</strong> $scinfo</li>";
-                       
-                       // query information
-                       if (is_object($this->modules[ISSO_DB_LAYER]))
-                       {
-                               $debug .= "\n\t<li><strong>Total Queries:</strong> " . sizeof($this->modules[ISSO_DB_LAYER]->history) . " (<a href=\"" . $this->sanitize($_SERVER['REQUEST_URI']) . ((strpos($_SERVER['REQUEST_URI'], '?') !== false) ? '&amp;query=1' : '?query=1') . "\">?</a>)</li>";
-                               
-                               $queries = $this->modules[ISSO_DB_LAYER]->history;
-                               $querydebug = "<br />\n" . '<table cellpadding="4" cellspacing="1" border="0" align="center" width="30%" style="background-color: rgb(60, 60, 60); color: white">' . "\n\t" . '<tr><td><strong>Query Debug</strong></td></tr>';
-                               foreach ($queries AS $query)
-                               {
-                                       $querydebug .= "\n\t<tr style=\"background-color: rgb(230, 230, 230); color: black\">";
-                                       $querydebug .= "\n\t\t<td>";
-                                       $querydebug .= "\n\t\t\t$query[query]\n\n\t\t\t<div style=\"font-size: 9px;\">($query[time])</div>\n<!--\n" . implode("\n", $query[trace]) . "\n-->\n\t\t</td>\n\t</tr>";
-                               }
-                               
-                               $querydebug .= "\n</table>\n\n\n";
-                       }
-                       
+
                        // total execution time
                        if (defined('ISSO_MT_START'))
                        {
@@ -1243,7 +1205,7 @@ class ISSO
                        
                        $debug .= "\n</ul>";
                                                
-                       $debug = "\n\n<!-- dev debug -->\n<div align=\"center\">\n\n<hr />\n" . $this->message('Debug Information', $debug, 1, true, false) . "\n</div>$querydebug\n<!-- / dev debug -->\n\n";
+                       $debug = "\n\n<!-- dev debug -->\n<div align=\"center\">\n\n<hr />\n" . $this->message('Debug Information', $debug, 1, true, false) . "\n</div>\n<!-- / dev debug -->\n\n";
                }
                
                return $debug;
index 8d9b997027e5cb85c2d5d0ca761ff525f5024a66..c60456758c4adb5b3d50c7f9d15c4d28db5d4dbe 100755 (executable)
@@ -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</body>\n</html>";
index 4c6fbad645080dc60a04e013d1168db117aa29dd..c5b6a527a6af7b0c83ec8f3392d2f3baa2be1162 100755 (executable)
@@ -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('</body>', $this->registry->construct_debug_block(true) . '</body>', $template);
+               $template = str_replace('</body>', $this->registry->construct_debug_block(true) . $this->registry->modules[ISSO_DB_LAYER]->dblink->ConstructHTMLDebugBlock() . '</body>', $template);
 
                print($template);
        }
index 632096709e0976f7c1a58dddce4dce9cb1699592..27dda14dbe778b3d448ad82218e97611bee9302d 160000 (submodule)
@@ -1 +1 @@
-Subproject commit 632096709e0976f7c1a58dddce4dce9cb1699592
+Subproject commit 27dda14dbe778b3d448ad82218e97611bee9302d
index 6167efe12e376b81d1b6a5d9fd47af1c41928e01..9d1b3e2b78ac87bc646a63f6257aba1422979ce4 100755 (executable)
@@ -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");