peak memory allocated is more interesting
-
Nice plugin that does almost everything I want. I have one suggestion.
The API call you are making memory_get_usage() provides the memory currently used/allocated in the nanosecond that you make that call. That API will not report the memory used in the php run before your plugin nor after.
There is another call memory_get_peak_usage() that will provide the peak memory used during the current execution of running php script. If your plugin loads late in the cycle, then it will report peak memory of usage for a large portion of the current wordpress lifecycle. Finally, the TRUE parameter can provide more useful information because it is this memory measurement which is used by PHP to throw/report memory errors. Here is a discussion on this https://stackoverflow.com/questions/15745385/memory-get-peak-usage-with-real-usage
There could *still* be a portion of PHP code that runs after your plugin which allocates a large amount of memory. This will not handle those cases. The new API I suggest only reports the peak usage from start of the PHP chain to the exact moment this API is called.
A one-line update to your code could be done. Changing line 51 to be:
$this->memory['usage'] = function_exists('memory_get_peak_usage') ? round(memory_get_peak_usage(TRUE) / 1024 / 1024, 2) : 0;
- The topic ‘peak memory allocated is more interesting’ is closed to new replies.