Add class MD_STD_DEBUG for debugging and code improvements

This commit is contained in:
Joshua Ramon Enslin 2021-07-27 23:44:08 +02:00
parent 5e7313f166
commit 2071b57053
Signed by: jrenslin
GPG Key ID: 46016F84501B70AE

35
src/MD_STD_DEBUG.php Normal file
View File

@ -0,0 +1,35 @@
<?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);
}
}