Використання SystemTap Π·Ρ– статичними Π·ΠΎΠ½Π΄Π°ΠΌΠΈ PHP DTrace

Π£ дСяких дистрибутивах Linux ΠΌΠΎΠΆΠ½Π° використовувати ΡƒΡ‚ΠΈΠ»Ρ–Ρ‚Ρƒ трасування SystemTap для відстСТСння статичних Π·ΠΎΠ½Π΄Ρ–Π² DTrace. Π”Π°Π½ΠΈΠΉ Π²Π°Ρ€Ρ–Π°Π½Ρ‚ доступний Ρƒ PHP 5.4.20 Ρ‚Π° PHP 5.5.

Установка PHP Π· SystemTap

Π’ΡΡ‚Π°Π½ΠΎΠ²Ρ–Ρ‚ΡŒ ΠΏΠ°ΠΊΠ΅Ρ‚ SystemTap SDT:

#yum install systemtap-sdt-devel

Π’ΡΡ‚Π°Π½ΠΎΠ²Ρ–Ρ‚ΡŒ PHP Π· DTrace:

#./configure --enable-dtrace ...

make

ΠžΡ‚Ρ€ΠΈΠΌΠ°Π½Π½Ρ списку статичних Π·ΠΎΠ½Π΄Ρ–Π² Π·Π° допомогою SystemTap

Π‘Ρ‚Π°Ρ‚ΠΈΡ‡Π½Ρ– Π·ΠΎΠ½Π΄ΠΈ PHP ΠΌΠΎΠΆΠ½Π° подивитися Π·Π° допомогою stap:

# 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")

ΠŸΡ€ΠΈΠΊΠ»Π°Π΄ використання SystemTap Π· PHP

ΠŸΡ€ΠΈΠΊΠ»Π°Π΄ #1 all_probes.stp - трасування всіх статичних Π·ΠΎΠ½Π΄Ρ–Π² PHP

probe process("sapi/cli/php").provider("php").mark("compile__file__entry") { printf("Probe compile__file__entry\n"); printf(" compile_file %s\n", user_string($arg1)); printf(" compile_file_translated %s\n", user_string($arg2)); } probe process("sapi/cli/php").provider("php").mark("compile__file__return") { printf("Probe compile__file__return\n"); printf(" compile_file %s\n", user_string($arg1)); printf(" compile_file_translated %s\n", user_string($arg2)); } probe process("sapi/cli/php").provider("php").mark("error") { printf("Probe error\n"); printf(" errormsg %s\n", user_string($arg1)); printf(" request_file %s\n", user_string($arg2)); printf(" lineno %d\n", $arg3); } probe process("sapi/cli/php").provider("php").mark("exception__caught") { printf("Probe exception__caught\n"); printf(" classname %s\n", user_string($arg1)); } probe process("sapi/cli/php").provider("php").mark("exception__thrown") { printf("Probe exception__thrown\n"); printf(" classname %s\n", user_string($arg1)); } probe process("sapi/cli/php").provider("php").mark("execute__entry") { printf("Probe execute__entry\n"); printf(" request_file %s\n", user_string($arg1)); printf(" lineno %d\n", $arg2); } probe process("sapi/cli/php").provider("php").mark("execute__return") { printf("Probe execute__return\n"); printf(" request_file %s\n", user_string($arg1)); printf(" lineno %d\n", $arg2); } probe process("sapi/cli/php").provider("php").mark("function__entry") { printf("Probe function__entry\n"); printf(" function_name %s\n", user_string($arg1)); printf(" request_file %s\n", user_string($arg2)); printf(" lineno %d\n", $arg3); printf(" classname %s\n", user_string($arg4)); printf(" scope %s\n", user_string($arg5)); } probe process("sapi/cli/php").provider("php").mark("function__return") { printf("Probe function__return: %s\n", user_string($arg1)); printf(" function_name %s\n", user_string($arg1)); printf(" request_file %s\n", user_string($arg2)); printf(" lineno %d\n", $arg3); printf(" classname %s\n", user_string($arg4)); printf(" scope %s\n", user_string($arg5)); } probe process("sapi/cli/php").provider("php").mark("request__shutdown") { printf("Probe request__shutdown\n"); printf(" file %s\n", user_string($arg1)); printf(" request_uri %s\n", user_string($arg2)); printf(" request_method %s\n", user_string($arg3)); } probe process("sapi/cli/php").provider("php").mark("request__startup") { printf("Probe request__startup\n"); printf(" file %s\n", user_string($arg1)); printf(" request_uri %s\n", user_string($arg2)); printf(" request_method %s\n", user_string($arg3)); }

НавСдСний Π²ΠΈΡ‰Π΅ скрипт Π²ΠΈΠ²ΠΎΠ΄ΠΈΡ‚ΠΈΠΌΠ΅ Π΄Π°Π½Ρ– статичних Π·ΠΎΠ½Π΄Ρ–Π² PHP Π½Π° Π²ΡΡŒΠΎΠΌΡƒ протязі Ρ€ΠΎΠ±ΠΎΡ‚ΠΈ PHP-скрипту:

# stap -c 'sapi/cli/php test.php' all_probes.stp