DBG extension!

This commit is contained in:
Robin Johnson
2003-02-02 08:17:00 +00:00
parent 85abb3393b
commit e001f70760
6 changed files with 197 additions and 3 deletions

View File

@@ -11,6 +11,13 @@ $Source$
gave their lives for the people of Earth. ---
* Documentation.html: Removed a bit of duplication in [7.4] and the
Developers section
* libraries/dbg: New directory for DBG code
* libraries/dbg/setup.php3:
- DBG initialization code, including module support
* libraries/dbg/profiling.php3: Profiling code
* lang/*: New strings added for DBG extension
* config.inc.php3: config options for DBG, off by default
* footer.inc.php3: DBG profiling output
2003-02-01 Michal Cihar <nijel@users.sourceforge.net>
* Documentati-on.*, translators.html, docs.css: New documentation layout.

View File

@@ -1400,6 +1400,36 @@ $cfg['PmaAbsoluteUri'] = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://'
<br /><br />
</dd>
<dt><b>$cfg['DBG']['enable']</b> boolean</dt>
<dd>
<b>DEVELOPERS ONLY!</b><br />
Enable the DBG extension for debugging phpMyAdmin. Required for profiling
the code.
<br />
For help in setting up your system to this, see the
<a href="#developersdbg">Developers</a> section.
</dd>
<dt><b>$cfg['DBG']['profile']['enable']</b> boolean</dt>
<dd>
<b>DEVELOPERS ONLY!</b><br />
Enable profiling support for phpMyAdmin. This will append a chunk of data
to the end of every page displayed in the main window with profiling
statistics for that page.<br />
You may need need to increase the maximum execution time for this to
complete successfully.
</dd>
<dt><b>$cfg['DBG']['profile']['threshold']</b> float (units in milliseconds)</dt>
<dd>
<b>DEVELOPERS ONLY!</b><br />
When profiling data is displayed, this variable controls the threshold of
display for any profiling data, based on the average time each time has
taken. If it is over the threshold it is displayed, otherwise it is not
displayed. This takes a value in milliseconds. In most cases you don't need
to edit this.
</dd>
<dt><b>$cfg['ColumnTypes'] </b>array</dt>
<dd>
All possible types of a MySQL column. In most cases you don't need to
@@ -2578,7 +2608,7 @@ $cfg['PmaAbsoluteUri'] = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://'
please try to keep your code as simple as possible: beginners are
using phpMyAdmin as an example application.<br />
As far as possible, we want the scripts to be XHTML1.0 and CSS2
compliant on one hand, they fit
compliant on one hand, they fit the
<a href="http://pear.php.net/" target="_blank">PEAR coding standards</a>
on the other hand. Please pay attention to this.
</li>
@@ -2594,6 +2624,17 @@ $cfg['PmaAbsoluteUri'] = (!empty($_SERVER['HTTPS']) ? 'https' : 'http') . '://'
<li>
If you want to be really helpful, write an entry for the ChangeLog.
</li>
<li id="developersdbg">
The DBG extension (<a href="http://dd.cron.ru/dbg/" target="_blank">PHP
Debugger DBG</a>) is now supported by phpMyAdmin for developers to
better debug and profile their code.<br />
Please see the <tt>$cfg['DBG']*</tt> configuration options for more
information.<br />
This is in memorium of the Space Shuttle Columbia (STS-107) which was
lost during its re-entry into Earth's atmosphere and in memory of the
brave men and women who gave their lives for the people of Earth.
</li>
</ul>
<!-- CREDITS -->

View File

@@ -417,6 +417,15 @@ $cfg['SQLValidator']['use'] = FALSE; // Make the SQL Validator available
$cfg['SQLValidator']['username'] = ''; // If you have a custom username, specify it here (defaults to anonymous)
$cfg['SQLValidator']['password'] = ''; // Password for username
/**
* Developers ONLY!
* To use the following, please install the DBG extension from http://dd.cron.ru/dbg/
*/
$cfg['DBG']['enable'] = FALSE; // Make the DBG stuff available
$cfg['DBG']['profile']['enable'] = FALSE; // Produce profiling results of PHP
$cfg['DBG']['profile']['threshold'] = 0.5; // Threshold of long running code to display
// Anything below the threshold is not displayed
/**
* MySQL settings

View File

@@ -21,11 +21,28 @@ if (isset($GLOBALS['userlink']) && $GLOBALS['userlink']) {
</html>
<?php
/**
* Generates profiling data if requested
*/
if (isset($GLOBALS['cfg']['DBG']['enable'])
&& $GLOBALS['cfg']['DBG']['enable']
&& isset($GLOBALS['cfg']['DBG']['profile']['enable'])
&& $GLOBALS['cfg']['DBG']['profile']['enable']) {
//run the basic setup code first
include('./libraries/dbg/setup.php3');
//if the setup ran fine, then do the profiling
if (isset($GLOBALS['DBG']) && $GLOBALS['DBG']) {
include('./libraries/dbg/profiling.php3');
dbg_dump_profiling_results();
}
}
/**
* Sends bufferized data
*/
if (isset($GLOBALS['cfg']['OBGzip']) && $GLOBALS['cfg']['OBGzip']
&& isset($GLOBALS['ob_mode']) && $GLOBALS['ob_mode']) {
PMA_outBufferPost($GLOBALS['ob_mode']);
&& isset($GLOBALS['ob_mode']) && $GLOBALS['ob_mode']) {
PMA_outBufferPost($GLOBALS['ob_mode']);
}
?>

View File

@@ -0,0 +1,89 @@
<?php
/* $Id$ */
// vim: expandtab sw=4 ts=4 sts=4:
if (!defined('PMA_DBG_PROFILING_INCLUDED')) {
define('PMA_DBG_PROFILING_INCLUDED', 1);
if (isset($GLOBALS['DBG']) && $GLOBALS['DBG']
&& isset($GLOBALS['cfg']['DBG']['profile']['enable'])
&& $GLOBALS['cfg']['DBG']['profile']['enable']) {
/**
* Displays profiling results when called
* WARNING: this function is SLOW
*/
function dbg_dump_profiling_results() {
/* Applies to the original 'dbg_dump_profiling_results' function,
* sourced from http://dd.cron.ru/dbg/download.php?h=prof_sample2
* Copyright (c) 2002. Dmitri Dmitrienko
* LICENCE: This source file is subject to Mozilla Public License (MPL)
* AUTHOR: Dmitri Dmitrienko <dd@cron.ru>
*/
dbg_get_profiler_results(&$dbg_prof_results);
echo '<br><table width="1000" cellspacing="0" cellpadding="2" style="font:8pt courier">' . "\n" .
'<thead>' . "\n" .
'<tr style="background:#808080; color:#FFFFFF">' . "\n" .
'<td>' . $GLOBALS['strDBGModule'] . '</td>' . "\n" .
'<td>' . $GLOBALS['strDBGLine'] . '</td>' . "\n" .
'<td>' . $GLOBALS['strDBGHits'] . '</td>' . "\n" .
'<td>' . $GLOBALS['strDBGTimePerHitMs'] . '</td>' . "\n" .
'<td>' . $GLOBALS['strDBGTotalTimeMs'] . '</td>' . "\n" .
'<td>' . $GLOBALS['strDBGMinTimeMs'] . '</td>' . "\n" .
'<td>' . $GLOBALS['strDBGMinTimeMs'] . '</td>' . "\n" .
'<td>' . $GLOBALS['strDBGContextID'] . '</td>' . "\n" .
'<td>' . $GLOBALS['strDBGContext'] . '</td>' . "\n" .
'</tr></thead>' . "\n" .
'<tbody style="vertical-align: top">' . "\n";
foreach ($dbg_prof_results['line_no'] as $idx => $line_no) {
$mod_no = $dbg_prof_results['mod_no'][$idx];
dbg_get_module_name($mod_no, &$mod_name);
//if (strpos("!".$mod_name, 'dbg.php') > 0) continue;
$hit_cnt = $dbg_prof_results['hit_count'][$idx];
$time_sum = $dbg_prof_results['tm_sum'][$idx] * 1000;
$time_avg_hit = $time_sum / $hit_cnt;
$time_min = $dbg_prof_results['tm_min'][$idx] * 1000;
$time_max = $dbg_prof_results['tm_max'][$idx] * 1000;
$time_sum = sprintf('%.3f', $time_sum);
$time_avg_hit = sprintf('%.3f', $time_avg_hit);
$time_min = sprintf('%.3f', $time_min);
$time_max = sprintf('%.3f', $time_max);
dbg_get_source_context($mod_no, $line_no, &$ctx_id);
//use a default context name if needed
if (dbg_get_context_name($ctx_id, &$ctx_name)
&& strcmp($ctx_name,'') == 0) {
$ctx_name = "::main";
}
$bk = "#ffffff";
if (($idx & 1) == 0)
$bk = "#e0e0e0";
if($time_avg_hit > $GLOBALS['cfg']['DBG']['profile']['threshold'] ) {
echo '<tr style="background:' . $bk . '">' .
'<td>' . $mod_name . '</td>' .
'<td>' . $line_no . '</td>' .
'<td>' . $hit_cnt . '</td>' .
'<td>' . $time_avg_hit . '</td>' .
'<td>' . $time_sum . '</td>' .
'<td>' . $time_min . '</td>' .
'<td>' . $time_max . '</td>' .
'<td>' . $ctx_id . '</td>' .
'<td>' . $ctx_name . '</td>' .
'</tr>' . "\n";
}
}
echo "</tbody></table>";
}
}
}
?>

31
libraries/dbg/setup.php3 Normal file
View File

@@ -0,0 +1,31 @@
<?php
if (!defined('PMA_DBG_SETUP_INCLUDED')) {
define('PMA_DBG_SETUP_INCLUDED', 1);
if (isset($GLOBALS['cfg']['DBG']['enable']) && $GLOBALS['cfg']['DBG']['enable']) {
/**
* Loads the DBG extension if needed
*/
if ( (PMA_PHP_INT_VERSION >= 40000 && !@ini_get('safe_mode') && @ini_get('enable_dl'))
&& @function_exists('dl')) {
$extension = 'dbg';
if (PMA_IS_WINDOWS) {
$suffix = '.dll';
} else {
$suffix = '.so';
}
if (!@extension_loaded($extension)) {
@dl($extension . $suffix);
}
if (!@extension_loaded($extension)) {
echo $strCantLoadDBG . '<br />' . "\n"
. '<a href="./Documentation.html#faqdbg" target="documentation">' . $GLOBALS['strDocu'] . '</a>' . "\n";
exit();
}
$GLOBALS['DBG'] = true;
} // end load mysql extension
}
}
?>