log time spent waiting for database queries
This commit is contained in:
parent
1c60942730
commit
4721d666cd
3 changed files with 17 additions and 3 deletions
|
@ -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];
|
||||
}
|
||||
|
||||
|
|
|
@ -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 = "<br>Took $time seconds and {$i_mem}MB of RAM";
|
||||
$debug = "<br>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";
|
||||
|
|
|
@ -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";
|
||||
|
|
Reference in a new issue