1
0
mirror of https://github.com/maximebf/php-debugbar.git synced 2025-01-16 21:08:34 +01:00

(fix) set memory baseline on MemoryCollector (#559)

* set memory baseline on MemoryCollector

* Rename method

---------

Co-authored-by: Barry vd. Heuvel <barryvdh@gmail.com>
This commit is contained in:
erikn69 2023-09-19 14:48:23 -05:00 committed by GitHub
parent ab33d08b02
commit 1d87377810
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -17,6 +17,10 @@ class MemoryCollector extends DataCollector implements Renderable
{
protected $realUsage = false;
protected $memoryRealStart = 0;
protected $memoryStart = 0;
protected $peakUsage = 0;
/**
@ -41,6 +45,17 @@ class MemoryCollector extends DataCollector implements Renderable
$this->realUsage = $realUsage;
}
/**
* Reset memory baseline, to measure multiple requests in a long running process
*
* @return void
*/
public function resetMemoryBaseline()
{
$this->memoryStart = memory_get_usage(false);
$this->memoryRealStart = memory_get_usage(true);
}
/**
* Returns the peak memory usage
*
@ -48,7 +63,7 @@ class MemoryCollector extends DataCollector implements Renderable
*/
public function getPeakUsage()
{
return $this->peakUsage;
return $this->peakUsage - ($this->realUsage ? $this->memoryRealStart : $this->memoryStart);
}
/**
@ -66,8 +81,8 @@ class MemoryCollector extends DataCollector implements Renderable
{
$this->updatePeakUsage();
return array(
'peak_usage' => $this->peakUsage,
'peak_usage_str' => $this->getDataFormatter()->formatBytes($this->peakUsage, 0)
'peak_usage' => $this->getPeakUsage(),
'peak_usage_str' => $this->getDataFormatter()->formatBytes($this->getPeakUsage(), 0)
);
}