The name of this hack is "Microstats (only for admin) - load times, server loads, queries, uncached templates!". It is based on vB3's native code:
Version 1.0 - works for most servers
Updated 1.02 - optimized code
Updated 1.2 - added names of uncached templates!
Information shown:
1) Page loading times
2) Number of Queries
3) Server Loads
4) Number of Any Uncached Templates
5) Name of Uncached Templates (NEW!)
By default only an Admin (usergroup 6) can see it. Feel free to modify this bit.
It's very easy to install.
Open includes/functions.php:
Find:
PHP:
// ####################################################################
// temporary code
global $_TEMPLATEQUERIES, $tempusagecache, $DEVDEBUG, $_SERVER, $debug
;
UNDERNEATH, ADD:
Version 1.2 - more optimized but requires /proc on your server - try this, if server loads don't show up use Version 1.02 below.
PHP:
// Microstats hack
if ($bbuserinfo[usergroupid]==6) {
$pageendtime = microtime();
$starttime = explode(' ', $pagestarttime);
$endtime = explode(' ', $pageendtime);
$totaltime = vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5);
$loadavg = @file_get_contents("/proc/loadavg");
if ($loadavg) {
$regs = explode(" ",$loadavg);
$serverload=' [Server Loads: <b>'.$regs[0].'</b> '.$regs[1].' : '.$regs[2].']';
}
$debughtml = "<center><span class=\"smallfont\">Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" . iif($_TEMPLATEQUERIES, " (<b>" . sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)", '') . "$serverload</span></center>";
ksort($tempusagecache);
foreach ($tempusagecache AS $tempname => $times)
{
if ($_TEMPLATEQUERIES["$tempname"]) $debughtml .= "<center><span class=\"smallfont\">Uncached templates: <font color=\"red\"><b>$tempname</b></font> ($times)</span></center>";
}
$vartext = str_replace('</body>', "$debughtml\n</body>", $vartext);
}
//Microstats Hack
Version 1.02 - Use this if Version 1.2 doesn't work for you.
PHP:
// Microstats hack
if ($bbuserinfo[usergroupid]==6) {
$pageendtime = microtime();
$starttime = explode(' ', $pagestarttime);
$endtime = explode(' ', $pageendtime);
$totaltime = vb_number_format($endtime[0] - $starttime[0] + $endtime[1] - $starttime[1], 5);
if ($stats=@exec('uptime')) {
preg_match('/averages?: ([0-9\.]+),[\s]+([0-9\.]+),[\s]+([0-9\.]+)/',$stats,$regs);
$serverload=' [Server Loads: <b>'.$regs[1].'</b> » '.$regs[2].' : '.$regs[3].']';
}
$debughtml = "<center><span class=\"smallfont\">Page generated in <b>$totaltime</b> seconds with <b>$query_count</b> queries" . iif($_TEMPLATEQUERIES, " (<b>" . sizeof($_TEMPLATEQUERIES) . "</b> queries for uncached templates)", '') . "$serverload</span>";
$vartext = str_replace('</body>', "$debughtml\n</body>", $vartext);
ksort($tempusagecache);
foreach ($tempusagecache AS $tempname => $times)
{
if ($_TEMPLATEQUERIES["$tempname"]) $debughtml .= "<center><span class=\"smallfont\">Uncached templates: <font color=\"red\"><b>$tempname</b></font> ($times)</span></center>";
}
}
//Microstats Hack
Done! As simple as that. No need to enable debug mode.
If you want only yourself to have this information, change:
if ($bbuserinfo[usergroupid]==6) {
to
if ($bbuserinfo[userid]==1) {
And replace 1 with your userid.
To let everyone see it, remove that line, and the last } of the code above.