[Pmwiki-users] StopWatch update

Knut Alboldt pmwiki
Mon Dec 20 03:21:18 CST 2004


I did some changes in for the Stopwatch-function in pmwiki.php and 
diag.php cause it didn't run right on a windows-webserver. Pm, if you 
could have a look and possibly test this for linux as well and migrate 
this to the distribution code.
My windows-webserver is not using the getrusage-function to calculate 
the microtime.

Knut


changes in pmwiki.php:

function StopWatch($x) {
   if (function_exists('getrusage') && ($dat=getrusage())) {
     $GLOBALS['StopWatch'][] = $dat['ru_utime.tv_sec'] . " " . 
$dat['ru_utime.tv_usec'] . " " . $x;
     return;
   }
   list($usec,$sec) = explode(' ',microtime());
   $GLOBALS['StopWatch'][] = "$sec $usec $x";
}


changes in diag.php

function DisplayStopWatch() {
   global $StopWatch;
   StopWatch('now');
   list($sec, $usec, $event) = explode(' ',$StopWatch[0],3);
   $au = $sec+$usec;
   $c  = 0.0;
   $out[] = 
"<table><tr><th>Event</th><th>Time</th><th>Cumulative</th></tr>\n";
   foreach ($StopWatch as $entry) {
     list($sec, $usec, $bevent) = explode(' ',$entry,3);
     $bu = $sec+$usec;
     $t = $bu-$au;
     $c = $c + $t;
     $out[] = "<tr><td>$bevent</td><td 
align='right'>".sprintf('%.02f',$t)."</td><td 
align='right'>".sprintf('%.02f',$c)."</td></tr>";
     $au=$bu;
   }
   array_pop($StopWatch);
   $out[] = '</table>';
   return implode('',$out);
}



More information about the pmwiki-users mailing list