Add class MD_STD_DEBUG for debugging and code improvements
This commit is contained in:
parent
5e7313f166
commit
2071b57053
35
src/MD_STD_DEBUG.php
Normal file
35
src/MD_STD_DEBUG.php
Normal 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);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user