Last active
October 8, 2015 13:17
-
-
Save craiga/3336985 to your computer and use it in GitHub Desktop.
_logMemoryUsage
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; | |
$this->_log("Memory usage: %s; change since last time: %s", formatMemory($memoryUsage), formatMemory($change)); | |
} | |
$this->_lastMemoryUsage = $memoryUsage; | |
} | |
/** | |
* Last recorded memory usage. | |
*/ | |
protected $_lastMemoryUsage = null; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment