reset(); } public function reset() { $this->timers = array(); $this->runningTimers = array(); $this->number = 0; } public function startTimer( $name, $source, $group ) { if ( !isset( $this->runningTimers[ $name ] ) ) { $this->totalRunningTimers++; $this->runningTimers[$name] = new ezcDebugStructure(); $this->runningTimers[$name]->name = $name; $this->runningTimers[$name]->source = $source; $this->runningTimers[$name]->group = $group; $this->runningTimers[$name]->switchTime = array(); $this->runningTimers[$name]->startTime = microtime( true ); $this->runningTimers[$name]->startNumber = $this->number++; return true; } return false; } /** * Stores the time from the running timer, and starts a new timer. * * @param string $newName Name of the new timer. * @param string $oldName The previous timer that must be stopped. * Only needed when multiple timers are running. */ public function switchTimer( $newName, $oldName = false ) { if ( $this->totalRunningTimers < 1 ) { return false; } if ( $oldName === false ) { if ( $this->totalRunningTimers > 1 ) { return false; } $oldName = key( $this->runningTimers ); } $this->runningTimers[$newName] = $this->runningTimers[$oldName]; unset( $this->runningTimers[$oldName] ); $switchStruct = new ezcDebugStructure(); $switchStruct->name = $newName; $switchStruct->time = microtime( true ); $this->runningTimers[$newName]->switchTime[] = $switchStruct; } /** * Stop the timer * * @param $name Need to supply a name only when multiple timers are running. */ public function stopTimer( $name = false ) { if ( $name === false && $this->totalRunningTimers == 1 ) { $name = key( $this->runningTimers ); } if ( isset( $this->runningTimers[ $name ] ) ) { $this->runningTimers[$name]->stopTime = microtime( true ); $this->runningTimers[$name]->elapsedTime = $this->runningTimers[$name]->stopTime - $this->runningTimers[$name]->startTime; $this->runningTimers[$name]->stopNumber = $this->number++; $this->timers[] = $this->runningTimers[$name]; unset( $this->runningTimers[$name] ); $this->totalRunningTimers--; return true; } return false; } /** * Returns an array with the used sources, groups, and timers. * * @return array */ public function getStructure() { /* $result = new ezcDebugStructure(); $result->stopTimes = $this->timers; $result->groups = $this->getGroups(); var_dump( $result ); */ return $this->timers; } protected function getGroups() { $groups = array(); foreach ( $this->timers as $time ) { $groups[$time->group][] = $time; } return $groups; } } ?>