When I have to analyse code for performance issues I mostly use logging methods. It's easy to extend these (often given) loggers with some performance functionality like memory usage an script execution time.
Something like this I use to log:
$this->justLog((microtime(true) - $_SERVER['REQUEST_TIME_FLOAT']).'s @' . $this->getMemoryUsage().'MB: in function X before calling function Y', $arrayOfFurtherInformation);
With this method I divide the code to look at into smaller pieces to faster find slowing parts. I also prevent XDebug from falsifying my measurements...
Joseluis Laso - 2015-09-08 07:45:12 - In reply to message 1 from ger ler
You are right.
But, be in mind that the example that I'll expose in the second part it's based on the console, as a server task or something like that. And, in this case I'm not sure if could be applied your notes. But I'll try, of course.
Related with the memory usage I have a version in local that uses php native functions to limit the amount of data cached. The target: prevent hang of the script, but all my tests didn't improve the speed because the memory_usage introduces lags. I'm very interested in how you are implemented your $this->getMemoryUsage().
ger ler - 2015-09-08 14:14:34 - In reply to message 2 from Joseluis Laso
I also mainly use the php native function memory_get_usage(), but it has an fallback that could be interesting for you.
I found it on stackoverflow: stackoverflow.com/questions/2290611 ...
The post of Alix Axel also reads the memory usage the running OS determines:
exec('ps -eo%mem,rss,pid | grep ' . getmypid(), $output);
And have a look at the comment of greg on Alix' post...