MD_STD/src/MD_STD_DEBUG.php

36 lines
1.1 KiB
PHP
Raw Normal View History

<?PHP
/**
* Provides basic debugging functions.
*/
declare(strict_types = 1);
/**
* Standard class providing simple and generally applicable
* debugging and code improvement functions.
*/
final class MD_STD_DEBUG {
/**
* Function simpleBenchmark prints the difference between start time and the time at the exit of script
* Should be put very early in the script.
*
* @return void
*/
public static function simpleBenchmark():void {
$start = \microtime(true);
\register_shutdown_function(function($start) :void {
echo PHP_EOL . '<pre>';
echo \microtime(true) - $start . "<br/>";
echo 'RAM Usage (Peak): ' . \memory_get_peak_usage() . "<br/>";
echo 'RAM Usage: ' . \memory_get_usage() . "<br/>";
if ($loadAvg = \sys_getloadavg()) {
echo 'Load avg. (last 1 minute): ' . $loadAvg[0] . '<br />';
echo 'Load avg. (last 5 minute): ' . $loadAvg[1] . '<br />';
echo 'Load avg. (last 15 minute): ' . $loadAvg[2] . '<br />';
}
echo '</pre>';
}, $start);
}
}