Merge branch 'MDL-37585' of git://github.com/timhunt/moodle
authorAparup Banerjee <aparup@moodle.com>
Tue, 22 Jan 2013 03:08:16 +0000 (11:08 +0800)
committerAparup Banerjee <aparup@moodle.com>
Tue, 22 Jan 2013 03:08:16 +0000 (11:08 +0800)
lib/dml/moodle_database.php

index 6ffbcbe..3dc9c55 100644 (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.