1

I want to get get memory usage info for each called method/function during a request. I'm working on a cloud service, for past years. When PHP 7.0 released, we noticed that we had about 30% more memory usage with same codes.

On 7.1, we noticed that 10% more memory usage was common for each request.

At the time we faced a trade-off between speed and memory (also cool new features), and we chose to upgrade our environment.

But now, PHP 7.2 has almost the same speed as 7.1 while we noticed that again, about 10% more memory is used by our codes on 7.2.


I want to know how to test our codes and see how much memory each method is using during a request. I tried a few things like memory_get_usage() or Meminfo but I'm looking for a way to automatically generate a report for all methods/functions that are called during a request. It's really impossible to check 2000+ methods/function by hand.

D.D
  • 21
  • 4
  • 2
    xdebug with cachegrind stats? or Blackfire.io? – Mark Baker Jan 10 '18 at 23:01
  • @LawrenceCherone: not in 2018 / with php7 – symcbean Jan 10 '18 at 23:24
  • @symcbean what do you mean. you don't think xdebug is a valid option? – Félix Adriyel Gagnon-Grenier Jan 10 '18 at 23:34
  • It's **only** a valid option if testing on a non-production environment, when you're only wanting qualitative performance metrics, you have a realistic set of regression tests and you can translate the results appropriately. The bit of code using the most memory is not the problem - its the bit of code with the highest frequency of invocation and memory usage product which is a priority for fixing. – symcbean Jan 11 '18 at 11:10
  • I see, while evident now you mention it, I had not taken the production-ready aspect into account here. – Félix Adriyel Gagnon-Grenier Jan 11 '18 at 14:36
  • Possible duplicate of [Simplest way to profile a PHP script](https://stackoverflow.com/questions/21133/simplest-way-to-profile-a-php-script) – Matt S Feb 04 '18 at 13:46

1 Answers1

1

There is a maintained fork of xhprof which will run on your php versions. NB you do not want to run a profiler not specifically designed for a production environment in a live service! (Xhprof-for-php7 was designed to be used in a production context)

But be wary of the the metrics you are measuring; a single process has a rather distorted view of its own footprint.

symcbean
  • 47,736
  • 6
  • 59
  • 94