Hallo, Gast! (Registrieren)

Letzte Ankündigung: MyBB 1.8.39 veröffentlicht (02.06.25)


Benutzer, die gerade dieses Thema anschauen: 1 Gast/Gäste
Profiler
#1
Ich habe mal einen kleinen Profiler gebastelt - als Patch, da das mit einem Plugin nicht so ohne weiteres geht. Die angehängte Datei kann mit meinem Patches-Plugin angewendet werden, ansonsten ist von Hand zu editieren.


.txt   patches-profiler.txt (Größe: 7 KB / Downloads: 3)

inc/class_plugins.php:
PHP-Code:
/* + */ global $maintimer, $profiler;
/* + */ $profiler[$maintimer->stop()] = "before load {$plugin}";
if(
$plugin != "" && file_exists(MYBB_ROOT."inc/plugins/".$plugin.".php"))
{
require_once
MYBB_ROOT."inc/plugins/".$plugin.".php";
}
/* + */ $profiler[$maintimer->stop()] = "after load {$plugin}";
PHP-Code:
/* + */ global $maintimer, $profiler;
/* + */ $profiler[$maintimer->stop()] = "hook {$hook}";
if(!
is_array($this->hooks[$hook]))
{
return
$arguments;
}
$this->current_hook = $hook;
ksort($this->hooks[$hook]);
foreach(
$this->hooks[$hook] as $priority => $hooks)
{
if(
is_array($hooks))
{
foreach(
$hooks as $hook)
{
if(
$hook['file'])
{
require_once
$hook['file'];
}
$oldreturnargs = $returnargs; // why is this line of code here?

$returnargs = call_user_func_array($hook['function'], array(&$arguments));


if(
$returnargs)
{
$arguments = $returnargs;
}
/* + */ $profiler[$maintimer->stop()] = "after {$this->current_hook} {$hook['function']}";
PHP-Code:
/* + */ global $maintimer, $profiler;
/* + */ $profiler[$maintimer->stop()] = "hook_by_ref {$hook}";
if(empty(
$this->hooks[$hook]) && !is_array($this->hooks[$hook]))
{
return
$arguments;
}
$this->current_hook = $hook;
ksort($this->hooks[$hook]);
foreach(
$this->hooks[$hook] as $priority => $hooks)
{
if(
is_array($hooks))
{
foreach(
$hooks as $hook)
{
if(
$hook['file'])
{
require_once
$hook['file'];
}

call_user_func_array($hook['function'], array(&$arguments));
/* + */ $profiler[$maintimer->stop()] = "after {$this->current_hook} {$hook['function']}";

inc/db_mysqli.php:
PHP-Code:
function query($string, $hide_errors=0, $write_query=0)
{
/* + */ global $profiler, $maintimer;
/* + */ $profiler[$maintimer->stop()] = "before query {$string}";
PHP-Code:
/* + */ $profiler[$maintimer->stop()] = "after query {$string}";
return
$query;

inc/functions.php:
PHP-Code:
$debugstuff = "Generated in $totaltime seconds ($percentphp% PHP / $percentsql% MySQL)<br />SQL Queries: $db->query_count / Global Parsing Time: $globaltime$memory_usage<br />$other<br />[<a href=\"$debuglink\" target=\"_blank\">advanced details</a>]<br />";
/* + */ global $profiler;
/* + */ $debugstuff .= "<pre style=\"float: left; text-align: left; overflow: auto; width: 1000px;\">".htmlspecialchars(print_r($profiler, true))."</pre>";

Das erzeugt dann eine Ausgabe der Form Zeit => Hook oder Query.

Code:
...
    [0.1339400] => hook_by_ref my_date
    [0.1339800] => hook_by_ref my_date
    [0.1340001] => hook_by_ref my_date
    [0.1345050] => hook_by_ref my_date
    [0.1349280] => hook global_end
    [0.1400831] => before query SELECT title,cache FROM mybb_datacache WHERE title='forumpermissions'
    [0.1401660] => after query SELECT title,cache FROM mybb_datacache WHERE title='forumpermissions'
    [0.1403849] => before query SELECT threads, unapprovedthreads FROM mybb_forums WHERE fid = '204' LIMIT 1
    [0.1404569] => after query SELECT threads, unapprovedthreads FROM mybb_forums WHERE fid = '204' LIMIT 1
    [0.1405070] => before query SELECT COUNT(tid) as threads FROM mybb_threads WHERE fid = '204' AND (lastpost >= '1293847185' OR sticky=1)  AND (visible='1' OR visible='0')  ORDER BY lastpost DESC
    [0.1405740] => after query SELECT COUNT(tid) as threads FROM mybb_threads WHERE fid = '204' AND (lastpost >= '1293847185' OR sticky=1)  AND (visible='1' OR visible='0')  ORDER BY lastpost DESC
    [0.1443200] => hook showthread_start
    [0.1556530] => before query
                    REPLACE INTO mybb_threadsread (tid, uid, dateline)
                    VALUES('295381', '100001', '1298300027')
                
    [0.1558521] => after query
                    REPLACE INTO mybb_threadsread (tid, uid, dateline)
                    VALUES('295381', '100001', '1298300027')
                
    [0.1558800] => before query
                    SELECT COUNT(t.tid) AS unread_count
                    FROM mybb_threads t
                    LEFT JOIN mybb_threadsread tr ON (tr.tid=t.tid AND tr.uid='100001')
                    LEFT JOIN mybb_forumsread fr ON (fr.fid=t.fid AND fr.uid='100001')
                    WHERE t.visible=1 AND t.closed NOT LIKE 'moved|%' AND t.fid IN (204) AND t.lastpost > IFNULL(tr.dateline,1297695227) AND t.lastpost > IFNULL(fr.dateline,1297695227) AND t.lastpost>1297695227
                
    [0.1833060] => after query
                    SELECT COUNT(t.tid) AS unread_count
                    FROM mybb_threads t
                    LEFT JOIN mybb_threadsread tr ON (tr.tid=t.tid AND tr.uid='100001')
                    LEFT JOIN mybb_forumsread fr ON (fr.fid=t.fid AND fr.uid='100001')
                    WHERE t.visible=1 AND t.closed NOT LIKE 'moved|%' AND t.fid IN (204) AND t.lastpost > IFNULL(tr.dateline,1297695227) AND t.lastpost > IFNULL(fr.dateline,1297695227) AND t.lastpost>1297695227
                
    [0.1834669] => hook showthread_ismod
...

Daran läßt sich dann der Zeitverlauf eines Requests so einigermaßen nachvollziehen.
Zitieren
#2
Sehr geil zum debuggen, danke!
Zitieren