Skip to content

Commit

Permalink
allow customization of the memory precision (#530)
Browse files Browse the repository at this point in the history
currently there is no way to see the raw "peak_usage" bytes in the output. I'd love to have that number available somewhere, but I couldn't figure out how to do that.

this change is the next best thing, as it allows us to override the default precision of "0", so we can get a little more granularity into the memory usage.
  • Loading branch information
browner12 authored Feb 11, 2024
1 parent 80ad074 commit dfde7d0
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion src/DebugBar/DataCollector/MemoryCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ class MemoryCollector extends DataCollector implements Renderable

protected $peakUsage = 0;

protected $precision = 0;

/**
* Set the precision of the 'peak_usage_str' output.
*
* @param int $precision
*/
public function setPrecision($precision)
{
$this->precision = $precision;
}

/**
* Returns whether total allocated memory page size is used instead of actual used memory size
* by the application. See $real_usage parameter on memory_get_peak_usage for details.
Expand Down Expand Up @@ -82,7 +94,7 @@ public function collect()
$this->updatePeakUsage();
return array(
'peak_usage' => $this->getPeakUsage(),
'peak_usage_str' => $this->getDataFormatter()->formatBytes($this->getPeakUsage(), 0)
'peak_usage_str' => $this->getDataFormatter()->formatBytes($this->getPeakUsage(), $this->precision)
);
}

Expand Down

0 comments on commit dfde7d0

Please sign in to comment.