3

I have a portal made with Symfony 3.4 and Sonata Admin.

In a specific admin page there are a lot of generated queries. I used the profiler to track them down but I cannot see where they generated from:

enter image description here

There is the same query repeated a lot of times with different IDs:

enter image description here

Is there a way to understand where they are generated? I saw that post and it seems impossible to do at the moment:

https://github.com/doctrine/DoctrineBundle/issues/722

Can't I just drop a dump/die somewhere in the profiler to get the specific line?

StockBreak
  • 2,857
  • 1
  • 35
  • 61

4 Answers4

8

Since v1.11.0, Doctrine Bundle can display query backtrace in Symfony Profiler. This is may be helpful to find what code caused the specific query to be executed.

The feature is disabled by default but you can enable it using profiling_collect_backtrace configuration in your doctrine connection settings.

See https://symfony.com/blog/new-in-doctrinebundle-1-11-0#store-backtraces-when-profiling-queries for more information.

  • If anyone else has tried turning this on, only for it to make no apparent difference, try clearing your symfony cache and trying again :) – Matt Gibson Jun 12 '21 at 16:17
4

I just found this plugin which is doing exactly what I need:

https://github.com/VincentChalnot/DoctrineDebugBundle

enter image description here

It seems to work fine and it's showing the stack trace from the query.

StockBreak
  • 2,857
  • 1
  • 35
  • 61
1

Is not an easy enought task, but I think that you can obtain some hints with the debug log info, the doctrine queries and the execution timeline.

enter image description here

In the timeline you can see when the doctrine execute a query, and with the info from Doctrine and debug you can join the execution time and the executed query.

I hope this info can help you

Jose M. González
  • 12,590
  • 1
  • 13
  • 9
0

It looks like there is no easy way to track query initiators but I found the following post explaining why you may see multiple similar queries: Doctrine2 in Symfony2: How can I see which object-call leads into a query?

EmilCataranciuc
  • 1,024
  • 1
  • 11
  • 24