6

I'm currently using xhprof library forked by tideways.io for profiling myscript.php execution. From xhprof, i can get the walltime, cputime, memoryusage, and peakmemoryusage. I'm try to benchmark a symfony console - so i add TIDEWAYS_ENABLE() on its ConsoleCommandEvent and TIDEWAYS_DISABLE on its ConsoleTerminateEvent.

Questions:

  1. How can i determine whether myscript.php consume how many percentage of cpu ? Can i just count the percentage as cpuusage = cputime / realtime like stated here on serverfault ?
  2. Given a memoryusage (mu) and peakmemoryusage (pmu) from xhprof profiler, how do i convert or calculate its ram usage ? (top result show much higher than memoryusage but somehow near peakmemoryusage value, so can i say that ram usage is the value of peakmemoryusage ?

Notes:

1 Answers1

0

I am not sure what you want to determine using the data, but if you're trying to do any comparative analysis (e.g. "when I remove this loop, it's 25% faster and uses 10% less memory") I'd suggest that you use https://blackfire.io/.

It's easy to setup and easy to use. It also offers automatic comparative analysis between requests. It also does multiple passes internally to make sure that external factors are averaged-out.

I can't really say whether the CPU and memory usage data is accurate. It is definitely accurate relatively to other data in blackfire - so works great if you just need to compare it. You should take it with a grain of salt if you need absolute numbers though (how many scripts like this is it safe to run on 4GB server?). But I'd say it's pretty accurate. It's definitely much better than xdebug's profiller.

Tomáš Fejfar
  • 11,129
  • 8
  • 54
  • 82
  • Actually i've no issue to retrieve the `cputime` - i'm using [xhprof](https://github.com/tideways/php-profiler-extension) forked by [tideways.io](https://tideways.io) instead of [blackfire.io](https://blackfire.io). What makes me curios is it possible to calculate a `script.php` cpu usage just like showed up in command like `top` or `htop` in percentage just from `cputime` value ? – Peter Juanda Jun 14 '17 at 14:19
  • oops, sorry I misunderstood what you asked – Tomáš Fejfar Jun 14 '17 at 18:17