MDL-37585 Make $DB->set_debug(true) show run time of each query.

This commit is contained in:
Tim Hunt 2013-01-18 16:46:16 +00:00
parent a5ec499521
commit 74fa94b26a

View File

@ -408,6 +408,7 @@ abstract class moodle_database {
// free memory
$this->last_sql = null;
$this->last_params = null;
$this->print_debug_time();
return;
}
@ -415,7 +416,6 @@ abstract class moodle_database {
$type = $this->last_type;
$sql = $this->last_sql;
$params = $this->last_params;
$time = microtime(true) - $this->last_time;
$error = $this->get_last_error();
$this->query_log($error);
@ -520,6 +520,25 @@ abstract class moodle_database {
}
}
/**
* Prints the time a query took to run.
* @return void
*/
protected function print_debug_time() {
if (!$this->get_debug()) {
return;
}
$time = microtime(true) - $this->last_time;
$message = "Query took: {$time} seconds.\n";
if (CLI_SCRIPT) {
echo $message;
echo "--------------------------------\n";
} else {
echo s($message);
echo "<hr />\n";
}
}
/**
* Returns the SQL WHERE conditions.
* @param string $table The table name that these conditions will be validated against.