1. sfWebDebugPanelTimer.class.php
  2. /** * sfWebDebugPanelTimer adds a panel to the web debug toolbar with timer information. * * @package symfony * @subpackage debug * @author Fabien Potencier * @version SVN: $Id: sfWebDebugPanelTimer.class.php 22955 2009-10-12 16:44:07Z Kris.Wallsmith $ */
  3. class sfWebDebugPanelTimer extends sfWebDebugPanel
  4. {
  5. static protected
  6. $startTime = null;
  7. /**
  8. * Constructor.
  9. *
  10. * @param sfWebDebug $webDebug The web debug toolbar instance
  11. */
  12. public function __construct(sfWebDebug $webDebug)
  13. {
  14. parent::__construct($webDebug);
  15. $this->webDebug->getEventDispatcher()->connect('debug.web.filter_logs', array($this, 'filterLogs'));
  16. }
  17. public function getTitle()
  18. {
  19. return '<img src="'.$this->webDebug->getOption('image_root_path').'/time.png" alt="Time" /> '.$this->getTotalTime().' ms';
  20. }
  21. public function getPanelTitle()
  22. {
  23. return 'Timers';
  24. }
  25. public function getPanelContent()
  26. {
  27. if (sfTimerManager::getTimers())
  28. {
  29. $totalTime = $this->getTotalTime();
  30. $panel = '<table class="sfWebDebugLogs" style="width: 300px"><tr><th>type</th><th>calls</th><th>time (ms)</th><th>time (%)</th></tr>';
  31. foreach (sfTimerManager::getTimers() as $name => $timer)
  32. {
  33. $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');
  34. }
  35. $panel .= '</table>';
  36. return $panel;
  37. }
  38. }
  39. public function filterLogs(sfEvent $event, $logs)
  40. {
  41. $newLogs = array();
  42. foreach ($logs as $log)
  43. {
  44. if ('sfWebDebugLogger' != $log['type'])
  45. {
  46. $newLogs[] = $log;
  47. }
  48. }
  49. return $newLogs;
  50. }
  51. static public function startTime()
  52. {
  53. self::$startTime = microtime(true);
  54. }
  55. static public function isStarted()
  56. {
  57. return null !== self::$startTime;
  58. }
  59. protected function getTotalTime()
  60. {
  61. return null !== self::$startTime ? sprintf('%.0f', (microtime(true) - self::$startTime) * 1000) : 0;
  62. }
  63. }

Debug toolbar