debesha/doctrine-hydration-profiler-bundle
Installation:
composer require debesha/doctrine-hydration-profiler-bundle
Add the bundle to config/bundles.php (Symfony 5.4+ auto-discovers it, but explicit declaration ensures compatibility):
return [
// ...
Debesha\DoctrineProfileExtraBundle\DoctrineProfileExtraBundle::class => ['all' => true],
];
Enable Profiler:
Ensure Symfony's profiler is enabled in config/packages/dev/profiler.yaml:
framework:
profiler: { only_exceptions: false }
First Use Case:
php bin/console server:run)./_profiler and inspect the "Doctrine Hydration" tab./_profiler/{token}?panel=doctrine_hydrationconfig/packages/dev/doctrine_profile_extra.yaml (if needed).loadClassMetadata and postLoad events.Debugging Slow Queries:
HYDRATE_ARRAY vs. HYDRATE_OBJECT).HYDRATE_ARRAY may take 500ms—switching to HYDRATE_OBJECT could reduce this to 100ms.Performance Profiling:
Integration with Custom Logic:
DoctrineHydrationEvent).use Debesha\DoctrineProfileExtraBundle\Event\DoctrineHydrationEvent;
public function onHydration(DoctrineHydrationEvent $event) {
if ($event->getDuration() > 100) { // ms
$this->monitoringClient->logWarning($event->getEntityClass(), $event->getDuration());
}
}
Conditional Profiling:
enabled config:
doctrine_profile_extra:
enabled: false # Disable in prod
HYDRATE_SCALAR for simple queries to avoid hydration overhead.php bin/console cache:clear) after enabling the bundle.ResultSetMapping), ensure they’re compatible with the profiler’s instrumentation.Overhead in Development:
doctrine_profile_extra:
enabled: '%kernel.debug%' # Only in dev
Missing Data:
postLoad listeners).config/bundles.php).DoctrineProfileExtraBundle to config/bundles.php explicitly.EntityManager-Specific Data:
EntityManager. For multi-EM setups, data may be split across tabs.Hydration Modes:
HYDRATE_ARRAY and HYDRATE_SCALAR are profiled, but HYDRATE_OBJECT may show higher times due to entity lifecycle callbacks.monolog:
handlers:
main:
level: debug
channels: ["doctrine"]
DoctrineHydrationEvent to inspect raw data:
$event->getHydrationData(); // Array of all hydration records.
/profiler/{token}?panel=doctrine) for query-level insights.Custom Data Collectors:
HydrationDataCollector to add custom metrics (e.g., memory usage):
use Debesha\DoctrineProfileExtraBundle\DataCollector\HydrationDataCollector;
class CustomHydrationDataCollector extends HydrationDataCollector {
public function collect($data) {
$data['memory_usage'] = memory_get_usage();
return parent::collect($data);
}
}
Event Listeners:
DoctrineHydrationEvent to modify or enrich hydration data:
$event->addMetadata('custom_tag', 'value');
Template Overrides:
templates/bundles/DoctrineProfileExtra/doctrine_hydration.html.twig
^2.19|^3.0. For older versions, check compatibility.Proxy\__CG__\User) may show as separate entries.How can I help you explore Laravel packages today?