MemoryPeakUsageProcessor.php 943 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. /*
  3. * This file is part of the Monolog package.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Monolog\Processor;
  11. use Monolog\Processor\MemoryProcessor;
  12. /**
  13. * Injects memory_get_peak_usage in all records
  14. *
  15. * @see Monolog\Processor\MemoryProcessor__construct() for options
  16. * @author Rob Jensen
  17. */
  18. class MemoryPeakUsageProcessor extends MemoryProcessor
  19. {
  20. /**
  21. * @param array $record
  22. * @return array
  23. */
  24. public function __invoke(array $record)
  25. {
  26. $bytes = memory_get_peak_usage($this->realUsage);
  27. $formatted = MemoryProcessor::formatBytes($bytes);
  28. $record['extra'] = array_merge(
  29. $record['extra'],
  30. array(
  31. 'memory_peak_usage' => $formatted,
  32. )
  33. );
  34. return $record;
  35. }
  36. }