00001 <?php
00007 if ( !class_exists( 'ProfilerSimple' ) ) {
00008 require_once(dirname(__FILE__).'/ProfilerSimple.php');
00009 }
00010
00016 class ProfilerSimpleTrace extends ProfilerSimple {
00017 var $mMinimumTime = 0;
00018 var $mProfileID = false;
00019 var $trace = "";
00020 var $memory = 0;
00021
00022 function __construct() {
00023 global $wgRequestTime, $wgRUstart;
00024 if (!empty($wgRequestTime) && !empty($wgRUstart)) {
00025 $this->mWorkStack[] = array( '-total', 0, $wgRequestTime,$this->getCpuTime($wgRUstart));
00026 $elapsedcpu = $this->getCpuTime() - $this->getCpuTime($wgRUstart);
00027 $elapsedreal = microtime(true) - $wgRequestTime;
00028 }
00029 $this->trace .= "Beginning trace: \n";
00030 }
00031
00032 function profileIn($functionname) {
00033 global $wgDebugFunctionEntry;
00034 $this->mWorkStack[] = array($functionname, count( $this->mWorkStack ), microtime(true), $this->getCpuTime());
00035 $this->trace .= " " . sprintf("%6.1f",$this->memoryDiff()) . str_repeat( " ", count($this->mWorkStack)) . " > " . $functionname . "\n";
00036 }
00037
00038 function profileOut($functionname) {
00039 global $wgDebugFunctionEntry;
00040
00041 if ($wgDebugFunctionEntry) {
00042 $this->debug(str_repeat(' ', count($this->mWorkStack) - 1).'Exiting '.$functionname."\n");
00043 }
00044
00045 list($ofname, ,$ortime,$octime) = array_pop($this->mWorkStack);
00046
00047 if (!$ofname) {
00048 $this->trace .= "Profiling error: $functionname\n";
00049 } else {
00050 if ($functionname == 'close') {
00051 $message = "Profile section ended by close(): {$ofname}";
00052 $functionname = $ofname;
00053 $this->trace .= $message . "\n";
00054 }
00055 elseif ($ofname != $functionname) {
00056 $self->trace .= "Profiling error: in({$ofname}), out($functionname)";
00057 }
00058 $elapsedcpu = $this->getCpuTime() - $octime;
00059 $elapsedreal = microtime(true) - $ortime;
00060 $this->trace .= sprintf("%03.6f %6.1f",$elapsedreal,$this->memoryDiff()) . str_repeat(" ",count($this->mWorkStack)+1) . " < " . $functionname . "\n";
00061 }
00062 }
00063
00064 function memoryDiff() {
00065 $diff = memory_get_usage() - $this->memory;
00066 $this->memory = memory_get_usage();
00067 return $diff/1024;
00068 }
00069
00070 function getOutput() {
00071 print "<!-- \n {$this->trace} \n -->";
00072 }
00073 }