note 85290 added to control-structures.declare
| From: | anotheruser at example dot com | Date: | Sat, 23 Aug 2008 23:50:11 +0000 |
| Subject: | note 85290 added to control-structures.declare | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143778@lists.php.net to get a copy of this message | ||
Code evaluation script which uses debug_backtrace() to get execution time in ns, relative current
line number, function, file, and calling function info on each tick, and shove it all in
$script_stats array. See debug_backtrace manual to customize what info is collected.
Warning: this will exhaust allowed memory very easily, so adjust tick counter according to the size
of your code. Also, array_key_exists checking on debug_backtrace arrays is removed here only to
keep this example simple, but should be added to avoid a large number of resulting PHP Notice
errors.
<?php
$script_stats = array();
$time = microtime(true);
function track_stats(){
global $script_stats,$time;
$trace = debug_backtrace();
$exe_time = (microtime(true) - $time) * 1000;
$func_args = implode(", ",$trace[1]["args"]);
$script_stats[] = array(
"current_time" => microtime(true),
"memory" => memory_get_usage(true),
"file" => $trace[1]["file"].': '.$trace[1]["line"],
"function" => $trace[1]["function"].'('.$func_args.')',
"called_by" => $trace[2]["function"].' in
'.$trace[2]["file"].': '.$trace[2]["line"],
"ns" => $exe_time
);
$time = microtime(true);
}
declare(ticks = 1);
register_tick_function("track_stats");
// the rest of your project code
// output $script_stats into a html table or something
?>
----
Server IP: 209.41.74.194
Probable Submitter: 24.107.184.98
----
Manual Page -- http://www.php.net/manual/en/control-structures.declare.php
Edit -- https://master.php.net/note/edit/85290
Del: integrated -- https://master.php.net/note/delete/85290/integrated
Del: useless -- https://master.php.net/note/delete/85290/useless
Del: bad code -- https://master.php.net/note/delete/85290/bad+code
Del: spam -- https://master.php.net/note/delete/85290/spam
Del: non-english -- https://master.php.net/note/delete/85290/non-english
Del: in docs -- https://master.php.net/note/delete/85290/in+docs
Del: other reasons-- https://master.php.net/note/delete/85290
Reject -- https://master.php.net/note/reject/85290
Search -- https://master.php.net/manage/user-notes.php