11

To check all queries by a specific piece of code I am using:

  1. Modify from protected to public the variable $_debug in Varien_Db_Adapter_Pdo_Mysql

  2. Do the same for $_logAllQueries

  3. Add this before code executes:

    $adapter = Mage::getSingleton('core/resource')->getConnection('core_write');
    $adapter->_debug = true;
    $adapter->_logAllQueries = true;
    
  4. Add this after the code

    $adapter->_debug = false;
    $adapter->_logAllQueries = false;
    

    so your final code will look like this:

    $adapter = Mage::getSingleton('core/resource')->getConnection('core_write');
    $adapter->_debug = true;
    $adapter->_logAllQueries = true;
    
    Mage::getModel('catalog/product')->load(1);
    
    $adapter->_debug = false;
    $adapter->_logAllQueries = false;
    

Is there any other more elegant solution?

1

3 Answers 3

1

You can use a variation of my answer at How do I print all the queries in Magento?

Instead of activating the profiler globally in local.xml, add these before and after the code you want to test:

$profiler = Mage::getSingleton('core/resource')->getConnection('core_write')->getProfiler();
$profiler->setEnabled(true);

// ...

Mage::log(print_r($profiler->getQueryProfiles(), true), null, 'queries.log', true);
$profiler->setEnabled(false);

Then you will find the queries in var/log/queries.log

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, @fschmengler, this is what I was looking for! Best, R
1

There is an extension available for Magento which i am personally using from long time (works for Community as well as EE) :

https://github.com/madalinoprea/magneto-debug

This will let you - Check all requests - See all SQL queries executed for a request - See all layout handles executed - and many more

1 Comment

Hi, I am using magneto-debug, a forked patched version, while Madalin Oprea does not accept any pull requests from a while. Is good, but not exactly for a specific piece of code. Thanks, R
0

You may simply open the MySQL Log file and monitor the logged queries while requesting the page, If you are using Linux for example, use the command tail -F to view all the changes on the log file in a live way.

Try this for example on debian: tail-F /var/log/mysql.log

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.