Add profile.php for profiling

This commit is contained in:
Zankaria 2024-06-21 00:57:10 +02:00
parent 54feeba2da
commit 0b746c4ec6

21
inc/profile.php Normal file
View file

@ -0,0 +1,21 @@
<?php
// From https://www.mediawiki.org/wiki/Excimer
// Inject with `auto_prepend_file` in php.ini
if (extension_loaded("excimer")) {
error_log("Profiler started", 0);
static $prof; // Keep object until the end of the request
$prof = new ExcimerProfiler();
$prof->setEventType(EXCIMER_REAL);
$prof->setPeriod(5); // every N seconds
$prof->setMaxDepth(250);
$prof->setFlushCallback(function ($log) {
error_log("Logged profile", 0);
file_put_contents('/tmp/profles-ramfs/excimer-traces.log', $log->formatCollapsed(), FILE_APPEND | LOCK_EX);
}, 1);
$prof->start();
} else {
error_log("Profiler code injected, but no excimer extension installed");
}