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:
- How can i determine whether
myscript.phpconsume how many percentage of cpu ? Can i just count the percentage ascpuusage = cputime / realtimelike stated here on serverfault ? - Given a
memoryusage (mu)andpeakmemoryusage (pmu)fromxhprofprofiler, how do i convert or calculate itsramusage ? (topresult show much higher thanmemoryusagebut somehow nearpeakmemoryusagevalue, so can i say thatramusage is the value ofpeakmemoryusage?
Notes:
- It's different with this How can I get the CPU and Memory useage, because what i want is not the
system load. p.s there might multiplescripts.phprunning at the same time.
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.