Created
December 11, 2011 11:38
-
-
Save co3k/1460117 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/sbin/dtrace -C -Z -s | |
#pragma D option quiet | |
/* | |
C オプションをつけることで、 C コンパイラのプリプロセッサが利用可能になる | |
(http://docs.oracle.com/cd/E19253-01/819-0395/chp-prog-5/index.html) | |
*/ | |
#define BEGIN_ENTRY() \ | |
self->depth++;\ | |
self->mu[self->depth] = 0 | |
#define END_ENTRY() \ | |
this->mu = self->mu[self->depth];\ | |
self->mu[self->depth] = 0;\ | |
self->depth-- | |
php*:*:php_request_startup:request-startup | |
{ | |
/* php_request_startup:request-startup の第 2 引数は request_uri, 第 3 引数は request_method */ | |
printf("[%Y] request startup: %s %s\n", walltimestamp, copyinstr(arg2), copyinstr(arg1)); | |
/* | |
識別子 self に -> 演算子でアクセスすることで、スレッド固有変数を参照できる | |
(http://docs.oracle.com/cd/E19253-01/819-0395/chp-variables/index.html#6n2qtsp8n) | |
*/ | |
self->memory = 0; | |
BEGIN_ENTRY(); | |
} | |
php*:*:dtrace_execute:function-entry | |
{ | |
BEGIN_ENTRY(); | |
} | |
php*:*:dtrace_execute:function-return | |
/ self->mu[self->depth] >= 131072 / | |
{ | |
/* 2 ^ 17 bytes 以上のメモリアロケーション時にのみ出力 */ | |
END_ENTRY(); | |
printf("[%Y] PID: %d, function: %s, file: %s, line: %d, allocated: %d\n", walltimestamp, pid, copyinstr(arg0), copyinstr(arg1), arg2, this->mu); | |
} | |
php*:*:dtrace_execute:function-return | |
/ self->mu[self->depth] < 131072 / | |
{ | |
END_ENTRY(); | |
} | |
php*:*:php_request_shutdown:request-shutdown | |
{ | |
END_ENTRY(); | |
printf("[%Y] PID: %d, function: main(), memory: %d\n", walltimestamp, pid, self->memory); | |
} | |
syscall::mmap:entry | |
/ curpsinfo->pr_fname == "php-5.4.0RC3" / | |
{ | |
self->memory += arg1; | |
self->mu[self->depth] += arg1; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
こっちの D じゃない気がする