123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- <?php
- namespace Symfony\Component\Stopwatch;
- class Stopwatch
- {
-
- private $sections;
-
- private $activeSections;
- public function __construct()
- {
- $this->sections = $this->activeSections = array('__root__' => new Section(null));
- }
-
- public function getSections()
- {
- return $this->sections;
- }
-
- public function openSection($id = null)
- {
- $current = end($this->activeSections);
- if (null !== $id && null === $current->get($id)) {
- throw new \LogicException(sprintf('The section "%s" has been started at an other level and can not be opened.', $id));
- }
- $this->start('__section__.child', 'section');
- $this->activeSections[] = $current->open($id);
- $this->start('__section__');
- }
-
- public function stopSection($id)
- {
- $this->stop('__section__');
- if (1 == \count($this->activeSections)) {
- throw new \LogicException('There is no started section to stop.');
- }
- $this->sections[$id] = array_pop($this->activeSections)->setId($id);
- $this->stop('__section__.child');
- }
-
- public function start($name, $category = null)
- {
- return end($this->activeSections)->startEvent($name, $category);
- }
-
- public function isStarted($name)
- {
- return end($this->activeSections)->isEventStarted($name);
- }
-
- public function stop($name)
- {
- return end($this->activeSections)->stopEvent($name);
- }
-
- public function lap($name)
- {
- return end($this->activeSections)->stopEvent($name)->start();
- }
-
- public function getEvent($name)
- {
- return end($this->activeSections)->getEvent($name);
- }
-
- public function getSectionEvents($id)
- {
- return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : array();
- }
- }
|