Vitalii Lebediev
Vitalii Lebediev

Reputation: 662

Is it possible to profile Zend_Table queries?

I'm looking for a way to profile queries which are performed internally by Zend_Table.
For example, after you finish Quickstart course, how to profile all the queries that are performed ?
I've tried to enable profiler from application.ini like this:

resources.db.profiler.class   = "Zend_Db_Profiler_Firebug"
resources.db.profiler.enabled = true

And placed next rows in a Guestbook controller:

...
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$profiler = $db->getProfiler();

echo $profiler->getTotalElapsedSecs();

Which gives me 0

I've also tried to enable profiler in a Bootstrap file like this:

protected function _initProfiler() {
    $this->bootstrap("db");
    $profiler = new Zend_Db_Profiler_Firebug("All DB Queries");
    $profiler->setEnabled(true);
    Zend_Registry::get("db")->setProfiler($profiler);
}

Whick doesn't give me any result (I've installed and tested Firebug and FirePHP, using Zend_Log_Writer_Firebug())

I will appreciate any help. Thanks !

Upvotes: 0

Views: 1874

Answers (2)

Vitalii Lebediev
Vitalii Lebediev

Reputation: 662

The problem was in the parameters instantiation. When I've entered

resources.db.params.profiler.class   = "Zend_Db_Profiler_Firebug"
resources.db.params.profiler.enabled = true

instead of previous configuration, everything went fine. Note .params section of the parameter lines

Upvotes: 1

RockyFord
RockyFord

Reputation: 8519

I've not tried the Firebug profiler. But I do use a html table to output profiler info at the bottom of each page that does a query.

enable profiler in application.ini

resources.db.params.profiler = true

render the profile results in the layout:

<?php
    $this->addScriptPath(APPLICATION_PATH . '/views/scripts');
    echo $this->render('profiler.phtml')
?>

profiler.phtml the view to render

<?php
// get the default db adapter
$adapter = Zend_Db_Table::getDefaultAdapter();
$profiler = $adapter->getProfiler();
if ($profiler->getEnabled() && $profiler->getTotalNumQueries() > 0) :
?>
    <div style='text-align:center'>
        <h2>Database Profiling Report</h2>
        <p>Total queries executed: <?php echo $profiler->getTotalNumQueries() ?></p>
        <p>Total elapsed time: <?php echo $profiler->getTotalElapsedSecs() ?></p>
    </div>
    <table class='spreadsheet' cellpadding='0' cellspacing='0' style='margin:10px auto'>
        <thead>
            <tr>
                <th>#</th>
                <th>Query</th>
                <th>Time</th>
            </tr>
        </thead>
        <tbody>
    <?php foreach ($profiler->getQueryProfiles() as $queryNumber => $query) : ?>
                <tr>
                    <td>(<?php echo $queryNumber + 1 ?>)</td>
                    <td><?php echo $query->getQuery(); ?></td>
                    <td><?php echo $query->getElapsedSecs(); ?></td>
                </tr>
    <?php endforeach ?>
        </tbody>
    </table>
    <?php endif ?>

I don't imagine that using the firebug profiler is much more difficult.

Upvotes: 2

Related Questions