|
Main sidebar
|
PITS /
00896Summary: Make StopWatch more informative and more flexible
Created: 2007-03-01 10:10
Status: Open
Category: Feature
From: Daniel Rairigh?
Assigned:
Priority: 31
I am trying to revive this old proposal by suggesting a slightly different StopWatch with three main changes to the one in core:
Proposed code below. -- Rogut279s? October 05, 2009, at 06:00 PM
function StopWatch($x) {
global $StopWatch, $EnableStopWatch;
if (!$EnableStopWatch) return;
static $wlast=0, $ulast=0, $n=0;
list($us,$wtime)=explode(' ', microtime());
$wtime+=$us;
if (!$wlast) $wlast=$wtime;
$StopWatch[++$n] = array($x, ($wtime-$wlast)*1000);
$wlast=$wtime;
if ($EnableStopWatch!=2) return;
$dat = getrusage();
$utime = $dat['ru_utime.tv_sec']*1000+$dat['ru_utime.tv_usec']/1000;
if (!$ulast) $ulast=$utime;
$StopWatch[$n][] = $utime-$ulast;
$ulast=$utime;
}
function StopWatchHTML($pagename, $print=0) {
global $StopWatch, $EnableStopWatch;
StopWatch('now');
$out='<pre>';
$wsum=0; $usum=0;
foreach ((array)$StopWatch as $t) {
$wsum+=$t[1];
if (isset($t[2])) {
$usum+=$t[2];
$out.=sprintf("%3d %3d %s\n", $t[1], $t[2], $t[0]);
}
else $out.=sprintf("%3d %s\n", $t[1], $t[0]);
}
if ($usum) $out.=sprintf("%3d %3d SUM\n", $wsum, $usum);
elseif ($wsum) $out.=sprintf("%3d SUM\n", $wsum);
$out.='</pre>';
if (is_array($StopWatch)) array_pop($StopWatch);
if ($print) echo $out;
return $out;
}
The original proposal below. Sorry for hijacking, but it lay here for 2.5 years without any activity... Version: 2.1.27
OS: Linux, PHP 4.3.11
Description: This adds a nice header to the StopWatch output and a time delta (makes the length of time that each step requires is clear). Patch: --- /home/rairighd/Desktop/pmwiki-2.1.27/pmwiki.php 2006-12-11 09:56:21.000000000 -0500 +++ notes/pmwiki.php 2007-03-01 10:29:01.000000000 -0500 |