renan/cakephp-xhprof

插件,用于快速为 CakePHP 应用程序启用 XHProf 性能分析。

安装次数: 38,732

依赖: 0

建议者: 0

安全: 0

星星: 21

关注者: 4

分支: 2

类型:cakephp-plugin

v1.0.0 2014-09-30 09:07 UTC

This package is not auto-updated.

Last update: 2024-09-24 06:21:28 UTC


README

Build Status Coverage Status Latest Stable Version

插件,用于快速为 CakePHP 应用程序启用 XHProf 性能分析。

需求

  • PHP 5.3+
  • CakePHP 2.3+
  • XHProf

安装

首先,确保您已启用 xhprof 扩展并下载了 phacility/xhprof

手册

  1. 下载 http://github.com/renan/CakePHP-XHProf/zipball/master
  2. 解压下载的文件
  3. 将内容移动到 Plugin/XHProf

Git 子模块

git submodule add git://github.com/renan/CakePHP-XHProf.git Plugin/XHProf
git submodule update --init

Git 克隆

git clone git://github.com/renan/CakePHP-XHProf.git Plugin/XHProf

Composer / Packagist

更多信息可以在 Packagist 上找到。

这将安装最新版本的 0.1 到 Plugin/XHProf

{
	"require": {
		"renan/cakephp-xhprof": "0.1.*"
	}
}

如果您只计划用于开发,则可能想使用 "require-dev"。

配置

基本配置包括加载插件并指定系统上 xhprof_lib 目录的位置。

在您的 Config/bootstrap.php 文件中

// Load XHProf Plugin
CakePlugin::load('XHProf');

// XHProf Configuration
Configure::write('XHProf', array(
	'library' => '/usr/local/Cellar/php54-xhprof/270b75d/xhprof_lib',
));

选项

  • library:xhprof_lib 目录的路径(必需)
  • namespace:保存您的 xhprof 运行的命名空间,默认为您的应用程序目录名称
  • flags:传递给分析器的标志,默认为 0。有关标志列表,请访问:https://php.ac.cn/xhprof.constants.php
  • ignored_functions:要忽略的函数数组,默认为 call_user_funccall_user_func_array
  • replaceRunId:用于替换运行 ID 以在页面上显示链接的占位符,设置 false 以禁用,默认为 %XHProfRunId%。有关更多信息,请参阅使用说明

所有选项示例

Configure::write('XHProf', array(
	'library' => '/usr/local/Cellar/php54-xhprof/270b75d/xhprof_lib',
	'namespace' => 'myapp',
	'flags' => XHPROF_FLAGS_CPU | XHPROF_FLAGS_MEMORY,
	'ignored_functions' => array(
		'my_function',
		'my_other_function',
	),
	'replaceRunId' => false,
));

使用方法

分发器过滤器

只需将 XHProfDispatcher 包含在 Config/bootstrap.php 中的分发器过滤器列表中。

Configure::write('Dispatcher.filters.xhprof', 'XHProf.XHProfDispatcher');

默认情况下,它将尝试用页面输出的保存运行 ID 替换 %XHProfRunId%。它允许您在页面上包含到 xhprof 报告的链接。

在您的 View/Layouts/default.ctp

$url = sprintf(
	'/url/to/xhprof_html/index.php?run=%s&source=%s',
	Configure::read('XHProf.replaceRunId'),
	Configure::read('XHProf.namespace')
);
echo $this->Html->link('XHProf Output', $url);

DebugKit 面板

如果您正在使用 DebugKit,您可以使用提供的面板。

确保您包括 xhprof_html 文件夹的 URL 终端点的 HTML 配置

Configure::write('XHProf', array(
	'library' => '/usr/local/Cellar/php54-xhprof/270b75d/xhprof_lib',
	'html' => 'http://path/to/xhprof_html',
));

然后您可以在 DebugKit 组件设置中添加面板

public $components = array(
	'DebugKit.Toolbar' => array(
		'panels' => array('XHProf.XHProf')
	),
);

完成。现在它应该显示新的面板,并带有指向页面输出结果的链接。

手册

此方法在分析代码的特定点时非常有用。为此,只需使用 XHProf 类来协助您即可。

示例

// Declare the class location
App::uses('XHProf', 'XHProf.Lib');

// Start the profiler
XHProf::start();

// ... your application code

// Stop the profiler
// 1. Returning the profiler data
$data = XHProf::stop();

// 2. or Save the profiler data, returning the run id
$runId = XHProf::finish();

注意:如上所述,有两种停止分析器的方法。但是每次运行只能使用其中一种。

变更日志

1.0.0 (2014-09-30)

  • 添加了 DebugKit 面板,而不是与布局文件纠缠。感谢 @dereuromark 的补丁。
  • 收集代码覆盖率指标并向 coveralls 报告

0.1.0 (2012-11-03)

首次发布

许可证

版权所有 (c) 2014 Renan Gonçalves

本许可证免费且无限制地授予任何获得本软件及其相关文档副本(以下简称“软件”)的个人,以使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,并允许向软件提供者授予此类权利的个人进行上述操作,但需遵守以下条件

上述版权声明和本许可声明应包含在软件的所有副本或主要部分中。

软件按“原样”提供,不提供任何形式的保证,包括但不限于适销性、特定用途适用性和非侵权性保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任承担责任,无论其基于合同、侵权或其他原因,无论是否与软件或软件的使用或其他相关事宜有关。