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 ''; for ($i=$start; $i<$end; $i++ ) { $key = $i; $query = self::$queries[$key]; echo ''; } echo '
Time File Line SQL
' . $query['time'] . ' ' . $query['file'] . ' ' . $query['line'] . ' ' . $query['sql'] . '
'; } static function display_errors() { if ( !self::$_is_error ) return null; echo ''; $show = array('error', 'warning'); foreach (self::$checkpoints as $c) { if ( !in_array($c['type'], $show) ) continue; echo ''; echo ''; } echo '
Name Info
' . $c['code'].'::'.$c['name'] . '
'. $c['msg'] . '
'; } static function display() { if ( !self::isActive() ) { return false; } $previous = array(); $cummulative = array(); $first = true; ob_start(); switch ( self::$debug_level ) { case 0 : //show only exceptions //shown in Abc_Exception::displayError break; case 1 : //show errors and warnings self::display_errors(); break; case 2 : // #1 + mysql site load, php file execution time and page elements load time self::display_errors(); //count php execution time foreach (self::$checkpoints as $name => $c) { if ( $c['type'] != 'checkpoint' ) continue; if ($first == true) { $first = false; $cummulative = $c; } $time = sprintf("%01.4f", $c['time'] - $cummulative['time']); } echo '
'; echo 'Queries - '. count(self::$queries). '
'; echo 'Queries execution time - '. sprintf('%01.5f', self::$queries_time). '
'; echo 'PHP Execution time - '. $time. '
'; echo '
'; break; case 3 : case 4 : case 5 : // #2 + basic logs and stack of execution // #3 + dump mysql statements // #4 + call stack echo ''; foreach (self::$checkpoints as $c) { echo ''; echo ''; } echo '
Name Info
' . $c['name'] . '
'; 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 '
'; break; default: } $debug = ob_get_clean(); switch ( self::$debug ) { case 1: //show echo $debug; break; case 2: //log require_once(DIR_CORE . 'lib/log.php'); $registry = Registry::getInstance(); if ( $registry->has('log') ) { $log = $registry->get('log'); } else { $log = new ALog('error.txt'); } $log->write( strip_tags(str_replace('
', "\r\n", $debug))); break; default: } } }