UPGRADE NOTE: Do not edit or add to this file if you wish to upgrade AbanteCart to newer versions in the future. If you wish to customize AbanteCart for your needs please refer to http://www.AbanteCart.com for more information. ------------------------------------------------------------------------------*/ if (! defined ( 'DIR_CORE' )) { header ( 'Location: static_pages/' ); } class ADebug { static public $checkpoints = array(); static public $queries = array(); static public $queries_time = 0; static private $debug = 0; //off static private $debug_level = 0; //only exceptions static private $_is_init = false; //class init static private $_is_error = false; static private function isActive() { if ( !self::$_is_init ) { if ( defined('INSTALL') ) { self::$debug = 1; self::$debug_level = 1; } else if (class_exists('Registry') ) { $registry = Registry::getInstance(); if ( $registry->has('config') ) { if ( $registry->get('config')->has('config_debug') ) self::$debug = $registry->get('config')->get('config_debug'); if ( $registry->get('config')->has('config_debug_level') ) self::$debug_level = $registry->get('config')->get('config_debug_level'); } } self::$_is_init = true; } return self::$debug; } static function set_query($query, $time , $backtrace) { if ( !self::isActive() ) { return false; } self::$queries[] = array( 'sql' => $query, 'time' => sprintf('%01.5f', $time), 'file' => $backtrace['file'], 'line' => $backtrace['line'] ); self::$queries_time += $time; } static function checkpoint($name) { if ( !self::isActive() ) { return false; } $e = new Exception(); self::$checkpoints[] = array( 'name' => $name, 'time' => self::microtime(), 'memory' => memory_get_usage(), 'included_files' => count(get_included_files()), 'queries' => count(self::$queries), 'type' => 'checkpoint', 'trace' => $e->getTraceAsString(), ); } static function variable($name, $variable) { if ( !self::isActive() ) { return false; } ob_start(); echo '
'; print_r($variable); echo ''; $msg = ob_get_clean(); self::$checkpoints[] = array( 'name' => $name, 'msg' => $msg, 'type' => 'variable', ); } static function error($name, $code, $msg) { self::$checkpoints[] = array( 'name' => $name, 'time' => self::microtime(), 'memory' => memory_get_usage(), 'included_files' => count(get_included_files()), 'queries' => count(self::$queries), 'msg' => $msg, 'code' => $code, 'type' => 'error', ); self::$_is_error = true; } static function warning($name, $code, $msg) { self::$checkpoints[] = array( 'name' => $name, 'time' => self::microtime(), 'memory' => memory_get_usage(), 'included_files' => count(get_included_files()), 'queries' => count(self::$queries), 'msg' => $msg, 'code' => $code, 'type' => 'warning', ); self::$_is_error = true; } static function microtime() { list($usec, $sec) = explode(' ', microtime()); return ((float)$usec + (float)$sec); } static function display_queries( $start, $end ) { if ( $end - $start <= 0 ) return null; echo '
Time | File | Line | SQL |
' . $query['time'] . ' | ' . $query['file'] . ' | ' . $query['line'] . ' | ' . $query['sql'] . ' |
Name | Info |
' . $c['code'].'::'.$c['name'] . ' | ';
echo ''. $c['msg'] . ' | ';
}
echo '
Name | Info |
' . $c['name'] . ' | ';
echo '';
if ( $first == true && $c['type'] != 'variable' ) {
$previous = array(
'time' => $c['time'],
'memory' => 0,
'included_files' => 0,
'queries' => 0,
);
$first = false;
$cummulative = $c;
}
switch ($c['type'] ) {
case 'variable':
echo $c['msg'].' '; break; case 'error': case 'warning': echo $c['msg'].' '; case 'checkpoint': echo '- Memory: ' . (number_format($c['memory'] - $previous['memory'])) . ' (' . number_format($c['memory']) . ')' . ' '; echo '- Files: ' . ($c['included_files'] - $previous['included_files']) . ' (' . $c['included_files'] . ')' . ' '; echo '- Queries: ' . ($c['queries'] - $previous['queries']) . ' (' . $c['queries'] . ')' . ' '; echo '- Time: ' . sprintf("%01.4f", $c['time'] - $previous['time']) . ' (' . sprintf("%01.4f", $c['time'] - $cummulative['time']) . ')' . ' '; if ( self::$debug_level > 3 ) { self::display_queries( $previous['queries'], $c['queries'] ); } if ( self::$debug_level > 4 ) { echo ' '.$c['trace'].''; } $previous = $c; break; } echo ' |