a tiny mvc framework for php using php-activerecord
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

add a database_time attribute

in query(), keep track of the time wasted waiting for the database, adding it to database_time

+41 -2
+41 -2
lib/php-activerecord/lib/Connection.php
··· 30 30 public $last_query; 31 31 32 32 /** 33 + * Seconds spent waiting for the database. 34 + * @var float 35 + */ 36 + public $database_time = 0; 37 + 38 + /** 33 39 * Default PDO options to set for each connection. 34 40 * @var array 35 41 */ ··· 214 220 215 221 $this->last_query = $sql; 216 222 223 + $start_time = microtime(true); 224 + 217 225 try { 218 - if (!($sth = $this->connection->prepare($sql))) 226 + if (!($sth = $this->connection->prepare($sql))) { 227 + $this->record_database_time(microtime(true) - $start_time); 219 228 throw new DatabaseException($this); 229 + } 220 230 } catch (PDOException $e) { 231 + $this->record_database_time(microtime(true) - $start_time); 221 232 throw new DatabaseException($this); 222 233 } 223 234 224 235 $sth->setFetchMode(PDO::FETCH_ASSOC); 225 236 226 237 try { 227 - if (!$sth->execute($values)) 238 + if (!$sth->execute($values)) { 239 + $this->record_database_time(microtime(true) - $start_time); 228 240 throw new DatabaseException($this); 241 + } 229 242 } catch (PDOException $e) { 243 + $this->record_database_time(microtime(true) - $start_time); 230 244 throw new DatabaseException($sth); 231 245 } 246 + 247 + $this->record_database_time(microtime(true) - $start_time); 248 + 232 249 return $sth; 233 250 } 234 251 ··· 341 358 * @return string 342 359 */ 343 360 abstract function quote_name($string); 361 + 362 + /** 363 + * Adds time spent in the database to the tally. 364 + * 365 + * @return void 366 + */ 367 + public function record_database_time($seconds) 368 + { 369 + $this->database_time += $seconds; 370 + } 371 + 372 + /** 373 + * Return the time spent in the database and reset the tally. 374 + * 375 + * @return float 376 + */ 377 + public function reset_database_time() 378 + { 379 + $t = $this->database_time; 380 + $this->database_time = 0; 381 + return $t; 382 + } 344 383 }; 345 384 ?>