3 require_once(dirname(__FILE__
).'/Profiler.php');
6 * Simple profiler base class.
7 * @todo document methods (?)
10 class ProfilerSimple
extends Profiler
{
11 var $mMinimumTime = 0;
12 var $mProfileID = false;
14 function __construct() {
15 global $wgRequestTime;
16 if (!empty($wgRequestTime)) {
17 $this->mWorkStack
[] = array( '-total', 0, $wgRequestTime);
19 $elapsedreal = microtime(true) - $wgRequestTime;
21 $entry =& $this->mCollated
["-setup"];
22 if (!is_array($entry)) {
23 $entry = array('real' => 0.0, 'count' => 0);
24 $this->mCollated
["-setup"] =& $entry;
26 $entry['real'] +
= $elapsedreal;
31 function setMinimum( $min ) {
32 $this->mMinimumTime
= $min;
35 function setProfileID( $id ) {
36 $this->mProfileID
= $id;
39 function getProfileID() {
40 if ( $this->mProfileID
=== false ) {
43 return $this->mProfileID
;
47 function profileIn($functionname) {
48 global $wgDebugFunctionEntry;
49 if ($wgDebugFunctionEntry) {
50 $this->debug(str_repeat(' ', count($this->mWorkStack
)).'Entering '.$functionname."\n");
52 $this->mWorkStack
[] = array($functionname, count( $this->mWorkStack
));
55 function profileOut($functionname) {
56 global $wgDebugFunctionEntry;
58 if ($wgDebugFunctionEntry) {
59 $this->debug(str_repeat(' ', count($this->mWorkStack
) - 1).'Exiting '.$functionname."\n");
62 list($ofname, /* $ocount */ ,$ortime,$octime) = array_pop($this->mWorkStack
);
65 $this->debug("Profiling error: $functionname\n");
67 if ($functionname == 'close') {
68 $message = "Profile section ended by close(): {$ofname}";
69 $functionname = $ofname;
70 $this->debug( "$message\n" );
72 elseif ($ofname != $functionname) {
73 $message = "Profiling error: in({$ofname}), out($functionname)";
74 $this->debug( "$message\n" );
76 $entry =& $this->mCollated
[$functionname];
77 $elapsedreal = microtime(true) - $ortime;
78 if (!is_array($entry)) {
79 $entry = array('real' => 0.0, 'count' => 0);
80 $this->mCollated
[$functionname] =& $entry;
82 $entry['real'] +
= $elapsedreal;
88 function getFunctionReport() {
89 /* Implement in output subclasses */
92 /* If argument is passed, it assumes that it is dual-format time string, returns proper float time value */
93 function getTime($time=null) {
95 return microtime(true);
96 list($a,$b)=explode(" ",$time);
97 return (float)($a+
$b);
100 function debug( $s ) {
101 if (function_exists( 'wfDebug' ) ) {