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 |
|
27 |
$q = "SELECT context, |
28 |
COUNT(context) AS count, |
29 |
SUM(duration) AS total, |
30 |
MIN(duration) AS minimum, |
31 |
AVG(duration) AS average, |
32 |
STDDEV(duration) AS deviation, |
33 |
MAX(duration) AS maximum |
34 |
FROM query_log |
35 |
GROUP BY context |
36 |
ORDER BY ".$dbh->quoteIdentifier($_GET['order'])." DESC"; |
37 |
|
38 |
$res = $dbh->query($q); |
39 |
|
40 |
if(DB::isError($res)) |
41 |
die(sprintf('<p><b>%s.</b></p><pre>%s</pre>', htmlspecialchars($res->getMessage()), htmlspecialchars($res->getDebugInfo()))); |
42 |
|
43 |
$contexts = array(); |
44 |
$averages = array(); |
45 |
$minimums = array(); |
46 |
$maximums = array(); |
47 |
$counts = array(); |
48 |
$totals = array(); |
49 |
|
50 |
while($context = $res->fetchRow()) { |
51 |
if(empty($context->context)) |
52 |
$context->context = 'None'; |
53 |
|
54 |
$contexts[] = $context; |
55 |
$averages[] = $context->average; |
56 |
$minimums[] = $context->minimum; |
57 |
$maximums[] = $context->maximum; |
58 |
$counts[] = $context->count; |
59 |
$totals[] = $context->total; |
60 |
} |
61 |
|
62 |
$average_avg = array_sum($averages) / count($averages); |
63 |
$minimum_avg = array_sum($minimums) / count($minimums); |
64 |
$maximum_avg = array_sum($maximums) / count($maximums); |
65 |
$count_avg = array_sum($counts) / count($counts); |
66 |
$total_avg = array_sum($totals) / count($totals); |
67 |
|
68 |
$average_max = max($averages); |
69 |
$minimum_max = max($minimums); |
70 |
$maximum_max = max($maximums); |
71 |
$count_max = max($counts); |
72 |
$total_max = max($totals); |
73 |
|
74 |
$average_min = min($averages); |
75 |
$minimum_min = min($minimums); |
76 |
$maximum_min = min($maximums); |
77 |
$count_min = min($counts); |
78 |
$total_min = min($totals); |
79 |
|
80 |
?> |
81 |
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" |
82 |
"http://www.w3.org/TR/html4/loose.dtd"> |
83 |
<html> |
84 |
<head> |
85 |
<title>Query Log</title> |
86 |
<link rel="stylesheet" href="style.css" type="text/css"> |
87 |
</head> |
88 |
<body> |
89 |
<table border="0"> |
90 |
<tr> |
91 |
<th><a href="index.php?order=context">Context</a></th> |
92 |
<th><a href="index.php?order=count">Count</a></th> |
93 |
<th><a href="index.php?order=total">Total</a></th> |
94 |
<th><a href="index.php?order=minimum">Min.</a></th> |
95 |
<th><a href="index.php?order=average">Avg.</a></th> |
96 |
<th><a href="index.php?order=maximum">Max.</a></th> |
97 |
<th>Dev.</th> |
98 |
</tr> |
99 |
<? foreach($contexts as $context): ?> |
100 |
<tr> |
101 |
<td class="label"><a href="context.php?context=<?= urlencode($context->context) ?>"><?= htmlspecialchars($context->context) ?></a></td> |
102 |
<td class="value number <?= ($context->count == $count_min) ? 'min' : '' ?> <?= ($context->count > $count_avg) ? above : below ?> <?= ($context->count == $count_max) ? 'max' : '' ?>"> |
103 |
<?= number_format($context->count) ?></td> |
104 |
<td class="value number <?= ($context->total == $total_min) ? 'min' : '' ?> <?= ($context->total > $total_avg) ? above : below ?> <?= ($context->total == $total_max) ? 'max' : '' ?>"> |
105 |
<?= number_format($context->total) ?></td> |
106 |
<td class="value number <?= ($context->minimum == $minimum_min) ? 'min' : '' ?> <?= ($context->minimum > $minimum_avg) ? above : below ?> <?= ($context->minimum == $minimum_max) ? 'max' : '' ?>"> |
107 |
<?= number_format($context->minimum, 2) ?></td> |
108 |
<td class="value number <?= ($context->average == $average_min) ? 'min' : '' ?> <?= ($context->average > $average_avg) ? above : below ?> <?= ($context->average == $average_max) ? 'max' : '' ?>"> |
109 |
<?= number_format($context->average, 2) ?></td> |
110 |
<td class="value number <?= ($context->maximum == $maximum_min) ? 'min' : '' ?> <?= ($context->maximum > $maximum_avg) ? above : below ?> <?= ($context->maximum == $maximum_max) ? 'max' : '' ?>"> |
111 |
<?= number_format($context->maximum, 2) ?></td> |
112 |
<td class="value number"><?= number_format($context->deviation, 2) ?></td> |
113 |
</tr> |
114 |
<? endforeach ?> |
115 |
</table> |
116 |
</body> |
117 |
</html> |