| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfWebDebugPanelTimer extends sfWebDebugPanel |
|---|
| 20 |
{ |
|---|
| 21 |
static protected |
|---|
| 22 |
$startTime = null; |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
* Constructor. |
|---|
| 26 |
* |
|---|
| 27 |
* @param sfWebDebug $webDebug The web debut 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 !is_null(self::$startTime); |
|---|
| 84 |
} |
|---|
| 85 |
|
|---|
| 86 |
protected function getTotalTime() |
|---|
| 87 |
{ |
|---|
| 88 |
return !is_null(self::$startTime) ? sprintf('%.0f', (microtime(true) - self::$startTime) * 1000) : 0; |
|---|
| 89 |
} |
|---|
| 90 |
} |
|---|
| 91 |
|
|---|