-
-
Save drewsonne/8854671 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Log memory usage. | |
* | |
* Makes use of {@link https://gist.github.com/1849563 _log} and {@link https://gist.github.com/2880386 formatMemory}. | |
* | |
* @author Craig Anderson <[email protected]> | |
* @link https://gist.github.com/3336985 | |
*/ | |
protected function _logMemoryUsage() | |
{ | |
$memoryUsage = memory_get_usage(); | |
if(is_null($this->_lastMemoryUsage)) | |
{ | |
$this->_log("Memory usage: %s", formatMemory($memoryUsage)); | |
} | |
else | |
{ | |
$change = $memoryUsage - $this->_lastMemoryUsage; | |
$change_time = microtime(true) - $this->_lastMemoryUsageTime; | |
$rate = $change_time == 0 ? 0 : $change / $change_time; | |
$this->_log("Memory usage: %s; change since last time: %s; rate: %s per second", formatMemory($memoryUsage), formatMemory($change), formatMemory($rate)); | |
} | |
$this->_lastMemoryUsage = $memoryUsage; | |
$this->_lastMemoryUsageTime = microtime(true); | |
} | |
/** | |
* Last recorded memory usage. | |
*/ | |
protected $_lastMemoryUsage = null; | |
/** | |
* Last recorded memory usgae time. | |
*/ | |
protected $_lastMemoryUsageTime = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment