/** * tearDown method * * @return void */ public function tearDown() { parent::tearDown(); Configure::write('log', true); DebugTimer::clear(); TestFireCake::reset(); }
/** * Stop timers for rendering. * * @param string $layoutFile */ public function afterLayout($layoutFile) { DebugTimer::stop('viewRender'); DebugTimer::stop('controllerRender'); DebugMemory::record(__d('debug_kit', 'View render complete')); $this->_renderComplete = true; }
function run($dbi, $argstr, $request, $basepage) { $args = $this->getArgs($argstr, $request); $pages = false; // Todo: extend given _GET args if ($args['debug']) { $timer = new DebugTimer(); } $caption = _("All pages in this wiki (%d total):"); if (!empty($args['owner'])) { $pages = PageList::allPagesByOwner($args['owner'], $args['include_empty'], $args['sortby'], $args['limit']); if ($args['owner']) { $caption = fmt("List of pages owned by [%s] (%d total):", WikiLink($args['owner'] == '[]' ? $request->_user->getAuthenticatedId() : $args['owner'], 'if_known'), count($pages)); } } elseif (!empty($args['author'])) { $pages = PageList::allPagesByAuthor($args['author'], $args['include_empty'], $args['sortby'], $args['limit']); if ($args['author']) { $caption = fmt("List of pages last edited by [%s] (%d total):", WikiLink($args['author'] == '[]' ? $request->_user->getAuthenticatedId() : $args['author'], 'if_known'), count($pages)); } } elseif (!empty($args['creator'])) { $pages = PageList::allPagesByCreator($args['creator'], $args['include_empty'], $args['sortby'], $args['limit']); if ($args['creator']) { $caption = fmt("List of pages created by [%s] (%d total):", WikiLink($args['creator'] == '[]' ? $request->_user->getAuthenticatedId() : $args['creator'], 'if_known'), count($pages)); } //} elseif ($pages) { // $args['count'] = count($pages); } else { if (!$request->getArg('count')) { $args['count'] = $dbi->numPages($args['include_empty'], $args['exclude']); } else { $args['count'] = $request->getArg('count'); } } if (empty($args['count']) and !empty($pages)) { $args['count'] = count($pages); } $pagelist = new PageList($args['info'], $args['exclude'], $args); if (!$args['noheader']) { $pagelist->setCaption($caption); } // deleted pages show up as version 0. if ($args['include_empty']) { $pagelist->_addColumn('version'); } if ($pages !== false) { $pagelist->addPageList($pages); } else { $pagelist->addPages($dbi->getAllPages($args['include_empty'], $args['sortby'], $args['limit'])); } if ($args['debug']) { return HTML($pagelist, HTML::p(fmt("Elapsed time: %s s", $timer->getStats()))); } else { return $pagelist; } }
/** * Wrapper around _isAuthorized to allow for timing * * @param array $user an array of user data. Can also be null * @param string $action The action to check access for * @return bool whether or not the user is authorized for access */ public function isAuthorized($user, $action) { $timerExists = Configure::read('debug') && class_exists('DebugTimer'); if ($timerExists) { DebugTimer::start(get_called_class() . '->isAuthorized()'); } $return = $this->performCheck($user, $action); if ($timerExists) { DebugTimer::stop(get_called_class() . '->isAuthorized()'); } return $return; }
/** * Renders view for given action and layout. * Adds timers, for all subsequent rendering, and injects the debugKit toolbar. * * @param string $action Name of action to render for * @param string $layout Layout to use * @return string Rendered Element */ public function render($action = null, $layout = null) { DebugTimer::start('viewRender', __d('debug_kit', 'Rendering View')); $out = parent::render($action, $layout); DebugTimer::stop('viewRender'); DebugTimer::stop('controllerRender'); DebugMemory::record(__d('debug_kit', 'View render complete')); if (empty($this->request->params['requested']) && $this->Helpers && $this->Helpers->attached('Toolbar')) { $backend = $this->Helpers->Toolbar->getName(); $this->Helpers->Toolbar->{$backend}->send(); } if (empty($this->output)) { return $out; } return $this->output; }
function run($dbi, $argstr, &$request, $basepage) { $args = $this->getArgs($argstr, $request); extract($args); if ($debug) { $timer = new DebugTimer(); } $group = $request->getGroup(); if (method_exists($group, '_allUsers')) { $allusers = $group->_allUsers(); } else { $allusers = array(); } $args['count'] = count($allusers); // deleted pages show up as version 0. $pagelist = new PageList($info, $exclude, $args); if (!$noheader) { $pagelist->setCaption(_("Authenticated users on this wiki (%d total):")); } if ($include_empty and empty($info)) { $pagelist->_addColumn('version'); } list($offset, $pagesize) = $pagelist->limit($args['limit']); if (!$pagesize) { $pagelist->addPageList($allusers); } else { for ($i = $offset; $i < $offset + $pagesize - 1; $i++) { if ($i >= $args['count']) { break; } $pagelist->addPage($allusers[$i]); } } /* $page_iter = $dbi->getAllPages($include_empty, $sortby, $limit); while ($page = $page_iter->next()) { if ($page->isUserPage($include_empty)) $pagelist->addPage($page); } */ if ($debug) { return HTML($pagelist, HTML::p(fmt("Elapsed time: %s s", $timer->getStats()))); } else { return $pagelist; } }
/** * test that vars are gathered and state is saved on beforeRedirect * * @return void */ public function testBeforeRedirect() { $this->_loadController(array('panels' => array('session', 'history'))); $configName = 'debug_kit'; $this->Controller->Toolbar->cacheKey = 'toolbar_history'; Cache::delete('toolbar_history', $configName); DebugTimer::start('controllerAction', 'testing beforeRedirect'); $MockPanel = $this->getMock('DebugPanel'); $MockPanel->expects($this->once())->method('beforeRender'); $this->Controller->Toolbar->panels['session'] = $MockPanel; $this->Controller->Toolbar->beforeRedirect($this->Controller, '/another/url'); $result = Cache::read('toolbar_history', $configName); $this->assertTrue(isset($result[0]['session'])); $this->assertFalse(isset($result[0]['history'])); $timers = DebugTimer::getAll(); $this->assertTrue(isset($timers['controllerAction'])); }
/** * Clear all existing timers * * @return bool true */ public static function clear() { self::$_timers = array(); return true; }
/** * beforeRender callback * * Calls beforeRender on all the panels and set the aggregate to the controller. * * @param Controller $controller * @return void */ public function beforeRender(Controller $controller) { if (!class_exists('DebugTimer')) { return null; } DebugTimer::stop('controllerAction'); DebugTimer::start('processToolbar', __d('debug_kit', 'Processing toolbar data')); $vars = $this->_gatherVars($controller); $this->_saveState($controller, $vars); $this->javascript = array_unique(array_merge($this->javascript, $vars['javascript'])); $this->css = array_unique(array_merge($this->css, $vars['css'])); unset($vars['javascript'], $vars['css']); $controller->set(array('debugToolbarPanels' => $vars, 'debugToolbarJavascript' => $this->javascript, 'debugToolbarCss' => $this->css)); $isHtml = !isset($controller->request->params['ext']) || $controller->request->params['ext'] === 'html'; if (!$controller->request->is('ajax') && $isHtml) { $format = 'Html'; } else { $format = 'FirePhp'; } $controller->helpers[] = 'DebugKit.DebugTimer'; $controller->helpers['DebugKit.Toolbar'] = array('output' => sprintf('DebugKit.%sToolbar', $format), 'cacheKey' => $this->cacheKey, 'cacheConfig' => 'debug_kit', 'forceEnable' => $this->settings['forceEnable']); DebugTimer::stop('processToolbar'); DebugMemory::record(__d('debug_kit', 'Controller render start')); }
/** * get the time the current request started. * * @return float time of request start * @deprecated use DebugTimer::requestStartTime() */ public static function requestStartTime() { return DebugTimer::requestStartTime(); }
/** * destruct method * * Allow timer info to be displayed if the code dies or is being debugged before rendering the view * Cheat and use the debug log class for formatting * * @return void */ public function __destruct() { $timers = DebugTimer::getAll(); if (Configure::read('debug') < 2 || count($timers) > 0) { return; } $timers = array_values($timers); $end = end($timers); echo '<table class="cake-sql-log"><tbody>'; echo '<caption>Debug timer info</caption>'; echo '<tr><th>Message</th><th>Start Time (ms)</th><th>End Time (ms)</th><th>Duration (ms)</th></tr>'; $i = 0; foreach ($timers as $timer) { $indent = 0; for ($j = 0; $j < $i; $j++) { if ($timers[$j]['end'] > $timer['start'] && $timers[$j]['end'] > $timer['end']) { $indent++; } } $indent = str_repeat(' » ', $indent); extract($timer); $start = round($start * 1000, 0); $end = round($end * 1000, 0); $time = round($time * 1000, 0); echo "<tr><td>{$indent}{$message}</td><td>{$start}</td><td>{$end}</td><td>{$time}</td></tr>"; $i++; } echo '</tbody></table>'; }
protected function _findView($state, $query, $results = array()) { if ($state == 'before') { if (empty($query['package_id'])) { throw new InvalidArgumentException(__('Invalid package')); } $query['conditions'] = array("{$this->alias}.{$this->primaryKey}" => $query['package_id']); $query['contain'] = array('Maintainer' => array('name', 'username')); $query['limit'] = 1; if (!empty($query['fields'])) { $query['fields'] = array_merge($this->getDataSource()->fields($this, null, $query['fields']), $this->Category->getDataSource()->fields($this->Category)); } else { $query['fields'] = array_merge($this->getDataSource()->fields($this), $this->Category->getDataSource()->fields($this->Category)); } $this->unbindModel(array('belongsTo' => array('Categories.Category'))); $query['joins'] = array(array('alias' => 'Category', 'table' => 'categories', 'type' => 'LEFT', 'conditions' => array('`Category`.`id` = `Package`.`category_id`'))); // Join additional records if necessary if ($query['user_id']) { if (!empty($query['fields'])) { $query['fields'] = array_merge($this->getDataSource()->fields($this, null, $query['fields']), $this->Rating->getDataSource()->fields($this->Rating), $this->Favorite->getDataSource()->fields($this->Favorite)); } else { $query['fields'] = array_merge($this->getDataSource()->fields($this), $this->Rating->getDataSource()->fields($this->Rating), $this->Favorite->getDataSource()->fields($this->Favorite)); } $this->unbindModel(array('hasMany' => array('Ratings.Rating', 'Favorites.Favorite'))); $query['joins'][] = array('alias' => 'Favorite', 'table' => 'favorites', 'type' => 'LEFT', 'conditions' => array('`Favorite`.`foreign_key` = `Package`.`id`', 'Favorite.model' => 'Package', 'Favorite.type' => 'bookmark', 'Favorite.user_id' => $query['user_id'])); $query['joins'][] = array('alias' => 'Rating', 'table' => 'ratings', 'type' => 'LEFT', 'conditions' => array('`Rating`.`foreign_key` = `Package`.`id`', 'Rating.model' => 'Package', 'Rating.user_id' => $query['user_id'])); } return $query; } if (empty($results[0])) { throw new NotFoundException(__('Invalid package')); } if (empty($results[0]['Maintainer'])) { throw new NotFoundException(__('Invalid maintainer')); } if (empty($results[0]['Favorite']['id'])) { $results[0]['Favorite'] = false; } if (empty($results[0]['Rating']['id'])) { $results[0]['Rating'] = false; } if ($this->shouldForceUpdate($results[0][$this->alias]['modified'])) { try { $this->enqueue('UpdatePackageJob', array($results[0][$this->alias][$this->primaryKey])); } catch (Exception $e) { CakeLog::warning('Package::find(\'view\')' . $e->getMessage()); } } DebugTimer::start('app.Package::rss', __d('app', 'Package::rss()')); list($results[0]['Rss'], $results[0]['Cache']) = $this->rss($results[0]); DebugTimer::stop('app.Package::rss'); return $results[0]; }
/** * Stop timer for Crud.Delete * * @param CakeEvent $event * @return void */ public function afterDelete(CakeEvent $event) { DebugTimer::stop('Event: Crud.Delete'); }
/** * beforeRender callback * * Calls beforeRender on all the panels and set the aggregate to the controller. * * @return void **/ public function beforeRender($controller) { if (!class_exists('DebugTimer')) { return null; } DebugTimer::stop('controllerAction'); $vars = $this->_gatherVars($controller); $this->_saveState($controller, $vars); $controller->set(array('debugToolbarPanels' => $vars, 'debugToolbarJavascript' => $this->javascript)); DebugTimer::start('controllerRender', __d('debug_kit', 'Render Controller Action')); DebugMemory::record(__d('debug_kit', 'Controller render start')); }
public function afterFind(Model $Model, $results, $primary = false) { if (CakePlugin::loaded('DebugKit')) { DebugTimer::start('data-copy-after-find', __d('data_copy', 'DataCopy: Running after find on %1$s with origin %2$s', $Model->alias, $Model->OriginModel->alias)); } $query = $Model->query; if (CakePlugin::loaded('DebugKit')) { DebugTimer::start('data-copy-list-old', __d('data_copy', 'DataCopy: Checking for old data from %1$s', $Model->alias)); } $oldestItems = array_map('strtotime', array_values($Model->find('list', array('fields' => array($Model->alias . '.' . $Model->primaryKey, $Model->alias . '.data_copy_modified'), 'order' => array($Model->alias . '.data_copy_modified' => 'ASC'), 'limit' => 10, 'copy' => true, 'callbacks' => false)))); if (CakePlugin::loaded('DebugKit')) { DebugTimer::stop('data-copy-list-old'); } $oldestData = null; foreach ($oldestItems as $oldestItemInArray) { if ($oldestItemInArray < $oldestData) { $oldestData = $oldestItemInArray; } } if ($query['copy'] === false) { DataCopyDebug::logExpiredLookup($Model, $Model->OriginModel, $query, __d('data_copy', 'Force update')); $results = false; } if ($query['copy'] === null && $oldestData !== null && time() - $oldestData > $this->settings[$Model->alias]['expire']) { DataCopyDebug::logExpiredLookup($Model, $Model->OriginModel, $query, __d('data_copy', 'Regular expire. Oldest data: %1$s', date('r', $oldestData))); $results = false; } if (is_array($results)) { DataCopyDebug::logLookup($Model, $Model->OriginModel, $query); if (CakePlugin::loaded('DebugKit')) { DebugTimer::stop('data-copy-after-find'); } return $results; } $Model->OriginModel->recursive = $Model->recursive; $queryData = $query; unset($queryData['conditions']); if (is_array($query['conditions'])) { foreach ($query['conditions'] as $field => $condition) { $queryData['conditions'][$this->convertField($Model, $field)] = $condition; } } if (is_array($query['order'][0])) { foreach ($query['order'][0] as $field => $direction) { unset($queryData['order'][0][$field]); $queryData['order'][$this->convertField($Model, $field)] = $direction; } } unset($queryData['order'][0]); if (is_array($queryData['fields'])) { foreach ($queryData['fields'] as $index => &$field) { $startQuote = isset($Model->getDataSource()->startQuote) ? $Model->getDataSource()->startQuote : null; $endQuote = isset($Model->getDataSource()->endQuote) ? $Model->getDataSource()->endQuote : null; $field = str_replace(array($startQuote, $endQuote), '', $field); $field = $this->convertField($Model, $field); if ($field === $Model->OriginModel->alias . '.data_copy_modified') { unset($queryData['fields'][$index]); } } } $originResults = $Model->OriginModel->find('all', $queryData); foreach ($originResults as $index => &$result) { $result[$Model->alias] = $result[$Model->OriginModel->alias]; unset($result[$Model->OriginModel->alias]); foreach ($result as $association => $data) { foreach ($data as $field => &$value) { $value = $this->convertValue($Model, $field, $value); $originResults[$index][$association][$field] = $value; } $originResults[$index][$association]['data_copy_modified'] = date($Model->getDataSource()->columns['datetime']['format']); } } foreach ($Model->getAssociated('belongsTo') as $association) { if (!isset($Model->belongsTo[$association]['origin'])) { continue; } $origin = $Model->belongsTo[$association]['origin']; foreach ($originResults as $index => &$result) { if (!isset($result[$origin])) { continue; } $data = $result[$origin]; unset($originResults[$index][$origin]); $originResults[$index][$association] = $data; } } if (CakePlugin::loaded('DebugKit')) { DebugTimer::start('data-copy-save-all', __d('data_copy', 'DataCopy: Saving data in %1$s from origin %2$s', $Model->alias, $Model->OriginModel->alias)); } $Model->saveAll($originResults, array('deep' => true)); if (CakePlugin::loaded('DebugKit')) { DebugTimer::stop('data-copy-save-all'); } if (!is_array($query['order'][0])) { $query['order'] = array(); } else { $query['order'] = $query['order'][0]; } $query['copy'] = true; $results = $Model->find('all', $query); if (CakePlugin::loaded('DebugKit')) { DebugTimer::stop('data-copy-after-find'); } return $results; }
/** * test getting all the set timers. * * @return void */ public function testGetTimers() { DebugTimer::start('test1', 'this is my first test'); DebugTimer::stop('test1'); usleep(50); DebugTimer::start('test2'); DebugTimer::stop('test2'); $timers = DebugTimer::getAll(); $this->assertEquals(3, count($timers)); $this->assertTrue(is_float($timers['test1']['time'])); $this->assertTrue(isset($timers['test1']['message'])); $this->assertTrue(isset($timers['test2']['message'])); }
/** * Stops a benchmarking timer. * * $name should be the same as the $name used in startTimer(). * * @param string $name The name of the timer to end. * @return boolean true if timer was ended, false if timer was not started. */ public static function stopTimer($name) { if (!Reveal::is('DebugKit.running')) { return; } DebugTimer::stop($name); }
/** * afterSave, stop the timer started from a save. * * @param \Model $Model The model. * @param string $created True if this save created a new record. * @param array $options The options. * @return bool Always true. */ public function afterSave(Model $Model, $created, $options = array()) { DebugTimer::stop($Model->alias . '_save'); return true; }
/** * Stop the DebugKitTimer. * * @param string $method Name of the method that has been called. * @return boolean Whether the DebugKitTimer has been stopped. */ public function stopTimer($method) { if (Configure::read('debug') == 0) { return false; } if ($this->_useDebugKit) { return DebugTimer::stop("soapQuery_{$method}"); } }