Here is my top output :
6747 example.com 15 0 241m 19m 8188 R 29.9[CPU] 0.2[RAM] 3:24.89 php
31798 mysql 15 0 1952m 422m 5384 S 12.0[CPU] 5.3[RAM] 9:00.27 mysqld
Look at PHP's CPU usage. I don't know which file is causing this load. Is there any module for show which file is using CPU under tree? I mean like this :
6747 example.com 15 0 241m 19m 8188 R 29.9[CPU] 0.2[RAM] 3:24.89 php
5.49% index.php 15.39% videos.php x% y.php
31798 mysql 15 0 1952m 422m 5384 S 12.0[CPU] 5.3[RAM] 9:00.27 mysqld
and I want same thing for mysql too. I want to now which query is executing now and how long is it take.
The simplest options (not saying the most accurate, but the simplest) will be:
For PHP, if you want to compare one PHP file against another, assume that the process that takes the longest is using most CPU. Use a network profiler (in-built into Chrome and IE, or Firebug) to find out which process takes longest. Failing that, user fiddler (on Windows) or Charles (Mac). Remove the data response times and average out the rest = time to generate response approx = CPU usage. Note that this will include external calls, memcached calls, mySQL calls etc.
for mySQL, the slow query log is invaluable. (Will need to be configure in my.cnf and restart the server - but it should be considered compulsory.)
For more diagnostics, Xdebug (as suggested by Xesued) will help you profile individual parts of scripts (as well as debug). Not recommended for production, though, as it will slow you down further.
Another crude way is to "echo microtime(true);" at various places in your script, or pump that info to a log file. (Open log file at start of script, and at various points record the microtime - look for the large gaps.)
I don't know how to determine PHP script load at runtime. (Not sure if it is even possiable). However, using Xdebug's profiler can help you determine where your scripts are slow.
Its a great tool that will help you catch 90+% of your slowdowns.
As far as MySQL: Here is a related question: how-to-analyze-query-cpu-time
I don't think there's anything that direct available, but assuming each of those scripts runs as a seperate process (something like called individually on the CLI), you could use getmypid()
then correlate that with your CPU load log.