integrated profiler

This commit is contained in:
Alexander Kampmann 2012-03-15 12:55:49 +01:00
parent 9796e99fa8
commit 899701c3d3
3 changed files with 26 additions and 41 deletions

View File

@ -858,11 +858,11 @@ INDEX ( `term` )
) ENGINE = MyISAM DEFAULT CHARSET=utf8; ) ENGINE = MyISAM DEFAULT CHARSET=utf8;
CREATE TABLE IF NOT EXISTS `profiling` ( CREATE TABLE IF NOT EXISTS `profiling` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY_KEY , `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`function` VARCHAR( 255 ) NOT NULL , `function` VARCHAR( 255 ) NOT NULL ,
`file` VARCHAR( 255 ) NOT NULL , `file` VARCHAR( 255 ) NOT NULL ,
`line` INT NOT NULL DEFAULT '-1', `line` INT NOT NULL DEFAULT '-1',
`class` VARCHAR(255), `class` VARCHAR( 255 ) NOT NULL ,
`time` FLOAT( 10, 2 ) NOT NULL , `time` FLOAT( 10, 2 ) NOT NULL ,
INDEX ( `function` ) , INDEX ( `function` ) ,
INDEX ( `file` ) INDEX ( `file` )

View File

@ -1,6 +1,6 @@
<?php <?php
define( 'UPDATE_VERSION' , 1131 ); define( 'UPDATE_VERSION' , 1132 );
/** /**
* *
@ -1125,13 +1125,13 @@ function update_1130() {
/** /**
* CREATE TABLE for profiling * CREATE TABLE for profiling
*/ */
function update_1132() { function update_1131() {
q("CREATE TABLE IF NOT EXISTS `profiling` ( q("CREATE TABLE IF NOT EXISTS `profiling` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY_KEY , `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`function` VARCHAR( 255 ) NOT NULL , `function` VARCHAR( 255 ) NOT NULL ,
`file` VARCHAR( 255 ) NOT NULL , `file` VARCHAR( 255 ) NOT NULL ,
`line` INT NOT NULL DEFAULT '-1', `line` INT NOT NULL DEFAULT '-1',
`class` VARCHAR(255), `class` VARCHAR( 255 ) NOT NULL ,
`time` FLOAT( 10, 2 ) NOT NULL , `time` FLOAT( 10, 2 ) NOT NULL ,
INDEX ( `function` ) , INDEX ( `function` ) ,
INDEX ( `file` ) INDEX ( `file` )

View File

@ -1,24 +1,12 @@
<?php <?php
function microtime_float() function microtime_float()
{ {
list($usec, $sec) = explode(" ", microtime()); return microtime(true);
return ((float)$usec + (float)$sec);
} }
function tick_event() { function tick_event() {
static $time = NULL; $db_info=debug_backtrace();
$db_info=$db_info[1];
if(NULL===$time) {
//initialise time with now
$time=microtime_float();
q("INSERT INTO `profiling` (`function`, `file`, `line`, `class`, `time`) VALUES ('initialization', 'index.php', '-1', NULL, '%f'); ",
floatval($time-$_SERVER['REQUEST_TIME']));
}
$elapsed=microtime_float()-$time;
$db_info=array_shift(debug_backtrace());
$function=$db_info['function']; $function=$db_info['function'];
$file=$db_info['file']; $file=$db_info['file'];
$line=$db_info['line']; $line=$db_info['line'];
@ -26,11 +14,8 @@ function tick_event() {
//save results //save results
q("INSERT INTO `profiling` (`function`, `file`, `line`, `class`, `time`) VALUES ('%s', '%s', '%d', '%s', '%f'); ", q("INSERT INTO `profiling` (`function`, `file`, `line`, `class`, `time`) VALUES ('%s', '%s', '%d', '%s', '%f'); ",
dbesc($function), dbesc($file), intval($line), dbesc($class), floatval($time)); dbesc($function), dbesc($file), intval($line), dbesc($class), microtime_float()*1000);
//set time to now
$time=microtime_float();
} }
declare(ticks=1);
register_tick_function('tick_event'); register_tick_function('tick_event');
declare(ticks=50);