The running time of the global recording program fragment correctly find the program logic time-consuming breakpoint _php technique

Source: Internet
Author: User
Copy Code code as follows:

Define global variable record time
$_timer_id = 0;
function to set global variables to record the time required for each breakpoint to run
function Maketimer ($notes, $onOff =false)
{
if ($ONOFF)
{
Global $_timer_id;
$GLOBALS [' timer '][$_timer_id][0] = Microtime (TRUE);
$GLOBALS [' timer '][$_timer_id][1] = $notes;
$_timer_id++;
}
}
The global run time condition output
function Tracetimer ()
{
$timer _str = ';
$G _timer = count ($GLOBALS [' Timer '])-1;
if ($G _timer>0)
{
for ($i =0; $i < $G _timer; $i + +)
{
$dif _time = Number_format ($GLOBALS [' Timer '] [$i +1][0]-$GLOBALS [' Timer '] [$i][0]), 3;
$timer _str. = ' dif: '. $dif _time. ' '. $GLOBALS [' Timer '] [$i][1]. " \ n ";
}
$dif _time = Number_format ((microtime (TRUE)-$GLOBALS [' Timer '] [$G _timer][0]), 3;
$timer _str. = ' dif: '. $dif _time. ' '. $GLOBALS [' Timer '] [$G _timer][1]. " \ n ";
}
return $timer _str;
}
How to use:
Start time
Maketimer (' line: '. __line__);
$imgstrpos = Strpos ($str, ' Maketimer (' line: '. __line__);
$str _p = substr ($str _noimg, 0, $imgstrpos);
Maketimer (' line: '. __line__);
$str _n = substr ($str _noimg, $imgstrpos, strlen ($str _noimg));
Maketimer (' line: '. __line__);
$pst _exc_imgs = $str _p. ' '. $str _n. " ";
Maketimer (' line: '. __line__);
Record to log
Error_log (Tracetimer (), 3, '/tmp/'. basename (__file__). Log ");
or direct output
Echo Tracetimer ();

At 2010-05-14 09:20

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.