Gazelle/classes/debug.class.php

634 lines
18 KiB
PHP
Raw Normal View History

2011-03-28 14:21:28 +00:00
<?
// Debug info for developers
2012-08-03 08:00:17 +00:00
ini_set('max_execution_time',600);
2011-03-28 14:21:28 +00:00
define('MAX_TIME', 20000); //Maximum execution time in ms
define('MAX_ERRORS', 0); //Maxmimum errors, warnings, notices we will allow in a page
2013-05-28 08:01:02 +00:00
define('MAX_MEMORY', 80 * 1024 * 1024); //Maximum memory used per pageload
2011-03-28 14:21:28 +00:00
define('MAX_QUERIES', 30); //Maxmimum queries
class DEBUG {
public $Errors = array();
public $Flags = array();
2012-10-30 08:00:18 +00:00
public $Perf = array();
2011-10-29 08:00:15 +00:00
private $LoggedVars = array();
2013-05-28 08:01:02 +00:00
public function profile($Automatic = '') {
2013-08-28 23:08:41 +00:00
global $ScriptStartTime;
2011-03-28 14:21:28 +00:00
$Reason = array();
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
if (!empty($Automatic)) {
$Reason[] = $Automatic;
}
2011-10-29 08:00:15 +00:00
2013-05-28 08:01:02 +00:00
$Micro = (microtime(true) - $ScriptStartTime) * 1000;
2011-10-29 08:00:15 +00:00
if ($Micro > MAX_TIME && !defined('TIME_EXCEPTION')) {
2011-03-28 14:21:28 +00:00
$Reason[] = number_format($Micro, 3).' ms';
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
$Errors = count($this->get_errors());
2011-10-29 08:00:15 +00:00
if ($Errors > MAX_ERRORS && !defined('ERROR_EXCEPTION')) {
2013-05-28 08:01:02 +00:00
$Reason[] = $Errors.' PHP errors';
2011-03-28 14:21:28 +00:00
}
/*
$Queries = count($this->get_queries());
2011-10-29 08:00:15 +00:00
if ($Queries > MAX_QUERIES && !defined('QUERY_EXCEPTION')) {
2011-03-28 14:21:28 +00:00
$Reason[] = $Queries.' Queries';
}
*/
$Ram = memory_get_usage(true);
if ($Ram > MAX_MEMORY && !defined('MEMORY_EXCEPTION')) {
2013-05-28 08:01:02 +00:00
$Reason[] = Format::get_size($Ram).' RAM used';
2011-03-28 14:21:28 +00:00
}
2011-10-29 08:00:15 +00:00
2013-08-28 23:08:41 +00:00
G::$DB->warnings(); // see comment in MYSQL::query
2013-07-17 08:00:52 +00:00
/*$Queries = $this->get_queries();
2013-07-02 08:01:37 +00:00
$DBWarningCount = 0;
foreach ($Queries as $Query) {
if (!empty($Query[2])) {
$DBWarningCount += count($Query[2]);
}
}
if ($DBWarningCount) {
$Reason[] = $DBWarningCount . ' DB warning(s)';
2013-07-17 08:00:52 +00:00
}*/
2013-07-02 08:01:37 +00:00
2013-10-06 08:01:04 +00:00
$CacheStatus = G::$Cache->server_status();
if (in_array(0, $CacheStatus) && !G::$Cache->get_value('cache_fail_reported')) {
// Limit to max one report every 15 minutes to avoid massive debug spam
G::$Cache->cache_value('cache_fail_reported', true, 900);
$Reason[] = "Cache server error";
}
2011-03-28 14:21:28 +00:00
if (isset($_REQUEST['profile'])) {
2013-08-28 23:08:41 +00:00
$Reason[] = 'Requested by ' . G::$LoggedUser['Username'];
2011-03-28 14:21:28 +00:00
}
2011-10-29 08:00:15 +00:00
2013-05-28 08:01:02 +00:00
$this->Perf['Memory usage'] = (($Ram>>10) / 1024).' MB';
2012-11-03 08:00:19 +00:00
$this->Perf['Page process time'] = number_format($Micro / 1000, 3).' s';
$this->Perf['CPU time'] = number_format($this->get_cpu_time() / 1000000, 3).' s';
2012-10-30 08:00:18 +00:00
2011-03-28 14:21:28 +00:00
if (isset($Reason[0])) {
2013-10-06 08:01:04 +00:00
$this->log_var($CacheStatus, 'Cache server status');
2011-03-28 14:21:28 +00:00
$this->analysis(implode(', ', $Reason));
return true;
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
return false;
}
2011-10-29 08:00:15 +00:00
2013-05-28 08:01:02 +00:00
public function analysis($Message, $Report = '', $Time = 43200) {
2013-08-28 23:08:41 +00:00
global $Document;
2011-03-28 14:21:28 +00:00
if (empty($Report)) {
$Report = $Message;
}
2012-10-11 08:00:15 +00:00
$Identifier = Users::make_secret(5);
2013-08-28 23:08:41 +00:00
G::$Cache->cache_value(
2011-10-29 08:00:15 +00:00
'analysis_'.$Identifier,
2011-03-28 14:21:28 +00:00
array(
'url' => $_SERVER['REQUEST_URI'],
'message' => $Report,
'errors' => $this->get_errors(true),
'queries' => $this->get_queries(),
'flags' => $this->get_flags(),
'includes' => $this->get_includes(),
2011-10-29 08:00:15 +00:00
'cache' => $this->get_cache_keys(),
2012-10-30 08:00:18 +00:00
'vars' => $this->get_logged_vars(),
'perf' => $this->get_perf()
2011-03-28 14:21:28 +00:00
),
$Time
);
2013-05-28 08:01:02 +00:00
send_irc('PRIVMSG '.LAB_CHAN." :{$Message} $Document https://".SSL_SITE_URL.'/tools.php?action=analysis&case='.$Identifier.' https://'.SSL_SITE_URL.$_SERVER['REQUEST_URI']);
2011-03-28 14:21:28 +00:00
}
2011-10-29 08:00:15 +00:00
2012-11-03 08:00:19 +00:00
public function get_cpu_time() {
if (!defined('PHP_WINDOWS_VERSION_MAJOR')) {
global $CPUTimeStart;
$RUsage = getrusage();
2013-05-28 08:01:02 +00:00
$CPUTime = $RUsage['ru_utime.tv_sec'] * 1000000 + $RUsage['ru_utime.tv_usec'] - $CPUTimeStart;
2012-11-03 08:00:19 +00:00
return $CPUTime;
}
return false;
}
2013-04-13 08:00:19 +00:00
public function log_var($Var, $VarName = false) {
2011-10-29 08:00:15 +00:00
$BackTrace = debug_backtrace();
2013-07-24 08:00:46 +00:00
$ID = Users::make_secret(5);
2013-04-13 08:00:19 +00:00
if (!$VarName) {
2011-10-29 08:00:15 +00:00
$VarName = $ID;
}
$File = array('path' => substr($BackTrace[0]['file'], strlen(SERVER_ROOT)), 'line' => $BackTrace[0]['line']);
$this->LoggedVars[$ID] = array($VarName => array('bt' => $File, 'data' => $Var));
}
2011-03-28 14:21:28 +00:00
public function set_flag($Event) {
global $ScriptStartTime;
2013-04-13 08:00:19 +00:00
$this->Flags[] = array($Event, (microtime(true) - $ScriptStartTime) * 1000, memory_get_usage(true), $this->get_cpu_time());
2011-03-28 14:21:28 +00:00
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
//This isn't in the constructor because $this is not available, and the function cannot be made static
public function handle_errors() {
//error_reporting(E_ALL ^ E_STRICT | E_WARNING | E_DEPRECATED | E_ERROR | E_PARSE); //E_STRICT disabled
error_reporting(E_WARNING | E_ERROR | E_PARSE);
set_error_handler(array($this, 'php_error_handler'));
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
protected function format_args($Array) {
$LastKey = -1;
$Return = array();
foreach ($Array as $Key => $Val) {
$Return[$Key] = '';
2013-04-13 08:00:19 +00:00
if (!is_int($Key) || $Key != $LastKey + 1) {
2011-03-28 14:21:28 +00:00
$Return[$Key] .= "'$Key' => ";
}
if ($Val === true) {
2013-05-28 08:01:02 +00:00
$Return[$Key] .= 'true';
2011-03-28 14:21:28 +00:00
} elseif ($Val === false) {
2013-05-28 08:01:02 +00:00
$Return[$Key] .= 'false';
2011-03-28 14:21:28 +00:00
} elseif (is_string($Val)) {
$Return[$Key] .= "'$Val'";
} elseif (is_int($Val)) {
$Return[$Key] .= $Val;
} elseif (is_object($Val)) {
$Return[$Key] .= get_class($Val);
} elseif (is_array($Val)) {
$Return[$Key] .= 'array('.$this->format_args($Val).')';
}
$LastKey = $Key;
}
return implode(', ', $Return);
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
public function php_error_handler($Level, $Error, $File, $Line) {
//Who added this, it's still something to pay attention to...
if (stripos('Undefined index', $Error) !== false) {
//return true;
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
$Steps = 1; //Steps to go up in backtrace, default one
$Call = '';
$Args = '';
$Tracer = debug_backtrace();
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
//This is in case something in this function goes wrong and we get stuck with an infinite loop
if (isset($Tracer[$Steps]['function'], $Tracer[$Steps]['class']) && $Tracer[$Steps]['function'] == 'php_error_handler' && $Tracer[$Steps]['class'] == 'DEBUG') {
return true;
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
//If this error was thrown, we return the function which threw it
if (isset($Tracer[$Steps]['function']) && $Tracer[$Steps]['function'] == 'trigger_error') {
$Steps++;
$File = $Tracer[$Steps]['file'];
$Line = $Tracer[$Steps]['line'];
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
//At this time ONLY Array strict typing is fully supported.
//Allow us to abuse strict typing (IE: function test(Array))
if (preg_match('/^Argument (\d+) passed to \S+ must be an (array), (array|string|integer|double|object) given, called in (\S+) on line (\d+) and defined$/', $Error, $Matches)) {
$Error = 'Type hinting failed on arg '.$Matches[1]. ', expected '.$Matches[2].' but found '.$Matches[3];
$File = $Matches[4];
$Line = $Matches[5];
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
//Lets not be repetative
if (($Tracer[$Steps]['function'] == 'include' || $Tracer[$Steps]['function'] == 'require' ) && isset($Tracer[$Steps]['args'][0]) && $Tracer[$Steps]['args'][0] == $File) {
unset($Tracer[$Steps]['args']);
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
//Class
if (isset($Tracer[$Steps]['class'])) {
$Call .= $Tracer[$Steps]['class'].'::';
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
//Function & args
if (isset($Tracer[$Steps]['function'])) {
$Call .= $Tracer[$Steps]['function'];
if (isset($Tracer[$Steps]['args'][0])) {
$Args = $this->format_args($Tracer[$Steps]['args']);
}
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
//Shorten the path & we're done
$File = str_replace(SERVER_ROOT, '', $File);
$Error = str_replace(SERVER_ROOT, '', $Error);
2013-09-09 08:00:52 +00:00
if (DEBUG_WARNINGS) {
2011-03-28 14:21:28 +00:00
$this->Errors[] = array($Error, $File.':'.$Line, $Call, $Args);
}
return true;
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
/* Data wrappers */
2011-10-29 08:00:15 +00:00
2012-10-30 08:00:18 +00:00
public function get_perf() {
2012-11-02 08:00:18 +00:00
if (empty($this->Perf)) {
global $ScriptStartTime;
$PageTime = (microtime(true) - $ScriptStartTime);
2012-11-03 08:00:19 +00:00
$CPUTime = $this->get_cpu_time();
$Perf = array(
'Memory usage' => Format::get_size(memory_get_usage(true)),
'Page process time' => number_format($PageTime, 3).' s');
if ($CPUTime) {
$Perf['CPU time'] = number_format($CPUTime / 1000000, 3).' s';
2012-11-02 08:00:18 +00:00
}
return $Perf;
}
2012-10-30 08:00:18 +00:00
return $this->Perf;
}
2011-03-28 14:21:28 +00:00
public function get_flags() {
return $this->Flags;
}
2011-10-29 08:00:15 +00:00
2013-05-28 08:01:02 +00:00
public function get_errors($Light = false) {
2011-03-28 14:21:28 +00:00
//Because the cache can't take some of these variables
if ($Light) {
foreach ($this->Errors as $Key => $Value) {
$this->Errors[$Key][3] = '';
}
}
return $this->Errors;
}
public function get_constants() {
return get_defined_constants(true);
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
public function get_classes() {
foreach (get_declared_classes() as $Class) {
$Classes[$Class]['Vars'] = get_class_vars($Class);
$Classes[$Class]['Functions'] = get_class_methods($Class);
}
return $Classes;
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
public function get_extensions() {
foreach (get_loaded_extensions() as $Extension) {
$Extensions[$Extension]['Functions'] = get_extension_funcs($Extension);
}
return $Extensions;
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
public function get_includes() {
return get_included_files();
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
public function get_cache_time() {
2013-08-28 23:08:41 +00:00
return G::$Cache->Time;
2011-03-28 14:21:28 +00:00
}
public function get_cache_keys() {
2013-08-28 23:08:41 +00:00
return array_keys(G::$Cache->CacheHits);
2011-03-28 14:21:28 +00:00
}
2011-10-29 08:00:15 +00:00
2012-08-30 08:00:17 +00:00
public function get_sphinxql_queries() {
2013-04-13 08:00:19 +00:00
if (class_exists('Sphinxql')) {
2013-03-17 08:00:17 +00:00
return Sphinxql::$Queries;
2012-08-30 08:00:17 +00:00
}
}
public function get_sphinxql_time() {
2013-04-13 08:00:19 +00:00
if (class_exists('Sphinxql')) {
2013-03-17 08:00:17 +00:00
return Sphinxql::$Time;
2012-08-30 08:00:17 +00:00
}
}
2011-03-28 14:21:28 +00:00
public function get_queries() {
2013-08-28 23:08:41 +00:00
return G::$DB->Queries;
2011-03-28 14:21:28 +00:00
}
2011-10-29 08:00:15 +00:00
2011-03-28 14:21:28 +00:00
public function get_query_time() {
2013-08-28 23:08:41 +00:00
return G::$DB->Time;
2011-03-28 14:21:28 +00:00
}
2011-10-29 08:00:15 +00:00
public function get_logged_vars() {
return $this->LoggedVars;
}
2011-03-28 14:21:28 +00:00
/* Output Formatting */
2013-05-28 08:01:02 +00:00
public function perf_table($Perf = false) {
2012-10-30 08:00:18 +00:00
if (!is_array($Perf)) {
$Perf = $this->get_perf();
}
if (empty($Perf)) {
return;
}
?>
<table class="layout" width="100%">
<tr>
2013-11-03 08:00:58 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_perf').gtoggle(); return false;" class="brackets">View</a> Performance Statistics:</strong></td>
2012-10-30 08:00:18 +00:00
</tr>
</table>
<table id="debug_perf" class="debug_table hidden" width="100%">
<?
foreach ($Perf as $Stat => $Value) {
?>
<tr valign="top">
<td class="debug_perf_stat"><?=$Stat?></td>
<td class="debug_perf_data"><?=$Value?></td>
</tr>
<?
}
?>
</table>
<?
}
2013-05-28 08:01:02 +00:00
public function include_table($Includes = false) {
2011-03-28 14:21:28 +00:00
if (!is_array($Includes)) {
$Includes = $this->get_includes();
}
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_include').gtoggle(); return false;" class="brackets">View</a> <?=number_format(count($Includes))?> Includes:</strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_include" class="debug_table hidden" width="100%">
2011-03-28 14:21:28 +00:00
<?
foreach ($Includes as $File) {
?>
<tr valign="top">
<td><?=$File?></td>
</tr>
<?
}
?>
</table>
2011-10-29 08:00:15 +00:00
<?
2011-03-28 14:21:28 +00:00
}
2013-05-28 08:01:02 +00:00
public function class_table($Classes = false) {
2011-03-28 14:21:28 +00:00
if (!is_array($Classes)) {
$Classes = $this->get_classes();
}
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_classes').gtoggle(); return false;" class="brackets">View</a> Classes:</strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_classes" class="debug_table hidden" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
<td align="left">
2013-10-08 08:00:52 +00:00
<pre>
<? print_r($Classes); echo "\n"; ?>
</pre>
2011-03-28 14:21:28 +00:00
</td>
</tr>
</table>
<?
}
public function extension_table() {
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_extensions').gtoggle(); return false;" class="brackets">View</a> Extensions:</strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_extensions" class="debug_table hidden" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
<td align="left">
2013-10-08 08:00:52 +00:00
<pre>
<? print_r($this->get_extensions()); echo "\n"; ?>
</pre>
2011-03-28 14:21:28 +00:00
</td>
</tr>
</table>
<?
}
2013-05-28 08:01:02 +00:00
public function flag_table($Flags = false) {
2011-03-28 14:21:28 +00:00
if (!is_array($Flags)) {
$Flags = $this->get_flags();
}
if (empty($Flags)) {
return;
}
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_flags').gtoggle(); return false;" class="brackets">View</a> Flags:</strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_flags" class="debug_table hidden" width="100%">
2012-11-03 08:00:19 +00:00
<tr valign="top">
<td align="left" class="debug_flags_event"><strong>Event</strong></td>
<td align="left" class="debug_flags_time"><strong>Page time</strong></td>
<? if ($Flags[0][3] !== false) { ?>
<td align="left" class="debug_flags_time"><strong>CPU time</strong></td>
<? } ?>
<td align="left" class="debug_flags_memory"><strong>Memory</strong></td>
</tr>
2011-03-28 14:21:28 +00:00
<?
foreach ($Flags as $Flag) {
2012-11-03 08:00:19 +00:00
list($Event, $MicroTime, $Memory, $CPUTime) = $Flag;
2011-03-28 14:21:28 +00:00
?>
<tr valign="top">
<td align="left"><?=$Event?></td>
2012-11-03 08:00:19 +00:00
<td align="left"><?=number_format($MicroTime, 3)?> ms</td>
<? if ($CPUTime !== false) { ?>
<td align="left"><?=number_format($CPUTime / 1000, 3)?> ms</td>
<? } ?>
2012-10-11 08:00:15 +00:00
<td align="left"><?=Format::get_size($Memory)?></td>
2011-03-28 14:21:28 +00:00
</tr>
2013-10-08 08:00:52 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</table>
<?
}
2013-05-28 08:01:02 +00:00
public function constant_table($Constants = false) {
2011-03-28 14:21:28 +00:00
if (!is_array($Constants)) {
$Constants = $this->get_constants();
}
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_constants').gtoggle(); return false;" class="brackets">View</a> Constants:</strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_constants" class="debug_table hidden" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2011-10-29 08:00:15 +00:00
<td align="left" class="debug_data debug_constants_data">
2013-10-08 08:00:52 +00:00
<pre>
2013-10-09 08:01:03 +00:00
<?= display_str(print_r($Constants, true))?>
2013-10-08 08:00:52 +00:00
</pre>
2011-03-28 14:21:28 +00:00
</td>
</tr>
</table>
<?
}
2013-05-28 08:01:02 +00:00
public function cache_table($CacheKeys = false) {
2013-11-03 08:00:58 +00:00
$Header = 'Cache Keys';
if (!is_array($CacheKeys)) {
$CacheKeys = $this->get_cache_keys();
2011-03-28 14:21:28 +00:00
$Header .= ' ('.number_format($this->get_cache_time(), 5).' ms)';
}
if (empty($CacheKeys)) {
2011-03-28 14:21:28 +00:00
return;
}
2013-05-28 08:01:02 +00:00
$Header = ' '.number_format(count($CacheKeys))." $Header:";
2011-03-28 14:21:28 +00:00
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_cache').gtoggle(); return false;" class="brackets">View</a><?=$Header?></strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_cache" class="debug_table hidden" width="100%">
2013-04-13 08:00:19 +00:00
<? foreach ($CacheKeys as $Key) { ?>
2011-03-28 14:21:28 +00:00
<tr>
2013-11-03 08:00:58 +00:00
<td class="label nobr debug_info debug_cache_key">
2013-06-17 08:01:02 +00:00
<a href="#" onclick="$('#debug_cache_<?=$Key?>').gtoggle(); return false;"><?=display_str($Key)?></a>
2013-11-03 08:00:58 +00:00
<a href="tools.php?action=clear_cache&amp;key=<?=$Key?>&amp;type=clear" target="_blank" class="brackets tooltip" title="Clear this cache key">Clear</a>
2011-03-28 14:21:28 +00:00
</td>
2011-10-29 08:00:15 +00:00
<td align="left" class="debug_data debug_cache_data">
2013-10-08 08:00:52 +00:00
<pre id="debug_cache_<?=$Key?>" class="hidden">
2013-10-09 08:01:03 +00:00
<?= display_str(print_r(G::$Cache->get_value($Key, true), true))?>
2013-10-08 08:00:52 +00:00
</pre>
2011-03-28 14:21:28 +00:00
</td>
</tr>
<? } ?>
</table>
<?
}
2013-05-28 08:01:02 +00:00
public function error_table($Errors = false) {
2011-03-28 14:21:28 +00:00
if (!is_array($Errors)) {
$Errors = $this->get_errors();
}
if (empty($Errors)) {
return;
}
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_error').gtoggle(); return false;" class="brackets">View</a> <?=number_format(count($Errors))?> Errors:</strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_error" class="debug_table hidden" width="100%">
2011-03-28 14:21:28 +00:00
<?
foreach ($Errors as $Error) {
2013-05-28 08:01:02 +00:00
list($Error, $Location, $Call, $Args) = $Error;
2011-03-28 14:21:28 +00:00
?>
<tr valign="top">
2012-11-03 08:00:19 +00:00
<td align="left" class="debug_info debug_error_call">
<?=display_str($Call)?>(<?=display_str($Args)?>)
</td>
<td class="debug_data debug_error_data" align="left">
<?=display_str($Error)?>
</td>
<td align="left">
<?=display_str($Location)?>
</td>
2011-03-28 14:21:28 +00:00
</tr>
2013-10-08 08:00:52 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</table>
2011-10-29 08:00:15 +00:00
<?
2011-03-28 14:21:28 +00:00
}
public function query_table($Queries=false) {
$Header = 'Queries';
if (!is_array($Queries)) {
$Queries = $this->get_queries();
$Header .= ' ('.number_format($this->get_query_time(), 5).' ms)';
}
if (empty($Queries)) {
return;
}
2013-05-28 08:01:02 +00:00
$Header = ' '.number_format(count($Queries))." $Header:";
2011-03-28 14:21:28 +00:00
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_database').gtoggle(); return false;" class="brackets">View</a><?=$Header?></strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_database" class="debug_table hidden" width="100%">
2011-03-28 14:21:28 +00:00
<?
foreach ($Queries as $Query) {
2013-07-02 08:01:37 +00:00
list($SQL, $Time, $Warnings) = $Query;
2013-10-06 08:01:04 +00:00
if ($Warnings !== null) {
$Warnings = implode('<br />', $Warnings);
}
2011-03-28 14:21:28 +00:00
?>
<tr valign="top">
2013-10-11 08:01:04 +00:00
<td class="debug_data debug_query_data"><div><?=str_replace("\t", '&nbsp;&nbsp;', nl2br(display_str(trim($SQL))))?></div></td>
2013-04-13 08:00:19 +00:00
<td class="rowa debug_info debug_query_time" style="width: 130px;" align="left"><?=number_format($Time, 5)?> ms</td>
2013-07-02 08:01:37 +00:00
<td class="rowa debug_info debug_query_warnings"><?=$Warnings?></td>
2011-03-28 14:21:28 +00:00
</tr>
2013-10-08 08:00:52 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</table>
2011-10-29 08:00:15 +00:00
<?
2011-03-28 14:21:28 +00:00
}
2013-05-28 08:01:02 +00:00
public function sphinx_table($Queries = false) {
2011-03-28 14:21:28 +00:00
$Header = 'Searches';
if (!is_array($Queries)) {
2013-09-13 08:00:53 +00:00
$Queries = $this->get_sphinxql_queries();
$Header .= ' ('.number_format($this->get_sphinxql_time(), 5).' ms)';
2011-03-28 14:21:28 +00:00
}
if (empty($Queries)) {
return;
}
2013-05-28 08:01:02 +00:00
$Header = ' '.number_format(count($Queries))." $Header:";
2011-03-28 14:21:28 +00:00
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-03-28 14:21:28 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_sphinx').gtoggle(); return false;" class="brackets">View</a><?=$Header?></strong></td>
2011-03-28 14:21:28 +00:00
</tr>
</table>
2011-10-29 08:00:15 +00:00
<table id="debug_sphinx" class="debug_table hidden" width="100%">
2011-03-28 14:21:28 +00:00
<?
foreach ($Queries as $Query) {
2013-05-28 08:01:02 +00:00
list($Params, $Time) = $Query;
2011-03-28 14:21:28 +00:00
?>
<tr valign="top">
2012-08-30 08:00:17 +00:00
<td class="debug_data debug_sphinx_data"><pre><?=str_replace("\t", ' ', $Params)?></pre></td>
2013-04-13 08:00:19 +00:00
<td class="rowa debug_info debug_sphinx_time" style="width: 130px;" align="left"><?=number_format($Time, 5)?> ms</td>
2011-03-28 14:21:28 +00:00
</tr>
2013-10-08 08:00:52 +00:00
<? } ?>
2011-03-28 14:21:28 +00:00
</table>
2011-10-29 08:00:15 +00:00
<?
}
2013-05-28 08:01:02 +00:00
public function vars_table($Vars = false) {
2011-10-29 08:00:15 +00:00
$Header = 'Logged Variables';
if (empty($Vars)) {
2013-04-13 08:00:19 +00:00
if (empty($this->LoggedVars)) {
2011-10-29 08:00:15 +00:00
return;
}
$Vars = $this->LoggedVars;
}
2013-05-28 08:01:02 +00:00
$Header = ' '.number_format(count($Vars))." $Header:";
2011-10-29 08:00:15 +00:00
?>
2012-09-01 08:00:24 +00:00
<table class="layout" width="100%">
2011-10-29 08:00:15 +00:00
<tr>
2013-10-06 08:01:04 +00:00
<td align="left"><strong><a href="#" onclick="$(this).parents('.layout').next('#debug_loggedvars').gtoggle(); return false;" class="brackets">View</a><?=$Header?></strong></td>
2011-10-29 08:00:15 +00:00
</tr>
</table>
<table id="debug_loggedvars" class="debug_table hidden" width="100%">
<?
2013-04-13 08:00:19 +00:00
foreach ($Vars as $ID => $Var) {
2011-10-29 08:00:15 +00:00
list($Key, $Data) = each($Var);
$Size = count($Data['data']);
?>
<tr>
2012-11-03 08:00:19 +00:00
<td align="left" class="debug_info debug_loggedvars_name">
2013-06-17 08:01:02 +00:00
<a href="#" onclick="$('#debug_loggedvars_<?=$ID?>').gtoggle(); return false;"><?=display_str($Key)?></a> (<?=$Size . ($Size == 1 ? ' element' : ' elements')?>)
2011-10-29 08:00:15 +00:00
<div><?=$Data['bt']['path'].':'.$Data['bt']['line'];?></div>
</td>
<td class="debug_data debug_loggedvars_data" align="left">
2013-10-08 08:00:52 +00:00
<pre id="debug_loggedvars_<?=$ID?>" class="hidden">
2013-10-09 08:01:03 +00:00
<?= display_str(print_r($Data['data'], true))?>
2013-10-08 08:00:52 +00:00
</pre>
2011-10-29 08:00:15 +00:00
</td>
</tr>
<? } ?>
</table>
<?
2011-03-28 14:21:28 +00:00
}
}