Skip to content

Instantly share code, notes, and snippets.

@craiga
Last active October 8, 2015 13:17
Show Gist options
  • Save craiga/3336985 to your computer and use it in GitHub Desktop.
Save craiga/3336985 to your computer and use it in GitHub Desktop.
_logMemoryUsage
<?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