protected function showTime(sfTimer $timer, $message = 'Time : ', $afterMessage = "\n\n") { $timer->addTime(); $this->log(''); $this->logSection($message, date('i:s', (int) $timer->getElapsedTime())); $this->log(''); $this->log(''); }
protected function execute($arguments = array(), $options = array()) { $definitions = $this->getDefinition(); $timer = new sfTimer(); $succeeded = array(); $targets = $this->getOption('targets', array_keys($definitions)); foreach ((array) $definitions as $k => $v) { if (!in_array($k, $targets)) { continue; } $timer->startTimer(); $defaultOptions = array_merge($this->options, array('name' => $k, 'dir' => $this->basePath, 'required_rules' => array(), 'configuration' => $this->configuration, 'dispatcher' => new sfEventDispatcher(), 'formatter' => $this->formatter)); $v = array_merge(array('options' => $defaultOptions), $v); if (!isset($v['options']['required_rules'])) { $v['options']['required_rules'] = array(); } $requiredRules = (array) $v['options']['required_rules']; if (!empty($requiredRules) && array_diff($requiredRules, $succeeded)) { $this->logSection('upgrade', 'Passed ' . $k, null, 'ERROR'); continue; } $this->logSection('upgrade', 'Processing ' . $k); if (isset($v['file']) && is_file($v['file'])) { require_once $v['file']; } if (class_exists($v['strategy'])) { $className = $v['strategy']; } else { $className = 'opUpgrade' . $v['strategy'] . 'Strategy'; } opApplicationConfiguration::registerZend(); try { // disable Doctrine profiling sfConfig::set('sf_debug', false); $strategy = new $className($v['options']); $strategy->run(); $succeeded[] = $k; } catch (Exception $e) { $this->logBlock($e->getMessage(), 'ERROR'); } opApplicationConfiguration::unregisterZend(); $this->logSection('upgrade', sprintf('Processed %s (%.2f sec)', $k, $timer->addTime())); } $this->logSection('upgrade', sprintf('Completed Upgrading (%.2f sec)', $timer->getElapsedTime())); $this->logSection('upgrade', sprintf('The %.2f MB memory allocated', round(memory_get_peak_usage(true) / 1048576, 2))); }
<?php /* * This file is part of the symfony package. * (c) 2004-2006 Fabien Potencier <*****@*****.**> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ require_once __DIR__ . '/../../bootstrap/unit.php'; $t = new lime_test(6); $t->diag('sfTimer starting and stopping'); $timer = new sfTimer(); $timer->addTime(); sleep(1); $timer->addTime(); $t->is($timer->getCalls(), 2, '->getCalls() returns the amount of addTime() calls'); $t->ok($timer->getElapsedTime() > 0, '->getElapsedTime() returns a value greater than zero. No precision is tested by the unit test to avoid false alarms'); $t->diag('sfTimerManager'); $timerA = sfTimerManager::getTimer('timerA'); $timerB = sfTimerManager::getTimer('timerB'); $t->isa_ok($timerA, 'sfTimer', '::getTimer() returns an sfTimer instance'); $timers = sfTimerManager::getTimers(); $t->is(count($timers), 2, '::getTimers() returns an array with the timers created by the timer manager'); $t->is($timers['timerA'], $timerA, '::getTimers() returns an array with keys being the timer name'); sfTimerManager::clearTimers(); $t->is(count(sfTimerManager::getTimers()), 0, '::clearTimers() empties the list of the timer instances');
function persist_menu(lime_test $t, ioDoctrineMenuItem $rt, ioMenuItem $menu) { $timer = new sfTimer(); $rt->persistFromMenuArray($menu->toArray()); $timer->addTime(); $rt->refresh(true); $t->info(sprintf('### Menu took %s to persist (%s nodes/min)', round($timer->getElapsedTime(), 4), floor(8 * 60 / $timer->getElapsedTime()))); }