determine how much resource used by a php script (cpu percentage and memory)
Asked Answered
W

1

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:

Whyalla answered 6/6, 2017 at 3:55 Comment(0)
R
-1

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.

Repulse answered 9/6, 2017 at 18:7 Comment(2)
Actually i've no issue to retrieve the cputime - i'm using xhprof forked by tideways.io instead of 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 ?Whyalla
oops, sorry I misunderstood what you askedLeverrier

© 2022 - 2024 — McMap. All rights reserved.