Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 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: sfWebDebugPanelTimer.class.php 22955 2009-10-12 16:44:07Z Kris.Wallsmith $
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
}