/[refeed]/trunk/introspect/context.php
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /trunk/introspect/context.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2 - (show annotations)
Wed Jul 5 00:27:49 2006 UTC (17 years, 11 months ago) by dpavlin
File size: 5874 byte(s)
make working copy of trunk
1 <?php
2 // vim: ts=4 foldcolumn=4 foldmethod=marker
3
4 ini_set("include_path",
5 join(PATH_SEPARATOR,
6 array(realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..'))),
7 realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'library', 'PEAR'))),
8 realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'library', 'Smarty'))),
9 realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'library', 'magpierss'))),
10 realpath(join(DIRECTORY_SEPARATOR, array(dirname(__FILE__), '..', 'library', 'RF'))),
11 ini_get("include_path"))));
12
13 require_once('config.php');
14 require_once('Utility.functions.php');
15 require_once("DB.php");
16
17 $dbh = & DB::connect(get_configured_dsn(),
18 array('debug' => REF_DB_DEBUG_LEVEL, 'portability' => DB_PORTABILITY_NONE));
19
20 if(DB::isError($dbh))
21 die(sprintf('<p><b>%s.</b></p><pre>%s</pre>', htmlspecialchars($dbh->getMessage()), htmlspecialchars($dbh->getDebugInfo())));
22
23 $dbh->setFetchMode(DB_FETCHMODE_OBJECT);
24
25 $_GET['order'] = empty($_GET['order']) ? 'total' : $_GET['order'];
26 $_GET['context'] = ($_GET['context'] == 'None') ? '' : $_GET['context'];
27
28 $q = "SELECT MIN(id) AS id,
29 COUNT(duration) AS count,
30 SUM(duration) AS total,
31 MIN(duration) AS minimum,
32 AVG(duration) AS average,
33 MAX(duration) AS maximum,
34 query_gen
35 FROM query_log
36 WHERE context = ".$dbh->quoteSmart($_GET['context'])."
37 GROUP BY query_gen
38 ORDER BY ".$dbh->quoteIdentifier($_GET['order'])." DESC";
39
40 $res = $dbh->query($q);
41
42 if(DB::isError($res))
43 die(sprintf('<p><b>%s.</b></p><pre>%s</pre>', htmlspecialchars($res->getMessage()), htmlspecialchars($res->getDebugInfo())));
44
45 $queries = array();
46 $averages = array();
47 $minimums = array();
48 $maximums = array();
49 $counts = array();
50 $totals = array();
51
52 while($query = $res->fetchRow()) {
53 $queries[] = $query;
54 $averages[] = $query->average;
55 $minimums[] = $query->minimum;
56 $maximums[] = $query->maximum;
57 $counts[] = $query->count;
58 $totals[] = $query->total;
59 }
60
61 $average_avg = array_sum($averages) / count($averages);
62 $minimum_avg = array_sum($minimums) / count($minimums);
63 $maximum_avg = array_sum($maximums) / count($maximums);
64 $count_avg = array_sum($counts) / count($counts);
65 $total_avg = array_sum($totals) / count($totals);
66
67 $average_max = max($averages);
68 $minimum_max = max($minimums);
69 $maximum_max = max($maximums);
70 $count_max = max($counts);
71 $total_max = max($totals);
72
73 $average_min = min($averages);
74 $minimum_min = min($minimums);
75 $maximum_min = min($maximums);
76 $count_min = min($counts);
77 $total_min = min($totals);
78
79 ?>
80 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
81 "http://www.w3.org/TR/html4/loose.dtd">
82 <html>
83 <head>
84 <title>Query Log: Context</title>
85 <link rel="stylesheet" href="style.css" type="text/css">
86 </head>
87 <body>
88 <p><a href="index.php">all contexts</a></p>
89 <h1><?= htmlspecialchars($_GET['context']) ?></h1>
90 <table border="0">
91 <tr>
92 <th></th>
93 <th><a href="context.php?context=<?= urlencode($_GET['context']) ?>&amp;order=count">Count</a></th>
94 <th><a href="context.php?context=<?= urlencode($_GET['context']) ?>&amp;order=total">Total</a></th>
95 <th><a href="context.php?context=<?= urlencode($_GET['context']) ?>&amp;order=minimum">Min.</a></th>
96 <th><a href="context.php?context=<?= urlencode($_GET['context']) ?>&amp;order=average">Avg.</a></th>
97 <th><a href="context.php?context=<?= urlencode($_GET['context']) ?>&amp;order=maximum">Max.</a></th>
98 <th>Query</th>
99 </tr>
100 <? foreach($queries as $query): ?>
101 <tr>
102 <td class="label"><a href="query.php?query=<?= urlencode($query->id) ?>">Explain</a></td>
103 <td class="value number <?= ($query->count == $count_min) ? 'min' : '' ?> <?= ($query->count > $count_avg) ? 'above' : 'below' ?> <?= ($query->count == $count_max) ? 'max' : '' ?>">
104 <?= number_format($query->count) ?></td>
105 <td class="value number <?= ($query->total == $total_min) ? 'min' : '' ?> <?= ($query->total > $total_avg) ? above : below ?> <?= ($query->total == $total_max) ? 'max' : '' ?>">
106 <?= number_format($query->total) ?></td>
107 <td class="value number <?= ($query->minimum == $minimum_min) ? 'min' : '' ?> <?= ($query->minimum > $minimum_avg) ? above : below ?> <?= ($query->minimum == $minimum_max) ? 'max' : '' ?>">
108 <?= number_format($query->minimum, 2) ?></td>
109 <td class="value number <?= ($query->average == $average_min) ? 'min' : '' ?> <?= ($query->average > $average_avg) ? above : below ?> <?= ($query->average == $average_max) ? 'max' : '' ?>">
110 <?= number_format($query->average, 2) ?></td>
111 <td class="value number <?= ($query->maximum == $maximum_min) ? 'min' : '' ?> <?= ($query->maximum > $maximum_avg) ? above : below ?> <?= ($query->maximum == $maximum_max) ? 'max' : '' ?>">
112 <?= number_format($query->maximum, 2) ?></td>
113 <td class="value text"><?= htmlspecialchars(str_replace("\n", ' ', $query->query_gen)) ?></td>
114 </tr>
115 <? endforeach ?>
116 </table>
117 </body>
118 </html>

  ViewVC Help
Powered by ViewVC 1.1.26