Sponsored LinksКатегорииLinksUnix Tutorial
Personal Development Ruslan Valiev Solaris Performance Team Damien Farnham Fintan Ryan Nicky Veitch Niall Mullen Sean McGrath DTrace Bryan Cantrill Brendan Gregg ZFS Tim Foster General Ben Rockwood Learning Solaris 10 Privacy policy |
Tuesday, December 13. 2005DTrace: observing PHP, part 2
Your next step in observing PHP with DTrace could easily be the following script. It times how much time (in nanoseconds) each Apache process has spent running a particular PHP function.
This script generates a table of Apache PIDs and PHP scripts started within, and later you'll get a table of all the functions with PIDs which ran them and the time spent. You can download this script here: php-scripts-timer.d CODE: #!/usr/sbin/dtrace -s #pragma D option quiet BEGIN { printf("php scripts timer started\n"); } :dtrace.so::function-entry / copyinstr(arg0) == "" && name[pid,copyinstr(arg1)] != 1 / { printf("%d -> %-30s\n", pid, copyinstr(arg1)); name[pid,copyinstr(arg1)] = 1; } :dtrace.so::function-entry / copyinstr(arg0) != "" / { self->ts = timestamp; } :dtrace.so::function-return / copyinstr(arg0) != "" / { self->elapsed = timestamp - self->ts; @time[pid, copyinstr(arg0)] = sum(self->elapsed); } END { printf("<------ php scripts timer finished"); printf("\n%10s %40s %14s\n", "PID", "PHP function", "Time elapsed"); printa("%10d %40s %14@u\n", @time); } A typical result of running this script while opening some PHP pages served by your Apache will look like this: CODE: php scripts timer started
223074 -> /export/www/nightly/pma/left.php 223071 -> /export/www/nightly/pma/main.php 223074 -> /export/www/nightly/pma/css/phpmyadmin.css.php 223071 -> /export/www/nightly/pma/css/phpmyadmin.css.php <------ php scripts timer finished PID PHP function Time elapsed 223074 ob_get_level 22280 223074 get_cfg_var 32678 223074 mysql_get_client_info 32705 223074 strrpos 39160 223074 PMA_auth_set_user 39178 223071 get_magic_quotes_gpc 39478 223071 ob_get_level 43673 223071 addslashes 54847 223074 strpos 56869 223071 basename 61874 223071 PMA_reloadNavigation 63588 223071 mysql_get_client_info 64570 223071 get_cfg_var 64592 223071 ereg_replace 65993 223074 get_magic_quotes_gpc 67738 ... 234950 main 84254684 238255 main 105016748 238255 substr 153752861 238255 mysql_query 192585647 238255 PMA_DBI_try_query 195113800 234950 PMA_DBI_query 220108343 234950 mysql_query 276732073 234950 PMA_DBI_try_query 280801228 Trackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
Добрый день.
Очень полезная информация, особенно для разработчиков программного обеспечения.
Спасибо, Егор!
Учитывая простоту исходного кода для модуля отладки PHP с помощью DTrace, туда можно добавлять какие угодно функции для личных целей - чем я и займусь в ближайшее время, просто чтобы узнать точно, как это делается. |





