本文整理汇总了PHP中sfTimerManager::getTimers方法的典型用法代码示例。如果您正苦于以下问题:PHP sfTimerManager::getTimers方法的具体用法?PHP sfTimerManager::getTimers怎么用?PHP sfTimerManager::getTimers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sfTimerManager
的用法示例。
在下文中一共展示了sfTimerManager::getTimers方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: filterResponseContent
/**
* Listens to the response.filter_content event.
*
* @param sfEvent $event The sfEvent instance
* @param string $context The response content
*
* @return string The filtered response content
*/
public function filterResponseContent(sfEvent $event, $content)
{
if (!sfConfig::get('sf_web_debug')) {
return $content;
}
// log timers information
$messages = array();
foreach (sfTimerManager::getTimers() as $name => $timer) {
$messages[] = sprintf('%s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls());
}
$this->dispatcher->notify(new sfEvent($this, 'application.log', $messages));
// don't add debug toolbar:
// * for XHR requests
// * if 304
// * if not rendering to the client
// * if HTTP headers only
$response = $event->getSubject();
if (!$this->context->has('request') || !$this->context->has('response') || !$this->context->has('controller') || $this->context->getRequest()->isXmlHttpRequest() || strpos($response->getContentType(), 'html') === false || $response->getStatusCode() == 304 || $this->context->getController()->getRenderMode() != sfView::RENDER_CLIENT || $response->isHeaderOnly()) {
return $content;
}
// add needed assets for the web debug toolbar
$root = $this->context->getRequest()->getRelativeUrlRoot();
$assets = sprintf('
<script type="text/javascript" src="%s"></script>
<link rel="stylesheet" type="text/css" media="screen" href="%s" />', $root . sfConfig::get('sf_web_debug_web_dir') . '/js/main.js', $root . sfConfig::get('sf_web_debug_web_dir') . '/css/main.css');
$content = str_ireplace('</head>', $assets . '</head>', $content);
// add web debug information to response content
$webDebugContent = $this->webDebug->getResults();
$count = 0;
$content = str_ireplace('</body>', $webDebugContent . '</body>', $content, $count);
if (!$count) {
$content .= $webDebugContent;
}
return $content;
}
示例2: getPanelContent
public function getPanelContent()
{
if (sfTimerManager::getTimers()) {
$totalTime = $this->getTotalTime();
$panel = '<table class="sfWebDebugLogs" style="width: 300px"><tr><th>type</th><th>calls</th><th>time (ms)</th><th>time (%)</th></tr>';
foreach (sfTimerManager::getTimers() as $name => $timer) {
$panel .= sprintf('<tr><td class="sfWebDebugLogType">%s</td><td class="sfWebDebugLogNumber" style="text-align: right">%d</td><td style="text-align: right">%.2f</td><td style="text-align: right">%d</td></tr>', $name, $timer->getCalls(), $timer->getElapsedTime() * 1000, $totalTime ? $timer->getElapsedTime() * 1000 * 100 / $totalTime : 'N/A');
}
$panel .= '</table>';
return $panel;
}
}
示例3: getPanelContent
public function getPanelContent()
{
$panel = array();
$timers = sfTimerManager::getTimers();
if (sfConfig::get('sf_debug') && $timers) {
$totalTime = $this->getTotalTime();
$timer_nb = 1;
foreach ($timers as $name => $timer) {
array_push($panel, array('number' => $timer_nb, 'name' => $name, 'calls' => $timer->getCalls(), 'time' => $timer->getElapsedTime() * 1000, 'percent' => $totalTime ? $timer->getElapsedTime() * 1000 * 100 / $totalTime : 'N/A'));
$timer_nb++;
}
$panel['total'] = 'Total time: ' . $this->getTotalTime() . ' ms';
} else {
$panel['total'] = 'No info available';
}
return $panel;
}
示例4: sendTimers
protected function sendTimers()
{
$timers = sfTimerManager::getTimers();
$totalTime = $this->getTotalTime();
$panel = array();
$timer_nb = 1;
foreach ($timers as $name => $timer) {
array_push($panel, array('number' => $timer_nb, 'name' => $name, 'calls' => $timer->getCalls(), 'time' => $timer->getElapsedTime() * 1000, 'percent' => $totalTime ? $timer->getElapsedTime() * 1000 * 100 / $totalTime : 'N/A'));
$timer_nb++;
}
if (count($panel)) {
array_unshift($panel, array('', 'Type', 'Calls', 'Time(ms)', 'Time(%)'));
$this->sfFire->table('Timers ' . $this->getTotalTime() . ' ms', $panel);
} else {
$this->sfFire->group('Timers ' . $this->getTotalTime() . ' ms');
$this->sfFire->info('No info available');
$this->sfFire->groupEnd();
}
}
示例5: filterResponseContent
/**
* Listens to the response.filter_content event.
*
* @param sfEvent $event The sfEvent instance
* @param string $context The response content
*
* @return string The filtered response content
*/
public function filterResponseContent(sfEvent $event, $content)
{
// log timers information
$messages = array();
foreach (sfTimerManager::getTimers() as $name => $timer) {
$messages[] = sprintf('%s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls());
}
$this->dispatcher->notify(new sfEvent($this, 'application.log', $messages));
// don't add debug toolbar:
// * for XHR requests
// * if 304
// * if not rendering to the client
// * if HTTP headers only
$response = $event->getSubject();
$request = $this->context->getRequest();
if (!$this->context->has('request') || !$this->context->has('response') || !$this->context->has('controller') || $request->isXmlHttpRequest() || strpos($response->getContentType(), 'html') === false || $response->getStatusCode() == 304 || $this->context->getController()->getRenderMode() != sfView::RENDER_CLIENT || $response->isHeaderOnly()) {
return $content;
}
$webDebug = new $this->webDebugClass($this->dispatcher, $this, array('image_root_path' => ($request->getRelativeUrlRoot() ? $request->getRelativeUrlRoot() . '/' : '') . sfConfig::get('sf_web_debug_web_dir') . '/images'));
return $webDebug->injectToolbar($content);
}
示例6: execute
/**
* Executes this filter.
*
* @param sfFilterChain The filter chain.
*
* @throws <b>sfInitializeException</b> If an error occurs during view initialization
* @throws <b>sfViewException</b> If an error occurs while executing the view
*/
public function execute($filterChain)
{
// execute next filter
$filterChain->execute();
if (sfConfig::get('sf_logging_enabled')) {
$this->getContext()->getLogger()->info('{sfFilter} render to client');
}
// get response object
$response = $this->getContext()->getResponse();
// send headers
$response->sendHttpHeaders();
// send content
$response->sendContent();
// log timers information
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
$logger = $this->getContext()->getLogger();
foreach (sfTimerManager::getTimers() as $name => $timer) {
$logger->info(sprintf('{sfTimerManager} %s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls()));
}
}
}
示例7: getResults
/**
* Returns the web debug toolbar as HTML.
*
* @return string The web debug toolbar HTML
*/
public function getResults()
{
if (!sfConfig::get('sf_web_debug')) {
return '';
}
$this->loadHelpers();
$result = '';
// max priority
$maxPriority = '';
if (sfConfig::get('sf_logging_enabled')) {
$maxPriority = $this->getPriority($this->maxPriority);
}
$logs = '';
$sqlLogs = array();
if (sfConfig::get('sf_logging_enabled')) {
$logs = '<table class="sfWebDebugLogs">
<tr>
<th>#</th>
<th>type</th>
<th>message</th>
</tr>' . "\n";
$line_nb = 0;
foreach ($this->log as $logEntry) {
$log = $logEntry['message'];
$priority = $this->getPriority($logEntry['priority']);
if (strpos($type = $logEntry['type'], 'sf') === 0) {
$type = substr($type, 2);
}
// xdebug information
$debug_info = '';
if ($logEntry['debugStack']) {
$debug_info .= ' <a href="#" onclick="sfWebDebugToggle(\'debug_' . $line_nb . '\'); return false;">' . image_tag(sfConfig::get('sf_web_debug_web_dir') . '/images/toggle.gif') . '</a><div class="sfWebDebugDebugInfo" id="debug_' . $line_nb . '" style="display:none">';
foreach ($logEntry['debugStack'] as $i => $logLine) {
$debug_info .= '#' . $i . ' » ' . $this->formatLogLine($logLine) . '<br/>';
}
$debug_info .= "</div>\n";
}
// format log
$log = $this->formatLogLine($log);
// sql queries log
if (preg_match('/execute(?:Query|Update).+?\\:\\s+(.+)$/', $log, $match)) {
$sqlLogs[] .= $match[1];
}
++$line_nb;
$logs .= sprintf("<tr class='sfWebDebugLogLine sfWebDebug%s %s'><td class=\"sfWebDebugLogNumber\">%s</td><td class=\"sfWebDebugLogType\">%s %s</td><td>%s%s</td></tr>\n", ucfirst($priority), $logEntry['type'], $line_nb, image_tag(sfConfig::get('sf_web_debug_web_dir') . '/images/' . $priority . '.png'), $type, $log, $debug_info);
}
$logs .= '</table>';
ksort($this->types);
$types = array();
foreach ($this->types as $type => $nb) {
$types[] = '<a href="#" onclick="sfWebDebugToggleMessages(\'' . $type . '\'); return false;">' . $type . '</a>';
}
}
// ignore cache link
$cacheLink = '';
if (sfConfig::get('sf_debug') && sfConfig::get('sf_cache')) {
$selfUrl = $_SERVER['PHP_SELF'] . (strpos($_SERVER['PHP_SELF'], '_sf_ignore_cache') === false ? '?_sf_ignore_cache=1' : '');
$cacheLink = '<li><a href="' . $selfUrl . '" title="reload and ignore cache">' . image_tag(sfConfig::get('sf_web_debug_web_dir') . '/images/reload.png') . '</a></li>';
}
// logging information
$logLink = '';
if (sfConfig::get('sf_logging_enabled')) {
$logLink = '<li><a href="#" onclick="sfWebDebugShowDetailsFor(\'sfWebDebugLog\'); return false;">' . image_tag(sfConfig::get('sf_web_debug_web_dir') . '/images/comment.png') . ' logs & msgs</a></li>';
}
// database information
$dbInfo = '';
$dbInfoDetails = '';
if ($sqlLogs) {
$dbInfo = '<li><a href="#" onclick="sfWebDebugShowDetailsFor(\'sfWebDebugDatabaseDetails\'); return false;">' . image_tag(sfConfig::get('sf_web_debug_web_dir') . '/images/database.png') . ' ' . count($sqlLogs) . '</a></li>';
$dbInfoDetails = '
<div id="sfWebDebugDatabaseLogs">
<ol><li>' . implode("</li>\n<li>", $sqlLogs) . '</li></ol>
</div>
';
}
// memory used
$memoryInfo = '';
if (sfConfig::get('sf_debug') && function_exists('memory_get_usage')) {
$totalMemory = sprintf('%.1f', memory_get_usage() / 1024);
$memoryInfo = '<li>' . image_tag(sfConfig::get('sf_web_debug_web_dir') . '/images/memory.png') . ' ' . $totalMemory . ' KB</li>';
}
// total time elapsed
$timeInfo = '';
if (sfConfig::get('sf_debug')) {
$totalTime = (microtime(true) - sfConfig::get('sf_timer_start')) * 1000;
$totalTime = sprintf($totalTime <= 1 ? '%.2f' : '%.0f', $totalTime);
$timeInfo = '<li class="last"><a href="#" onclick="sfWebDebugShowDetailsFor(\'sfWebDebugTimeDetails\'); return false;">' . image_tag(sfConfig::get('sf_web_debug_web_dir') . '/images/time.png') . ' ' . $totalTime . ' ms</a></li>';
}
// timers
$timeInfoDetails = '<table class="sfWebDebugLogs" style="width: 300px"><tr><th>type</th><th>calls</th><th>time (ms)</th><th>time (%)</th></tr>';
foreach (sfTimerManager::getTimers() as $name => $timer) {
$timeInfoDetails .= sprintf('<tr><td class="sfWebDebugLogType">%s</td><td class="sfWebDebugLogNumber" style="text-align: right">%d</td><td style="text-align: right">%.2f</td><td style="text-align: right">%d</td></tr>', $name, $timer->getCalls(), $timer->getElapsedTime() * 1000, $timer->getElapsedTime() * 1000 * 100 / $totalTime);
}
$timeInfoDetails .= '</table>';
// logs
//.........这里部分代码省略.........
示例8: execute
public function execute($filterChain)
{
$filterChain->execute();
if (sfConfig::get('sf_logging_enabled')) {
$this->getContext()->getLogger()->info('{sfFilter} render to client');
}
$response = $this->getContext()->getResponse();
if (method_exists($response, 'sendHttpHeaders')) {
$response->sendHttpHeaders();
}
$response->sendContent();
if (sfConfig::get('sf_debug') && sfConfig::get('sf_logging_enabled')) {
$logger = $this->getContext()->getLogger();
foreach (sfTimerManager::getTimers() as $name => $timer) {
$logger->info(sprintf('{sfTimerManager} %s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls()));
}
}
}
示例9: filterResponseContent
/**
* Listens to the response.filter_content event.
*
* @param sfEvent $event The sfEvent instance
* @param string $content The response content
*
* @return string The filtered response content
*/
public function filterResponseContent(sfEvent $event, $content)
{
if (!sfConfig::get('sf_web_debug')) {
return $content;
}
// log timers information
$messages = array();
foreach (sfTimerManager::getTimers() as $name => $timer) {
$messages[] = sprintf('%s %.2f ms (%d)', $name, $timer->getElapsedTime() * 1000, $timer->getCalls());
}
$this->dispatcher->notify(new sfEvent($this, 'application.log', $messages));
// don't add debug toolbar:
// * for XHR requests
// * if response status code is in the 3xx range
// * if not rendering to the client
// * if HTTP headers only
$response = $event->getSubject();
$request = $this->context->getRequest();
if (null === $this->webDebug || !$this->context->has('request') || !$this->context->has('response') || !$this->context->has('controller') || $request->isXmlHttpRequest() || strpos($response->getContentType(), 'html') === false || '3' == substr($response->getStatusCode(), 0, 1) || $this->context->getController()->getRenderMode() != sfView::RENDER_CLIENT || $response->isHeaderOnly()) {
return $content;
}
return $this->webDebug->injectToolbar($content);
}
示例10: lime_test
<?php
/*
* This file is part of the symfony package.
* (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
*
* 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');
示例11: timersGetTotal
protected function timersGetTotal()
{
$timers = sfTimerManager::getTimers();
$total = 0;
foreach ($timers as $timer) {
$total += $timer->getElapsedTime();
}
return $total;
}
示例12: getResults
/**
* Returns the web debug toolbar as HTML.
*
* @return string The web debug toolbar HTML
*/
public function getResults()
{
if (!sfConfig::get('sf_web_debug')) {
return '';
}
$logPanel = array();
$configPanel = $this->getCurrentConfigAsArray();
$databasePanel = array();
$memoryPanel = array();
$timersPanel = array();
$this->loadHelpers();
$result = '';
// max priority
$maxPriority = '';
if (sfConfig::get('sf_logging_enabled')) {
$maxPriority = $this->getPriority($this->maxPriority);
}
$logData = array();
//Database Information
$sqlLogs = array();
if (sfConfig::get('sf_logging_enabled')) {
$line_nb = 0;
foreach ($this->log as $logEntry) {
$log = $logEntry['message'];
$priority = $this->getPriority($logEntry['priority']);
// xdebug information
$debug_info = array();
if (isset($logEntry['debug_stack'])) {
foreach ($logEntry['debug_stack'] as $i => $logLine) {
array_push($debug_info, array('line_nb' => $i, 'message' => $this->formatLogLine($logLine)));
}
}
// format log
$log = $this->formatLogLine($log);
// sql queries log
if (preg_match('/execute(?:Query|Update).+?\\:\\s+(.+)$/', $log, $match)) {
$queryLog = trim($match[1]);
preg_match('/(\\[.*\\])\\s?(.*)/', $queryLog, $queryMatches);
if (count($queryMatches) > 1) {
$sqlLogs[] = array('time' => isset($queryMatches[1]) ? $queryMatches[1] : '-', 'query' => isset($queryMatches[2]) ? $queryMatches[2] : '-');
} else {
$sqlLogs[] = array('time' => '-', 'query' => $queryLog);
}
}
++$line_nb;
$logData[] = array('line_nb' => $line_nb, 'priority' => $priority, 'type' => $logEntry['type'], 'message' => $log, 'debug_info' => $debug_info);
}
//end foreach
ksort($this->types);
$type_index = 0;
foreach ($this->types as $t => $n) {
$types[$type_index] = $t;
$type_index++;
}
$logPanel = array('logData' => $logData, 'types' => $types);
}
// ignore cache link and cache info
$cachePanel = array();
if (sfConfig::get('sf_debug') && sfConfig::get('sf_cache')) {
$cachePanel['reload_url'] = strpos($_SERVER['PHP_SELF'], '_sf_ignore_cache') === false ? '?_sf_ignore_cache=1' : '';
$cachePanel['cache_info'] = $this->cache_info;
}
// memory used
$memoryPanel = '';
if (sfConfig::get('sf_debug') && function_exists('memory_get_usage')) {
$totalMemory = sprintf('%.1f', memory_get_usage() / 1024);
$memoryPanel = $totalMemory . ' KB';
}
// total time elapsed
$totalTime = '';
if (sfConfig::get('sf_debug')) {
$totalTime = (microtime(true) - sfConfig::get('sf_timer_start')) * 1000;
$totalTime = sprintf($totalTime <= 1 ? '%.2f' : '%.0f', $totalTime);
}
$timersPanel = array();
//my timers
$timer_nb = 1;
foreach (sfTimerManager::getTimers() as $name => $timer) {
$timersPanel[] = array('number' => $timer_nb, 'name' => $name, 'calls' => $timer->getCalls(), 'time' => $timer->getElapsedTime() * 1000, 'percent' => $totalTime ? $timer->getElapsedTime() * 1000 * 100 / $totalTime : 'N/A');
$timer_nb++;
}
$timersPanel['total'] = 'Total time: ' . $totalTime . ' ms';
$panels = array();
$panels['config'] = array('title' => 'Configuration and request variables', 'content' => $configPanel);
$panels['cache'] = array('title' => 'reload and ignore cache', 'content' => $cachePanel);
$panels['logs'] = array('title' => 'Logs & Messages', 'content' => $logPanel);
$panels['memory'] = array('title' => 'Memory usage', 'content' => $memoryPanel);
$panels['timer'] = array('title' => 'Timers', 'content' => $timersPanel);
$panels['database'] = array('title' => 'Database information', 'content' => $sqlLogs);
$panels['info'] = array('title' => 'Information', 'content' => $this->getInfoPanel());
if (function_exists('json_encode')) {
return "<script type=\"text/javascript\"> //<![CDATA[ \n FireSymfonyDebugData = " . json_encode($panels) . "\n //]]></script>";
} else {
throw new fsNoJsonException("To use FireSymfony you need to enable the json php extension.");
}
//.........这里部分代码省略.........