Re: Ticks and finding out where the script currently is.
| From: | William Bailey | Date: | Thu, 01 May 2003 13:07:54 +0000 |
| Subject: | Re: Ticks and finding out where the script currently is. | ||
| References: | 1 2 3 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-145944@lists.php.net to get a copy of this message | ||
I think that i have this worked out. Below is the code i'm using, if there is
something wrong of i'm not doing things correctly then please tell me.
<?php
function get_microtime ( ) {
list($usec, $sec)=explode(' ', microtime());
return ((float)$usec + (float)$sec);
}
function profile ( $dump = false) {
static $profile;
if(!$dump){
$debug = debug_backtrace();
if(!isset($debug[count($debug)-2])){
return false;
}
$debug = $debug[count($debug)-2]; // I think this is the correct part
i want.
$now = get_microtime();
$data = array(
'totalTime'=>$now - APP_START,
'function'=>$debug['function'],
);
if(count($profile)>1){
$data['diffTime']=$data['totalTime'] -
$profile[count($profile)-1]['totalTime'];
}else{
$data['diffTime']=0;
}
if(isset($debug['file'])){
$data['file']=$debug['file'];
}else{
$data['file']='';
}
if(isset($debug['line'])){
$data['line']=$debug['line'];
}else{
$data['line']='';
}
if(isset($debug['class'])){
$data['class']=$debug['class'];
}else{
$data['class']='';
}
$profile[]=$data;
}else{
print('
<div style="background-color: #C0C0C0; color: #000000; font-size:
10px; font-family: arial; font-weight: bold; position: absolute; top: 2px;
left: 900px; padding: 2px 10px 2px 10px;">
Tick @
');
foreach($profile as $data){
printf('
<p>
<b>Time:</b> %0.4f (+%0.4f)
<br><b>File:</b> %s line %d
<br><b>Class:</b> %s
<br><b>Function:</b> %s
', $data['totalTime']
, $data['diffTime']
, $data['file']
, $data['line']
, $data['class']
, $data['function']
);
}
print('</div>');
}
}
function display_time ( ) {
profile(true);
}
register_tick_function('profile');
register_shutdown_function('display_time');
declare (ticks=50);
?>
On Thursday 01 May 2003 13:14, William Bailey wrote:
> Hi all,
>
> I am using ticks to time one of my scripts and was just wondering if there
> was a way to find out where the script is (filename & line or current
> function/scope) at the time the tick function was called. It be nice to be
> able to follow the script as it runs.
>
> --
> Regards,
> William Bailey.
> Pro-Net Internet Services Ltd.
> http://www.pro-net.co.uk
> http://wb.pro-net.co.uk
--
Regards,
William Bailey.
Pro-Net Internet Services Ltd.
http://www.pro-net.co.uk
http://wb.pro-net.co.uk