rfc:dtrace

This is an old revision of the document!


Request for Comments: How to write RFCs

Introduction

Applications can provide own probes to better reflect its underlying structure. Nevertheless it is possible to trace an application that doesn't have own probes. In that case the kernel will generate probes for every C function call, thus requiring deep knowledge of the applications code base. While static probes in an application can provide additional useful parameters to DTrace consumers, the dynamic approach just provides the parameters passed to a function, making it hard for end-users to get useful data.

Why DTrace probes for PHP

The proposed patch adds a provider for PHP specific probes to PHP. This will better reflect the execution flow of a PHP script. Former inaccessible information, such as the error message in zend_error are passed to probes. The patch introduces probes to track the compilation of a script, the execution and function call stacks and error/exception handling. Calling a probe doesn't affect the performance until the probe is enabled by DTrace. Disabled probes are replaced by NOPs. If additional information is needed, the information is retrieved and passed to the probes once it is enabled.

Probes Description
request-(startup/shutodnw) These probes are fire when a request starts or shuts down.
compile-file-(entry/return) These probes are fire when the compilation of a script starts and when it finishes.
execute-(entry/return) These probes are fire when a new opcode is executed.
function-(entry/return) These probes are fire when the engine enters or returns from a PHP function or method call.
exception-thrown This probe is fired whenever an exception is thrown
exception-caught This probe is fired whenever an exception is caught
error This probe is fired whenever an error occurs. It doesn't depend on the error_reproting level.

Examples

Display errors

Display all errors, warning and notices independent from the current error_reporting setting or @-operator on all running PHP instances:

#!/usr/sbin/dtrace -s

#pragma D option quiet

php*:::error
{
    printf("Error: %s in line %d (%s)\n", copyinstr(arg0), arg2, copyinstr(arg1));
} 
Count FSTAT calls

The following example counts the fstat calls in a PHP file and add up the time needed for the fstats.

#!/usr/sbin/dtrace -s

#pragma D option quiet

php*:::execute-entry
/!self->start/
{
    self->start = vtimestamp;
}

php*:::execute-entry
/self->start/
{
    self->isInsidePHP++;
    self->filename = copyinstr(arg0);
    self->result[self->filename] = 0;
}

php*:::execute-return
{
    self->isInsidePHP--;
}

syscall::fstat:entry
/self->isInsidePHP > 0/
{
    self->calltime = timestamp;
}

syscall::fstat:return
/self->isInsidePHP > 0/
{
    self->result[self->filename] = timestamp - self->calltime;
}

More about DTrace

Changelog

rfc/dtrace.1247537530.txt.gz · Last modified: 2017/09/22 13:28 (external edit)