Probing PHP with Systemtap on Linux
PHP introduced DTrace support with PHP 5.3, enabling probing points in the PHP executable that can be used to simplify probing of PHP applications without having to the PHP implementation details. We enabled probes on function calls, file compilation, exceptions and errors. But this has always been limited to the operating systems that support DTrace. With the popularity of DTrace, Systemap programmers decided to add a DTrace compatibility layer that allows to use DTrace probes as Systemtap probing points as well.
With my recent commit to the PHP 5.5 branch, we allow DTrace probes to be build on Linux, so people can use Systemtap to probe those userland probes.
$ git clone git://github.com/php/php-src php-src $ cd php-src $ git checkout PHP-5.5
$ ./buildconf --force $ ./configure --disable-all --enable-dtrace $ make
$ stap -l 'process.provider("php").mark("*")' -c 'sapi/cli/php -i' process("sapi/cli/php").provider("php").mark("compile__file__entry") process("sapi/cli/php").provider("php").mark("compile__file__return") process("sapi/cli/php").provider("php").mark("error") process("sapi/cli/php").provider("php").mark("exception__caught") process("sapi/cli/php").provider("php").mark("exception__thrown") process("sapi/cli/php").provider("php").mark("execute__entry") process("sapi/cli/php").provider("php").mark("execute__return") process("sapi/cli/php").provider("php").mark("function__entry") process("sapi/cli/php").provider("php").mark("function__return") process("sapi/cli/php").provider("php").mark("request__shutdown") process("sapi/cli/php").provider("php").mark("request__startup")
$ cat request.stp global callcount; probe process.provider("php").mark("function-entry") { callcount[user_string($arg1)] += 1; } probe end { printf("count : function\n"); foreach (name in callcount) { printf("%5d : %s\n", callcount[name], name); } }
$ sudo stap -c 'sapi/cli/php test.php' request.stp count : function 100 : foo 101 : bar
So that’s all. You can use systemtap now to probe your PHP. Hope you come up with some useful scripts. Share them!
DTrace for Linux is being actively worked on. See https://blogs.oracle.com/linux/entry/dtrace_for_oracle_linux_news
December 5th, 2012 at 01:54[…] original post here: Probing PHP with Systemtap on Linux – experimentalworks Tags: daily, experimentalworks, Function, Linux, News, open-source, php, Programming, Search, […]
December 6th, 2012 at 11:53[…] DTrace for Linux is being created by Oracle and is currently in tech preview. Currently it doesn’t support userspace tracing so, in the meantime, Systemtap can be used to monitor the probes implemented in PHP. This was recently outlined in David Soria Parra’s post Probing PHP with Systemtap on Linux. […]
December 7th, 2012 at 05:46