As I add more and more complexity to my script, it would be nice to get a benchmark of performance status over time. I wonder if I can start a thread on methods for this.
I have a function already for seeing time "checkpoints" through a script as follows:
//at the head of my coding
function gmicrotime($n){
//store array of all calls
global $gmicrotime, $mT;
list($usec, $sec) = explode(' ',microtime());
$mT[]=$gmicrotime[$n]=round((float)$usec + (float)$sec,6);
//return elapsed since last call
if(count($mT)>1)return round(1000*($mT[count($mT)-1]-$mT[count($mT)-2]),6);
}
gmicrotime('initial');
#do some code block A
gmicrotime('after_A');
#do something else, B
gmicrotime('after_B');
#end of page
gmicrotime('end');
if($test){
echo '<pre>';
print_r($mT);
}
Now, I suppose I could get the memory usage at that point as well and build a parallel array called $mM (micro memory). But memory is not everything. How can I determine what the current CPU load is by the script? Is this even possible?
Any other suggestions on monitoring the performance of a script, or examples, is welcome.
Sam