profiler.txt 1.13 KB
Newer Older
meus's avatar
meus committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
+++ Introduction
{{Doctrine_Connection_Profiler}} is an eventlistener for {{Doctrine_Connection}}. It provides flexible query profiling. Besides the SQL strings the query profiles include elapsed time to run the queries. This allows inspection of the queries that have been performed without the need for adding extra debugging code to model classes.

{{Doctrine_Connection_Profiler}} can be enabled by adding it as an eventlistener for {{Doctrine_Connection}}.

<code type="php">
$conn = Doctrine_Manager::connection($dsn);

$profiler = new Doctrine_Connection_Profiler();

$conn->setListener($profiler);
</code>
+++ Basic usage

Perhaps some of your pages is loading slowly. The following shows how to build a complete profiler report from the connection:

<code type="php">
$time = 0;
19
foreach ($profiler as $event) {
meus's avatar
meus committed
20 21 22 23
    $time += $event->getElapsedSecs();
    echo $event->getName() . " " . sprintf("%f", $event->getElapsedSecs()) . "<br>\n";
    echo $event->getQuery() . "<br>\n";
    $params = $event->getParams();
24
    if( ! empty($params)) {
meus's avatar
meus committed
25 26 27 28 29 30 31 32
        var_dump($params);
    }
}
echo "Total time: " . $time  . "<br>\n";
</code>

+++ Advanced usage