Still now I’ve found Xdebug as the most useful tool to profile the bottleneck of an API. To understand the profiling result step by step- there is Webgrind.
To install Xdebug-
$ sudo apt-get install php5-xdebug
On successful installation, it should list up
$ ls /usr/lib/php5/20121212/xdebug.so
/usr/lib/php5/20121212/xdebug.so
Add Xdebug config
$ sudo vim /etc/php5/mods-available/xdebug.ini
;;;;;;;;;;;;;;;;;;; ; Xdebug config ; ;;;;;;;;;;;;;;;;;;; zend_extension="/usr/lib/php5/20121212/xdebug.so" xdebug.remote_enable=1 xdebug.remote_connect_back=1 xdebug.profiler_enable=0 xdebug.profiler_enable_trigger=1 xdebug.profiler_output_dir=/tmp/ xdebug.remote_handler=dbgp xdebug.remote_mode=req xdebug.remote_host=127.0.0.1 xdebug.remote_port=9000
Restart fpm
$ sudo service php5-fpm restart
That’s all to setup xdebug. Just to confirm the setup, check config
$ php -i | grep "xdebug"
/etc/php5/cli/conf.d/20-xdebug.ini, xdebug xdebug support => enabled
and all other config details should show up there
Now send request using ?XDEBUG_PROFILE=1 e.g. http://domain/api?XDEBUG_PROFILE=1
The output should be available here
$ ls -lth /tmp/*.out.*
-rw-r--r-- 1 www-data www-data 55M Nov 9 09:16 /tmp/cachegrind.out.26030
Now watch every steps using webgrind.