Database Query Profiling to improve performance

From Snapp CMS Developer Documentation

Jump to: navigation, search

Contents

Introduction

As of version 2.10.7.27, Snapp supports client-side database query profiling. This allows developers to see all database queries performed on a request by request basis, identify bottlenecks, and track down faulty queries as they occur.

The feature uses the excellent FirePHP/FireConsole remote console library, which enables extended logging and debug information to be delivered to a developer's web browser without interfering with display output.

Image:firephp.jpg

Server Requirements

The server requires the FireConsole PHP extension - as supplied by the FirePHP PEAR extension - installed. See http://www.firephp.org/HQ/Install.htm for installation instructions

Client Requirements

Setup

config.ini

In your site's config.ini, add the following entries:

[Site]
fire_console = 1

and

[Database]
profiling = 1

If profiling is set to 1, stack traces will only be generated for queries that fail. If it is set to 2, stack traces will be generated for all queries. This option is slower, but allows you to identify parts of code where inefficient, if valid, queries are being executed.

Bootstrap file

Depending on the type of site template you're using (traditional or MVC), you may need to add a profiling code call to your bootstrap file to generate the DB profiling output.

MVC Templates

For MVC templates, the CRU_CMS_V2 class has a convenience function, dispatch(), which handles all necessary bootstrapping, now also including DB profiling. Unless you have any odd custom bootstrapping requirements, your top level index.php file should look like:

<?
include('/cms/includes/cms.php');
$cms = new CRU_CMS_V2();

// Fire off the request
$cms->dispatch();

If you are not using the dispatch() method, you can always add your own call to $cms->db->outputProfile() at the end of the bootstrap.


Traditional Templates

Simply add the following line to the very end of your top level index.php file:

<?php $cms->db->outputProfile() ?>

An example in context:

....
			</div>
			<!-- END: Footer Menu -->
		</div> <!-- End of #masterTemplateContainer -->
        <?=$cms->loadWidget('GoogleAnalytics');?>
	</body>
</html>
<?php $cms->db->outputProfile() ?>

Flash

load.php

If you are also using load.php for Flash interaction, you may wish to add the line to the end of this file too.

AMF

AMF-based Flash sites automatically have profiling enabled provided the config.ini settings are as described above.

Personal tools
Core Components
Standalone Installs