sigjlr/phpsimpleprofiler

轻量级php性能分析库

dev-master 2013-11-07 10:52 UTC

This package is not auto-updated.

Last update: 2024-09-23 14:07:58 UTC


README

轻量级php性能分析库

##安装 您可以使用 Composer (推荐) 或手动方式安装 PhpSimpleProfiler。

##使用 示例假设您正在使用 Composer 或其他遵守 PSR-0 规范的自动加载器自动加载依赖。

PhpSimpleProfiler可用方法

  • setOption($name , $value) 设置选项(如果 $name 是有效的选项名称)的值。可用选项:'active' (bool) (默认 = true) 如果设置为 false,则不记录任何配置文件 'handler' (PhpSimpleProfiler\Handler\IHandler) (默认 = PhpSimpleProfiler\HandlerStreamHandler) 处理和返回数据的对象 'realUsage' (bool) (默认 = false) 设置为 TRUE 以获取系统分配的内存的真实大小(php引擎使用的所有内存),设置为 FALSE 以获取仅由 emalloc() 使用的内存(仅脚本)

  • add($message) 向统计配置文件添加条目。

  • stop() 结束性能分析。

  • printData() 获取数据。

###处理器

  • StreamHandler 此处理器旨在将配置文件数据打印到日志文件

  • HTMLHandler 此处理器旨在在网页上显示数据

###示例

// Create a new PhpSimpleProfiler
$psp = new PhpSimpleProfiler\PhpSimpleProfiler(array('realUsage' =>true));

// Add profiled entry
$psp->add('Before loop');

$y = 0;
for($i = 0; $i<1000; ++$i){
	$y++;	
}

// Add profiled entry
$psp->add('After loop');

// Stop the profiler
$psp->stop();

// Print the result
echo $psp->printData();

// You shold see something like this:
/*
Time: 1380207924 | Memory Usage: 0.75 MB | execution_time: 1.4066696166992E-5 | Info: Initial state
Time: 1380207924 | Memory Usage: 0.75 MB | execution_time: 0.00024199485778809 | Info: Before loop
Time: 1380207924 | Memory Usage: 0.75 MB | execution_time: 0.00027799606323242 | Info: After loop
Time: 1380207924 | Memory Usage: 0.75 MB | execution_time: 1.6927719116211E-5 | Info: Final state

Peak of memory usage: 0.75 MB

CPU elaboration time: 0.00055694580078125
*/

##许可证 PhpSimpleProfiler 在 MIT 公共许可证下发布