I noticed that there's no solution for debugging execution time, memory and sql queries in OpenCart.
This is how you can add this useful(especially for developers) feature:
1. Extract attached archive in /system/helper/ directory.
2. Open index.php file(located in root directory).
3. Add the following block at the beginning of the file:
Code: Select all
// debug hack start
define('DEBUG', true); // comment to disable debug mode
define('SQL_DEBUG', true); // comment to disable sql-debugging
if(defined('DEBUG')) {
$start_time = microtime();
$start_mem = memory_get_usage();
}
// debug hack endd
Code: Select all
// debug hack start
if(defined('SQL_DEBUG'))
require_once(DIR_SYSTEM . 'helper/debug.php');
// debug hack end
Code: Select all
// debug hack start
if(defined('DEBUG')) {
$end_time = (microtime() - $start_time);
$end_mem = (memory_get_usage() - $start_mem);
echo '<style>#debug tr:hover {background:#FFC}</style><table id="debug" border="1" width="100%">';
echo '<tr><td colspan="3">Memory Usage: '.round((($end_mem / 1024) / 1024), 6).' MB</td></tr>';
echo '<tr><td colspan="3">Execution Time: '.abs(round($end_time, 6)).' seconds</td></tr>';
if(defined('SQL_DEBUG'))
Debug::output();
echo '</table>';
}
// debug hack end
Code: Select all
public function query($sql) {
Code: Select all
if(defined('SQL_DEBUG')) { $caller = debug_backtrace(); Debug::trigger('sql', $sql, $caller); }
In SQL queries debugger you will see 3-column table where:
#1 is query number
#2 is query itself
#3 file and the line in the brackets, where query() method was called; Class name :: method(), which called query()
Hope the debug feature will be added by default in future versions.