diff --git a/core/database.class.php b/core/database.class.php index fd9bade2..da68d598 100644 --- a/core/database.class.php +++ b/core/database.class.php @@ -384,6 +384,7 @@ class Database { * @var null|PDO */ private $db = null; + public $dbtime = 0.0; /** * Meta info about the database engine. @@ -580,7 +581,10 @@ class Database { * @return array */ public function get_all($query, $args=array()) { - return $this->execute($query, $args)->fetchAll(); + $_start = microtime(true); + $data = $this->execute($query, $args)->fetchAll(); + $this->dbtime += microtime(true) - $_start; + return $data; } /** @@ -591,7 +595,9 @@ class Database { * @return mixed|null */ public function get_row($query, $args=array()) { + $_start = microtime(true); $row = $this->execute($query, $args)->fetch(); + $this->dbtime += microtime(true) - $_start; return $row ? $row : null; } @@ -603,11 +609,13 @@ class Database { * @return array */ public function get_col($query, $args=array()) { + $_start = microtime(true); $stmt = $this->execute($query, $args); $res = array(); foreach($stmt as $row) { $res[] = $row[0]; } + $this->dbtime += microtime(true) - $_start; return $res; } @@ -619,11 +627,13 @@ class Database { * @return array */ public function get_pairs($query, $args=array()) { + $_start = microtime(true); $stmt = $this->execute($query, $args); $res = array(); foreach($stmt as $row) { $res[$row[0]] = $row[1]; } + $this->dbtime += microtime(true) - $_start; return $res; } @@ -635,7 +645,9 @@ class Database { * @return mixed */ public function get_one($query, $args=array()) { + $_start = microtime(true); $row = $this->execute($query, $args)->fetch(); + $this->dbtime += microtime(true) - $_start; return $row[0]; } diff --git a/core/util.inc.php b/core/util.inc.php index 6f510ca2..029fcee0 100644 --- a/core/util.inc.php +++ b/core/util.inc.php @@ -1344,12 +1344,13 @@ function get_debug_info() { else { $commit = " (".$config->get_string("commit_hash").")"; } - $time = sprintf("%5.2f", microtime(true) - $_load_start); + $time = sprintf("%.2f", microtime(true) - $_load_start); + $dbtime = sprintf("%.2f", $database->dbtime); $i_files = count(get_included_files()); $hits = $database->cache->get_hits(); $miss = $database->cache->get_misses(); - $debug = "
Took $time seconds and {$i_mem}MB of RAM"; + $debug = "
Took $time seconds (db:$dbtime) and {$i_mem}MB of RAM"; $debug .= "; Used $i_files files and $_execs queries"; $debug .= "; Sent $_event_count events"; $debug .= "; $hits cache hits and $miss misses"; diff --git a/ext/statsd/main.php b/ext/statsd/main.php index c80acd39..5a17fbb3 100644 --- a/ext/statsd/main.php +++ b/ext/statsd/main.php @@ -23,6 +23,7 @@ class StatsDInterface extends Extension { $time = microtime(true) - $_load_start; StatsDInterface::$stats["shimmie.$type.hits"] = "1|c"; StatsDInterface::$stats["shimmie.$type.time"] = "$time|ms"; + StatsDInterface::$stats["shimmie.$type.time-db"] = "{$database->dbtime}|ms"; StatsDInterface::$stats["shimmie.$type.memory"] = memory_get_peak_usage(true)."|c"; StatsDInterface::$stats["shimmie.$type.files"] = count(get_included_files())."|c"; StatsDInterface::$stats["shimmie.$type.queries"] = $_execs."|c";