I enable the devel module and set it to Display query log.

Then on every page load I get a list of the generated sql queries. You can see an example of that list in the capture I uploaded. So far so good.

Is there any way to know which module is responsible for each database queries (in case that the query is generated by a module)?

If this is not possible. Is there any way to do an analysis of all enabled modules to see how them are affecting the general performance of the site?

enter image description here

1 Answer 1


For any modules you download from drupal.org, you can click on the function link within the where column and it will direct you to api.drupal.org and you can see the module there.

I couldn't find any settings that would enable showing where the call originated (file path) if the module wasn't an 'official' contrib. A little digging and you can find the information within the devel.module. Specifically, devel_query_table() receives $queries as its first argument. $queries contains the rows that will be displayed and it does have the file path.

I created a quick patch to test this (Doing this does not imply that i think you should modify contrib modules in a production environment):

diff --git a/sites/all/modules/devel/devel.module b/sites/all/modules/devel/devel.module
index 0ebdef4..dd6aaa8 100644
--- a/sites/all/modules/devel/devel.module
+++ b/sites/all/modules/devel/devel.module
@@ -1482,7 +1482,7 @@ function _devel_print_object($obj, $prefix = NULL, $parents = NULL, $object = FA
 function devel_query_table($queries, $counts) {
   $version = devel_get_core_version(VERSION);
 -  $header = array ('ms', '#', 'where', 'ops', 'query', 'target');
 +  $header = array ('ms', '#', 'what', 'ops', 'query', 'target', 'where');
    $i = 0;
   $api = variable_get('devel_api_url', 'api.drupal.org');
   foreach ($queries as $query) {
 @@ -1514,7 +1514,8 @@ function devel_query_table($queries, $counts) {
   'id' => "devel-query-$i",
   'data' => $placeholders . $args . $explain,
 -    $cell[$i][] = $query['target'];
 +    $cell[$i][] = $query['target'];    
 +    $cell[$i][] = '<div style="overflow-x:scroll">' . check_plain($query['caller']['file']) . '</div>';
     unset($diff, $count, $ops);

Here is the raw output on pastebin: http://pastebin.com/Ww5CkQsL

And a screenshot of the un-styled results:

enter image description here

This is a little rough looking as there are style sheets involved, but it gets the information.

Even better would be if the where column builder checked for the availability of the function on d.o but I'll digress, as I feel we may be entering, 'file an issue (feature request)' territory.

  • I tried to use the patch but I get this error message: git apply -v devel-module-queries.patch devel-module-queries.patch:10: trailing whitespace. $header = array ('ms', '#', 'what', 'ops', 'query', 'target', 'where'); devel-module-queries.patch:19: trailing whitespace. $cell[$i][] = $query['target']; devel-module-queries.patch:20: trailing whitespace. $cell[$i][] = '<div style="overflow-x:scroll">' . check_plain($query['caller']['file']) . '</div>'; fatal: corrupt patch at line 23
    – chefnelone
    Commented Aug 12, 2013 at 15:51
  • Must just be whitespace from copying/pasting, try this one, which I was able to just apply cleanly: pastebin.com/E16gT1w0. Commented Aug 12, 2013 at 17:09
  • Same, I get the trailing whitespace errors. Can you post a link to the patch file?
    – chefnelone
    Commented Aug 14, 2013 at 7:25
  • I've got the patch applied.
    – chefnelone
    Commented Aug 14, 2013 at 13:41
  • It works fine. Very useful. I was able to find a module which was causing lots of queries. Many thanks Chris.
    – chefnelone
    Commented Aug 14, 2013 at 13:51

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.