Π Π°Π±ΠΎΡ‚Π° срСдства SystemTap со статичСскими Π·ΠΎΠ½Π΄Π°ΠΌΠΈ PHP DTrace

Π’ ΠΎΡ‚Π΄Π΅Π»ΡŒΠ½Ρ‹Ρ… дистрибутивах Linux для отслСТивания статичСских Π·ΠΎΠ½Π΄ΠΎΠ² DTrace доступСн инструмСнт трассировки SystemTap. Π­Ρ‚ΠΎΡ‚ Π²Π°Ρ€ΠΈΠ°Π½Ρ‚ доступСн Π² 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
οΌ‹Π”ΠΎΠ±Π°Π²ΠΈΡ‚ΡŒ

ΠŸΡ€ΠΈΠΌΠ΅Ρ‡Π°Π½ΠΈΡ ΠΏΠΎΠ»ΡŒΠ·ΠΎΠ²Π°Ρ‚Π΅Π»Π΅ΠΉ 1 note

up
-2
idealities at gmail dot com ΒΆ
7 years ago
# stap -l 'process.provider("php").mark("*")' -c 'sapi/cli/php -i'

This can also be archived by:

stap -l 'process("sapi/cli/php").mark("*")'

And, no need to be root to run this command.