文字

xhprof_enable

(PECL xhprof >= 0.9.0)

xhprof_enable启动 xhprof 性能分析器

说明

void xhprof_enable ([ int $flags = 0 [, array $options ]] )

启动 xhprof 进行性能分析。

参数

flags

分析添加额外信息的可选标记。 关于此标记的更多信息参见 XHprof 常量,例如, XHPROF_FLAGS_MEMORY 可以开启内存的分析。

options

array 的可选选项,就是通过传递 'ignored_functions' 选项来忽略性能分析中的某些函数。

返回值

NULL

更新日志

版本 说明
0.9.2 添加可选的 options 参数。

范例

Example #1 xhprof_enable() 范例

<?php
// 1. elapsed time + memory + CPU profiling; and ignore built-in (internal) functions
xhprof_enable ( XHPROF_FLAGS_NO_BUILTINS  XHPROF_FLAGS_CPU  XHPROF_FLAGS_MEMORY );

// 2. elapsed time profiling; ignore call_user_func* during profiling
xhprof_enable (
    
0 ,
    array(
'ignored_functions'  =>  array( 'call_user_func' ,
                                        
'call_user_func_array' )));
                                       
// 3. elapsed time + memory profiling; ignore call_user_func* during profiling
xhprof_enable (
    
XHPROF_FLAGS_MEMORY ,
    array(
'ignored_functions'  =>  array( 'call_user_func' ,
                                        
'call_user_func_array' )));
?>

参见

  • xhprof_disable() - 停止 xhprof 分析器
  • xhprof_sample_enable() - 以采样模式启动 XHProf 性能分析
  • memory_get_usage() - 返回分配给 PHP 的内存量
  • getrusage() - 获取当前资源使用状况

用户评论:

[#1] Vladimir Kovpak [2015-11-08 22:43:30]

<?php

// You can optionally profile CPU time and/or memory usage:
xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY);

上一篇: 下一篇: