Development

/branches/1.3/lib/debug/sfWebDebugPanelTimer.class.php

You must first sign up to be able to contribute.

root/branches/1.3/lib/debug/sfWebDebugPanelTimer.class.php

Revision 22955, 2.4 kB (checked in by Kris.Wallsmith, 5 years ago)

[1.3] enhanced propel WDT, fixed some typos (refs #7139)

  • Property svn:mime-type set to text/x-php
  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
Line 
1 <?php
2
3 /*
4  * This file is part of the symfony package.
5  * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
6  *
7  * For the full copyright and license information, please view the LICENSE
8  * file that was distributed with this source code.
9  */
10
11 /**
12  * sfWebDebugPanelTimer adds a panel to the web debug toolbar with timer information.
13  *
14  * @package    symfony
15  * @subpackage debug
16  * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17  * @version    SVN: $Id$
18  */
19 class sfWebDebugPanelTimer extends sfWebDebugPanel
20 {
21   static protected
22     $startTime = null;
23
24   /**
25    * Constructor.
26    *
27    * @param sfWebDebug $webDebug The web debug toolbar instance
28    */
29   public function __construct(sfWebDebug $webDebug)
30   {
31     parent::__construct($webDebug);
32
33     $this->webDebug->getEventDispatcher()->connect('debug.web.filter_logs', array($this, 'filterLogs'));
34   }
35
36   public function getTitle()
37   {
38     return '<img src="'.$this->webDebug->getOption('image_root_path').'/time.png" alt="Time" /> '.$this->getTotalTime().' ms';
39   }
40
41   public function getPanelTitle()
42   {
43     return 'Timers';
44   }
45
46   public function getPanelContent()
47   {
48     if (sfTimerManager::getTimers())
49     {
50       $totalTime = $this->getTotalTime();
51       $panel = '<table class="sfWebDebugLogs" style="width: 300px"><tr><th>type</th><th>calls</th><th>time (ms)</th><th>time (%)</th></tr>';
52       foreach (sfTimerManager::getTimers() as $name => $timer)
53       {
54         $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');
55       }
56       $panel .= '</table>';
57
58       return $panel;
59     }
60   }
61
62   public function filterLogs(sfEvent $event, $logs)
63   {
64     $newLogs = array();
65     foreach ($logs as $log)
66     {
67       if ('sfWebDebugLogger' != $log['type'])
68       {
69         $newLogs[] = $log;
70       }
71     }
72
73     return $newLogs;
74   }
75
76   static public function startTime()
77   {
78     self::$startTime = microtime(true);
79   }
80
81   static public function isStarted()
82   {
83     return null !== self::$startTime;
84   }
85
86   protected function getTotalTime()
87   {
88     return null !== self::$startTime ? sprintf('%.0f', (microtime(true) - self::$startTime) * 1000) : 0;
89   }
90 }
91
Note: See TracBrowser for help on using the browser.