/[drupal]/contributions/tricks/blocks/databasecalls.php
ViewVC logotype

Contents of /contributions/tricks/blocks/databasecalls.php

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.1 - (show annotations) (download) (as text)
Fri Aug 15 19:54:45 2003 UTC (6 years, 3 months ago) by chris
Branch: MAIN
Branch point for: DRUPAL-4-3, drop
File MIME type: text/x-php
Add code snippet for displaying database query counts and time in a block.
Add support for database table name prefixes via braces {} around table
names in mostrecentcomments.php.
1 /*
2 * This PHP-type blocks displays the number of queries against the
3 * the database and the total clock time required for these queries
4 * used in the generation of this page. The time does not include
5 * any other time spent in PHP code, only during SQL queries.
6 *
7 * Optionally, if the 2 commented out lines are commented in, it will
8 * list all of the queries and how much time they each took.
9 *
10 * Note that the capturing of database query times is OFF by default
11 * in Drupal. It must be turned ON by setting the "dev_query" variable
12 * in the "variable" table. That can be done by hand via this SQL:
13 * Insert Into variable Values ("dev_query", 's:1:"1";');
14 *
15 * $Id$
16 * Author: Chris Johnson / chris@chaska.com
17 */
18
19 global $queries;
20 $sum = 0.0;
21 foreach ($queries as $query) {
22 $sum += $query[1];
23 }
24 $sum = sprintf("%2.5f", $sum);
25 $output .= "Page generated with ".count($queries)." queries which consumed $sum seconds";
26 // Comment in the following 2 lines to get full list of queries and their
27 // times. Note it could be 50 or 70 queries long for an average node page!
28 // $header = array("Query", "Time");
29 // $output .= table($header, $queries);
30 return $output;

  ViewVC Help
Powered by ViewVC 1.1.2