Added memory profiling by Benson Geoff with minor changes.

Tested on xdebug 2.1.2 with KCachegrind 0.6kde