/** * @param $event * @param $parameters * * @return mixed|void */ public function emit($event, $parameters) { self::$depth++; $this->stopwatch->openSection(); if (isset($this->callbacks[$event])) { if (!$this->callbacks[$event][0]) { usort($this->callbacks[$event][1], function ($A, $B) { if ($A[0] == $B[0]) { return 0; } return $A[0] > $B[0] ? 1 : -1; }); $this->callbacks[$event][0] = true; } foreach ($this->callbacks[$event][1] as $item) { $name = $this->getCallableName($item[1]); $this->stopwatch->start($name); $diagnoseEvent = Event::create()->setEvent($event)->setCallback($name)->setDepth(self::$depth); $this->events[] = $diagnoseEvent; call_user_func_array($item[1], $this->buildParameters($parameters)); $stopwatchEvent = $this->stopwatch->stop($name); $diagnoseEvent->setDuration($stopwatchEvent->getDuration())->setMemory($stopwatchEvent->getMemory()); } } $this->stopwatch->stopSection($event); self::$depth--; }
/** * Fixes all files for the given finder. * * @param ConfigInterface $config A ConfigInterface instance * @param bool $dryRun Whether to simulate the changes or not * @param bool $diff Whether to provide diff * * @return array */ public function fix(ConfigInterface $config, $dryRun = false, $diff = false) { $changed = array(); $fixers = $config->getFixers(); $this->stopwatch->openSection(); $fileCacheManager = new FileCacheManager($config->usingCache(), $config->getCacheFile(), $config->getRules()); $processed = array(); foreach ($config->getFinder() as $file) { $name = $this->getFileRelativePathname($file); if (in_array($name, $processed, true)) { continue; } $processed[] = $name; if ($file->isDir() || $file->isLink()) { continue; } $this->stopwatch->start($this->getFileRelativePathname($file)); if ($fixInfo = $this->fixFile($file, $fixers, $dryRun, $diff, $fileCacheManager)) { $changed[$name] = $fixInfo; } $this->stopwatch->stop($this->getFileRelativePathname($file)); } $this->stopwatch->stopSection('fixFile'); return $changed; }
/** * Fixes all files for the given finder. * * @param ConfigInterface $config A ConfigInterface instance * @param bool $dryRun Whether to simulate the changes or not * @param bool $diff Whether to provide diff * * @return array */ public function fix(ConfigInterface $config, $dryRun = false, $diff = false) { $fixers = $this->prepareFixers($config); $changed = array(); if ($this->stopwatch) { $this->stopwatch->openSection(); } $fileCacheManager = new FileCacheManager($config->usingCache(), $config->getDir()); foreach ($config->getFinder() as $file) { if ($file->isDir()) { continue; } if ($this->stopwatch) { $this->stopwatch->start($this->getFileRelativePathname($file)); } if ($fixInfo = $this->fixFile($file, $fixers, $dryRun, $diff, $fileCacheManager)) { $changed[$this->getFileRelativePathname($file)] = $fixInfo; } if ($this->stopwatch) { $this->stopwatch->stop($this->getFileRelativePathname($file)); } } if ($this->stopwatch) { $this->stopwatch->stopSection('fixFile'); } return $changed; }
/** * Fixes all files for the given finder. * * @param ConfigInterface $config A ConfigInterface instance * @param bool $dryRun Whether to simulate the changes or not * @param bool $diff Whether to provide diff * * @return array */ public function fix(ConfigInterface $config, $dryRun = false, $diff = false) { $fixers = $this->prepareFixers($config); $fixers = $this->sortFixers($fixers); $changed = array(); if ($this->stopwatch) { $this->stopwatch->openSection(); } $fileCacheManager = new FileCacheManager($config->usingCache(), $config->getDir(), $fixers); $finder = $config->getFinder(); $finderIterator = $finder instanceof \IteratorAggregate ? $finder->getIterator() : $finder; foreach (new UniqueFileIterator($finderIterator) as $file) { if ($this->stopwatch) { $this->stopwatch->start($this->getFileRelativePathname($file)); } if ($fixInfo = $this->fixFile($file, $fixers, $dryRun, $diff, $fileCacheManager)) { $changed[$this->getFileRelativePathname($file)] = $fixInfo; } if ($this->stopwatch) { $this->stopwatch->stop($this->getFileRelativePathname($file)); } } if ($this->stopwatch) { $this->stopwatch->stopSection('fixFile'); } return $changed; }
public function testReopenASection() { $stopwatch = new Stopwatch(); $stopwatch->openSection(); $stopwatch->start('foo', 'cat'); $stopwatch->stopSection('section'); $stopwatch->openSection('section'); $stopwatch->start('bar', 'cat'); $stopwatch->stopSection('section'); $events = $stopwatch->getSectionEvents('section'); $this->assertCount(3, $events); $this->assertCount(2, $events['__section__']->getPeriods()); }
<?php require_once 'vendor/autoload.php'; require_once 'functions.php'; use Symfony\Component\Stopwatch\Stopwatch; $stopwatch = new Stopwatch(); $stopwatch->openSection(); $stopwatch->start('do_phase_1'); doSomeFunction(); $stopwatch->stopSection('step1'); $stopwatch->openSection(); $stopwatch->start('do_phase_1'); $totalLap = 10; for ($count = 0; $count < $totalLap; $count++) { doSomeFunction(); $stopwatch->lap('do_phase_1'); } $stopwatch->stopSection('step2'); echo '<p>Step 1 :</p>'; $events_1 = $stopwatch->getSectionEvents('step1'); echo '<ul>'; foreach ($events_1 as $id => $event) { echo '<li> phase ' . $id . ':' . $event->getDuration() . '</li>'; } echo '</ul>'; echo '<p>Step 2 :</p>'; $events_2 = $stopwatch->getSectionEvents('step2'); echo '<ul>'; foreach ($events_2 as $id => $event) { echo '<li> phase ' . $id . ':' . $event->getDuration() . '</li>'; }