Using PHP and DTrace

PHP can be configured with DTrace static probes on platforms that   support DTrace Dynamic Tracing.

Configuring PHP for DTrace Static Probes

Refer to external platform specific documentation for enabling    operating system DTrace support.  For example, on Oracle Linux    boot a UEK3 kernel and do:

# modprobe fasttrap# chmod 666 /dev/dtrace/helper

Instead of using chmod, you could instead use an    ACL package rule to limit device access to a specific user.

Build PHP with the --enable-dtrace configuration parameter:

# ./configure --enable-dtrace ...# make# make install

This enables the static probes in core PHP.  Any PHP extensions    that provide their own probes should be built separately as shared    extensions.

DTrace Static Probes in Core PHP

The following static probes are available in PHP
Probe NameProbe DescriptionProbe Arguments
request-startupFires when a request starts.char *file, char *request_uri, char *request_method
request-shutdownFires when a request shutdown.char *file, char *request_uri, char *request_method
compile-file-entryFires when the compilation of a script starts.char *compile_file, char *compile_file_translated
compile-file-returnFires when the compilation of a script finishes.char *compile_file, char *compile_file_translated
execute-entryFires when a new opcode is executed.char *request_file, intlineno
execute-returnFires when a execution of an opcode is returns.char *request_file, intlineno
function-entryFires whn the PHP engine enters a PHP function or method call.char *function_name, char *request_file, intlineno, char *classname, char *scope
function-returnFires when the PHP engine returns from a PHP function or method call.char *function_name, char *request_file, intlineno, char *classname, char *scope
exception-thrownFires when an exception is thrown.char *classname
exception-caughtFires when an exception is caught.char *classname
errorFires when an error occurs, regardless of the error_reporting level.char *errormsg, char *request_file, intlineno

PHP extensions may also have additional static probes.

Listing DTrace Static Probes in PHP

To list available probes, start a PHP process and then run:

# dtrace -l

The output will be similar to:

   ID   PROVIDER            MODULE                          FUNCTION NAME
   [ . . . ]
    4   php15271               php               dtrace_compile_file compile-file-entry
    5   php15271               php               dtrace_compile_file compile-file-return
    6   php15271               php                        zend_error error
    7   php15271               php  ZEND_CATCH_SPEC_CONST_CV_HANDLER exception-caught
    8   php15271               php     zend_throw_exception_internal exception-thrown
    9   php15271               php                 dtrace_execute_ex execute-entry
   10   php15271               php           dtrace_execute_internal execute-entry
   11   php15271               php                 dtrace_execute_ex execute-return
   12   php15271               php           dtrace_execute_internal execute-return
   13   php15271               php                 dtrace_execute_ex function-entry
   14   php15271               php                 dtrace_execute_ex function-return
   15   php15271               php              php_request_shutdown request-shutdown
   16   php15271               php               php_request_startup request-startup

The Provider column values consist of php and    the process id of the currently running PHP process.

If the Apache web server is running, the module name might be, for    example,libphp5.so, and there would be    multiple blocks of listings, one per running Apache process.

The Function column refers to PHP's internal C implementation    function names where each provider is located.

If a PHP process is not running, then no PHP probes will be shown.

DTrace with PHP Example

This example shows the basics of the DTrace D scripting language.

Example #1all_probes.dfor tracing all PHP Static Probes with DTrace

#!/usr/sbin/dtrace -Zs
#pragma D option quiet
php*:::compile-file-entry
{
    printf("PHP compile-file-entry\n");
    printf("  compile_file              %s\n", copyinstr(arg0));
    printf("  compile_file_translated   %s\n", copyinstr(arg1));
}
php*:::compile-file-return
{
    printf("PHP compile-file-return\n");
    printf("  compile_file              %s\n", copyinstr(arg0));
    printf("  compile_file_translated   %s\n", copyinstr(arg1));
}
php*:::error
{
    printf("PHP error\n");
    printf("  errormsg                  %s\n", copyinstr(arg0));
    printf("  request_file              %s\n", copyinstr(arg1));
    printf("  lineno                    %d\n", (int)arg2);
}
php*:::exception-caught
{
    printf("PHP exception-caught\n");
    printf("  classname                 %s\n", copyinstr(arg0));
}
php*:::exception-thrown
{
    printf("PHP exception-thrown\n");
    printf("  classname                 %s\n", copyinstr(arg0));
}
php*:::execute-entry
{
    printf("PHP execute-entry\n");
    printf("  request_file              %s\n", copyinstr(arg0));
    printf("  lineno                    %d\n", (int)arg1);
}
php*:::execute-return
{
    printf("PHP execute-return\n");
    printf("  request_file              %s\n", copyinstr(arg0));
    printf("  lineno                    %d\n", (int)arg1);
}
php*:::function-entry
{
    printf("PHP function-entry\n");
    printf("  function_name             %s\n", copyinstr(arg0));
    printf("  request_file              %s\n", copyinstr(arg1));
    printf("  lineno                    %d\n", (int)arg2);
    printf("  classname                 %s\n", copyinstr(arg3));
    printf("  scope                     %s\n", copyinstr(arg4));
}
php*:::function-return
{
    printf("PHP function-return\n");
    printf("  function_name             %s\n", copyinstr(arg0));
    printf("  request_file              %s\n", copyinstr(arg1));
    printf("  lineno                    %d\n", (int)arg2);
    printf("  classname                 %s\n", copyinstr(arg3));
    printf("  scope                     %s\n", copyinstr(arg4));
}
php*:::request-shutdown
{
    printf("PHP request-shutdown\n");
    printf("  file                      %s\n", copyinstr(arg0));
    printf("  request_uri               %s\n", copyinstr(arg1));
    printf("  request_method            %s\n", copyinstr(arg2));
}
php*:::request-startup
{
    printf("PHP request-startup\n");
    printf("  file                      %s\n", copyinstr(arg0));
    printf("  request_uri               %s\n", copyinstr(arg1));
    printf("  request_method            %s\n", copyinstr(arg2));
}

This script uses the -Z option todtrace, allowing it to be run when there is no    PHP process executing.  If this option were omitted the script    would immediately terminate because it knows none of the probes to    be monitored are in existence.

The script traces all core PHP static probe points throughout the    duration of a running PHP script. Run the D script:

# ./all_probes.d

Run a PHP script or application.  The monitoring D script will    output each probe's arguments as it fires.

When monitoring is complete, the D script can be terminated with a     ^C.

On multi-CPU machines the probe ordering might not appear to be    sequential. This depends on which CPU was processing the probes,    and how threads migrate across CPUs.  Displaying probe time stamps    will help reduce confusion, for example:

php*:::oci8-connect-entry
{
      printf("%lld: PHP connect-entry ", walltimestamp);
      [ . . .]
}

See Also

  • OCI8 and DTrace Dynamic Tracing

点赞(0) 打赏

评论列表 共有 0 条评论

暂无评论

热门产品

php编程基础教程.pptx|php编程培训,php,编程,基础,教程,pptx
php编程基础教程.pptx

历史上的今天:04月20日

ThinkPHP5快速入门

ThinkPHP5快速入门目 录零、序言一、基础二、URL和路由三、请求和响应四、数据库五、查询语言六、模型和关联 (1)模型定义 (2)基础操作 (3)读取器和修改器 (4)类型转换和自动完成 (5)查询范围 (6)输入和验证 (7)关联 (8)模型输出七、视图和模板八、调试和日志九、API开发十、命令行工具十一、扩展十二、杂项SessionCookie验证

ThinkPHP5快速入门基础

ThinkPHP5快速入门基础一、基础快速入门 ( 一 ) :基础本章介绍了 ThinkPHP5 .0 的安装及基本使用 ,并给出了一个最简单的示例带你了解如何开始开发 ,主要包 含 :简介官网下载 omposer安装和更新CGit下载和更新目录结构运行环境入口文件调试模式控制器视图读取数据总结在学习 ThinkPHP5.0 之前 ,如果你还不理解面向对象和命名空间的概念 ,建议首先去PHP手册恶

热门专题

自考本科|自考本科有用吗,自考文凭,自考本科文凭,自考文凭有用吗,自考本科文凭有用吗,自考文凭承认吗
自考本科
卓越综合高中|卓越综合高中
卓越综合高中
云南开放大学|云南开放大学报名,云南开放大学报考,云南开放大学,什么是云南开放大学,云南开放大学学历,云南开放大学学费,云南开放大学报名条件,云南开放大学报名时间,云南开放大学学历,云南开放大学专业
云南开放大学
易捷尔单招|易捷尔单招,易捷尔单招培训,易捷尔单招报名,易捷尔单招考试,易捷尔单招培训学校,易捷尔单招分数
易捷尔单招
中源管业|中源管业,中源管业公司,中源管业有限公司,中源管业电话,中源管业地址,中源管业电力管,中源管业mpp电力管,中源管业cpvc电力管,中源管业pe穿线管
中源管业
大理科技管理学校|大理科技管理学校,大理科技,大理科技中等职业技术学校,大理科技管理中等职业技术学校,大理科技学校
大理科技管理学校
云南网站建设|云南网站制作,网站建设,云南网站开发,云南网站设计,云南网页设计,云南网站建设公司,云南网站建设
云南网站建设
外贸网站建设|外贸网站建设,英文网站制作,英文网站设计,美国主机空间,外贸建站平台,多语言网站制作
外贸网站建设

微信小程序

微信扫一扫体验

立即
投稿

微信公众账号

微信扫一扫加关注

发表
评论
返回
顶部