From owner-freebsd-stable@FreeBSD.ORG Sun Jul 17 10:53:59 2011 Return-Path: Delivered-To: freebsd-stable@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 87F6F1065672 for ; Sun, 17 Jul 2011 10:53:59 +0000 (UTC) (envelope-from ml@os2.kiev.ua) Received: from s1.sdv.com.ua (s1.sdv.com.ua [77.120.97.61]) by mx1.freebsd.org (Postfix) with ESMTP id 475E28FC0A for ; Sun, 17 Jul 2011 10:53:59 +0000 (UTC) Received: from 90-105-243-80.cust.centrio.cz ([80.243.105.90] helo=[192.168.100.107]) by s1.sdv.com.ua with esmtpsa (SSLv3:CAMELLIA256-SHA:256) (Exim 4.76 (FreeBSD)) (envelope-from ) id 1QiObV-000Pol-KD for freebsd-stable@freebsd.org; Sun, 17 Jul 2011 13:29:44 +0300 Message-ID: <4E22B98F.20008@os2.kiev.ua> Date: Sun, 17 Jul 2011 12:29:35 +0200 From: Alex Samorukov User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110516 Lightning/1.0b2 Thunderbird/3.1.10 MIME-Version: 1.0 To: freebsd-stable@freebsd.org Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-SA-Score: -1.0 Subject: Dtrace with PHP scripts works on FreeBSD8-STABLE! X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 17 Jul 2011 10:53:59 -0000 Hello, I was able to compile [1] and and run PHP Dtrace provider on FreeBSD-STABLE. Everything works as expected and looks very cool. It works both from Apache (mod_php) and cli. If there are port commiters with dtrace experience - please, take it. Below there is a small demo: This is a test script: PrintTest(); class demoClass{ function demoClass(){ @chdir("/notexists"); } function PrintTest(){ echo "TEST\n"; } } ?> This is the most basic output to demonstrate how provider works: # dtrace -n 'php*::: /arg0/ {printf("\t\t%s%s%s",copyinstr(arg3),copyinstr(arg4),copyinstr(arg0))}' dtrace: description 'php*::: ' matched 24 probes dtrace: buffer size lowered to 2m CPU ID FUNCTION:NAME 2 44455 php_dtrace_execute_internal:function-entry file_get_contents 2 44457 php_dtrace_execute_internal:function-return file_get_contents 2 44456 php_dtrace_execute:function-entry demoClass::demoClass 2 44455 php_dtrace_execute_internal:function-entry chdir 2 44457 php_dtrace_execute_internal:function-return chdir 2 44458 php_dtrace_execute:function-return demoClass::demoClass 2 44456 php_dtrace_execute:function-entry demoClass::PrintTest 2 44458 php_dtrace_execute:function-return demoClass::PrintTest As you could see there is information about all functions (and classnames) in our test. Also there is a possibility to trace syscalls used by PHP function. This is output from ./php_syscolors.d (with minor modifications): for the file_get_contents (reads file to variable): 1 16019/100898 6 test.php:4 func -> file_get_contents 1 16019/100898 18 ":- syscall -> __getcwd 1 16019/100898 8 ":- syscall <- __getcwd 1 16019/100898 8 ":- syscall -> clock_gettime 1 16019/100898 4 ":- syscall <- clock_gettime 1 16019/100898 5 ":- syscall -> open 1 16019/100898 9 ":- syscall <- open 1 16019/100898 5 ":- syscall -> fstat 1 16019/100898 5 ":- syscall <- fstat 1 16019/100898 4 ":- syscall -> lseek 1 16019/100898 4 ":- syscall <- lseek 1 16019/100898 5 ":- syscall -> fstat 1 16019/100898 4 ":- syscall <- fstat 1 16019/100898 4 ":- syscall -> read 1 16019/100898 6 ":- syscall <- read 1 16019/100898 9 ":- syscall -> read 1 16019/100898 5 ":- syscall <- read 1 16019/100898 4 ":- syscall -> read 1 16019/100898 4 ":- syscall <- read 1 16019/100898 5 ":- syscall -> close 1 16019/100898 10 ":- syscall <- close 1 16019/100898 8 test.php:4 func <- file_get_contents Of course it is possible to use aggregations, filtering and all other dtrace features. Problems: I found that buffer size in dtrace is always about 2m. I am using a lot of events while trying to debug running web server. Todo: latest PHP alpha releases include dtrace support internally (and it is extended, compared to this pecl extension). Currently build failing on BSD and i had no time to investigate problem source (i think they are using some ugly linker hacks). It would be great to get it fixed before PHP release to have it in FreeBSD out of the box. [1] http://www.freebsd.org/cgi/query-pr.cgi?pr=158983