description = array(); $this->startTime = array(); $this->endTime = array(); $this->initTime = 0; $this->cur_timer = ""; $this->stack = array(); $this->trail = ""; $this->trace = ""; $this->count = array(); $this->running = array(); $this->initTime = $this->getMicroTime(); $this->output_enabled = $output_enabled; $this->trace_enabled = $trace_enabled; $this->startTimer('unprofiled'); } // Public Methods static function init() { if(!self::$inst) self::$inst = new Profiler(true,true); } static function mark($name, $level2 = "", $desc = "") { if($level2 && $_GET['debug_profile'] > 1) $name .= " $level2"; if(!self::$inst) self::$inst = new Profiler(true,true); self::$inst->startTimer($name, $desc); } static function unmark($name, $level2 = "", $desc = "") { if($level2 && $_GET['debug_profile'] > 1) $name .= " $level2"; if(!self::$inst) self::$inst = new Profiler(true,true); self::$inst->stopTimer($name, $desc); } static function show($showTrace = false) { if(!self::$inst) self::$inst = new Profiler(true,true); echo "
\n"); $oaTime = $this->getMicroTime() - $this->initTime; echo"============================================================================\n"; echo " PROFILER OUTPUT\n"; echo"============================================================================\n"; print( "Calls Time Routine\n"); echo"-----------------------------------------------------------------------------\n"; while (list ($key, $val) = each ($this->description)) { $t = $this->elapsedTime($key); $total = $this->running[$key]; $count = $this->count[$key]; $TimedTotal += $total; $perc = ($total/$oaTime)*100; $tot_perc+=$perc; // $perc=sprintf("%3.2f", $perc ); $lines[ sprintf( "%3d %3.4f ms (%3.2f %%) %s\n", $count, $total*1000, $perc, $key) ] = $total; } arsort($lines); foreach($lines as $line => $total) { echo $line; } echo "\n"; $missed=$oaTime-$TimedTotal; $perc = ($missed/$oaTime)*100; $tot_perc+=$perc; // $perc=sprintf("%3.2f", $perc ); printf( " %3.4f ms (%3.2f %%) %s\n", $missed*1000,$perc, "Missed"); echo"============================================================================\n"; printf( " %3.4f ms (%3.2f %%) %s\n", $oaTime*1000,$tot_perc, "OVERALL TIME"); echo"============================================================================\n"; print(""); } } function printTrace( $enabled=false ) { if($this->trace_enabled||$enabled){ print("
"); print("Trace\n$this->trace\n\n"); print(""); } } /// Internal Use Only Functions /** * Get the current time as accuratly as possible * */ function getMicroTime(){ $tmp=explode(' ', microtime()); $rt=$tmp[0]+$tmp[1]; return $rt; } /** * resume an individual timer * */ function __resumeTimer($name){ $this->trace.="resume $name\n"; $this->startTime[$name] = $this->getMicroTime(); } /** * suspend an individual timer * */ function __suspendTimer($name){ $this->trace.="suspend $name\n"; $this->endTime[$name] = $this->getMicroTime(); if (!array_key_exists($name, $this->running)) $this->running[$name] = $this->elapsedTime($name); else $this->running[$name] += $this->elapsedTime($name); } } ?>