Wednesday, February 11, 2009

Database Operations Analysis using zend_profiler

The Zend Framework offers its own logging solution for all SQL queries to profile what is run, and how long it takes to execute, using Zend_Db_Profiler. The profiler can be enabled by passing an option called "profiler" with a boolean TRUE value with the options when constructing a database adapter. Thereafter you can instantiate the Zend_Db_Profiler class and use a variety of methods to examine how many queries were profiled, how long they took in total to execute, and retrieve an array of query profiles on which to perform a more in-depth analysis using the accompanying filters. There's even a special Zend_Db_Profiler_Firebug class so you can view profiling data on the fly through the Firebug console in Firefox.

Usage
in Bootstrap file

// turn on profiler:
$db->getProfiler()->setEnabled(true);

in Action before all queries

$profiler = $db->getProfiler();


Bottom of the function


foreach ($profiler->getQueryProfiles() as $query) {

echo '
'.$query->getQuery();
echo ' TIME: ' .$query->getElapsedSecs()." Seconds";

}

It will list the Connection Time and all other executed queries with taken time


No comments:

Post a Comment