-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* initial work on a profiler extension * sort service definition alphabetically * fix php code style * fixed type annotations * removed obsolete ProfilerDisabler * added test for FixtureReferenceResolver * cs fix * Apply suggestions from code review Co-authored-by: Jacob Dreesen <[email protected]> * load profiler extension only when in dev env --------- Co-authored-by: Luka Dschaak <[email protected]> Co-authored-by: Jacob Dreesen <[email protected]>
- Loading branch information
1 parent
5c080fa
commit e49bd1e
Showing
17 changed files
with
629 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\FixtureBundle\Profiler\DataCollector; | ||
|
||
use Neusta\Pimcore\FixtureBundle\Profiler\FixtureReference\FixtureReference; | ||
use Neusta\Pimcore\FixtureBundle\Profiler\FixtureReference\FixtureReferenceResolver; | ||
use Neusta\Pimcore\FixtureBundle\Profiler\PerformanceInfo\PerformanceInfo; | ||
use Neusta\Pimcore\FixtureBundle\Profiler\Timing\TimingCollector; | ||
use Symfony\Bundle\FrameworkBundle\DataCollector\AbstractDataCollector; | ||
use Symfony\Component\HttpFoundation\Request; | ||
use Symfony\Component\HttpFoundation\Response; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class FixtureLoaderCollector extends AbstractDataCollector | ||
{ | ||
public function __construct( | ||
private readonly FixtureReferenceResolver $fixtureReferenceResolver, | ||
private readonly TimingCollector $timingCollector, | ||
) { | ||
} | ||
|
||
public function collect(Request $request, Response $response, ?\Throwable $exception = null): void | ||
{ | ||
$this->data['timings'] = $this->timingCollector->getAll(); | ||
|
||
$this->data['references'] = $this->fixtureReferenceResolver->getRootReferences(); | ||
} | ||
|
||
public static function getTemplate(): ?string | ||
{ | ||
return '@NeustaPimcoreFixture/data_collector/template.html.twig'; | ||
} | ||
|
||
/** | ||
* @return list<FixtureReference> | ||
*/ | ||
public function getDependencyFreeFixtures(): array | ||
{ | ||
return $this->data['references']; | ||
} | ||
|
||
public function getTiming(FixtureReference $fixtureReference): PerformanceInfo | ||
{ | ||
return $this->data['timings'][$fixtureReference->getName()]; | ||
} | ||
|
||
/** | ||
* @return array<class-string, PerformanceInfo> | ||
*/ | ||
public function getTimings(): array | ||
{ | ||
return $this->data['timings']; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/Profiler/EventListener/FixtureDependencyGraphSubscriber.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\FixtureBundle\Profiler\EventListener; | ||
|
||
use Neusta\Pimcore\FixtureBundle\Event\AfterLoadFixtures; | ||
use Neusta\Pimcore\FixtureBundle\Event\BeforeExecuteFixture; | ||
use Neusta\Pimcore\FixtureBundle\Fixture\Fixture; | ||
use Neusta\Pimcore\FixtureBundle\Profiler\FixtureReference\FixtureReferenceResolver; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class FixtureDependencyGraphSubscriber implements EventSubscriberInterface | ||
{ | ||
/** @var list<Fixture> */ | ||
private array $loadedFixtures = []; | ||
|
||
public function __construct( | ||
private readonly FixtureReferenceResolver $fixtureReferenceResolver, | ||
) { | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
BeforeExecuteFixture::class => ['beforeExecuteFixture', 10], | ||
AfterLoadFixtures::class => 'afterLoadFixtures', | ||
]; | ||
} | ||
|
||
public function beforeExecuteFixture(BeforeExecuteFixture $event): void | ||
{ | ||
$this->loadedFixtures[] = $event->fixture; | ||
} | ||
|
||
public function afterLoadFixtures(): void | ||
{ | ||
$this->fixtureReferenceResolver->setFixtures($this->loadedFixtures); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\FixtureBundle\Profiler\EventListener; | ||
|
||
use Neusta\Pimcore\FixtureBundle\Event\AfterExecuteFixture; | ||
use Neusta\Pimcore\FixtureBundle\Event\BeforeExecuteFixture; | ||
use Neusta\Pimcore\FixtureBundle\Profiler\Timing\Timing; | ||
use Neusta\Pimcore\FixtureBundle\Profiler\Timing\TimingCollector; | ||
use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class TimingSubscriber implements EventSubscriberInterface | ||
{ | ||
public function __construct( | ||
private readonly Timing $timing, | ||
private readonly TimingCollector $timingCollector, | ||
) { | ||
} | ||
|
||
public static function getSubscribedEvents(): array | ||
{ | ||
return [ | ||
BeforeExecuteFixture::class => 'beforeExecuteFixture', | ||
AfterExecuteFixture::class => 'afterExecuteFixture', | ||
]; | ||
} | ||
|
||
public function beforeExecuteFixture(BeforeExecuteFixture $event): void | ||
{ | ||
$this->timing->beforeExecuteFixture($event->fixture); | ||
} | ||
|
||
public function afterExecuteFixture(AfterExecuteFixture $event): void | ||
{ | ||
$this->timing->afterExecuteFixture($event->fixture); | ||
|
||
$this->timingCollector->add($event->fixture, $this->timing->getPerformanceInfo($event->fixture)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php declare(strict_types=1); | ||
|
||
namespace Neusta\Pimcore\FixtureBundle\Profiler\FixtureReference; | ||
|
||
use Neusta\Pimcore\FixtureBundle\Fixture\Fixture; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class FixtureReference | ||
{ | ||
/** @var class-string */ | ||
private string $fixtureFqcn; | ||
|
||
/** @var list<FixtureReference> */ | ||
private array $dependencies = []; | ||
|
||
/** @var list<FixtureReference> */ | ||
private array $dependants = []; | ||
|
||
public function __construct(Fixture $fixture) | ||
{ | ||
$this->fixtureFqcn = $fixture::class; | ||
} | ||
|
||
/** | ||
* @return class-string | ||
*/ | ||
public function getName(): string | ||
{ | ||
return $this->fixtureFqcn; | ||
} | ||
|
||
public function addDependencyReference(self $dependency): void | ||
{ | ||
$this->dependencies[] = $dependency; | ||
} | ||
|
||
public function addDependantReference(self $fixtureReference): void | ||
{ | ||
$this->dependants[] = $fixtureReference; | ||
} | ||
|
||
/** | ||
* @return list<FixtureReference> | ||
*/ | ||
public function getDependencies(): array | ||
{ | ||
return $this->dependencies; | ||
} | ||
|
||
public function hasDependencies(): bool | ||
{ | ||
return !empty($this->dependencies); | ||
} | ||
|
||
/** | ||
* @return list<FixtureReference> | ||
*/ | ||
public function getDependants(): array | ||
{ | ||
return $this->dependants; | ||
} | ||
|
||
public function hasDependants(): bool | ||
{ | ||
return !empty($this->dependants); | ||
} | ||
} |
Oops, something went wrong.