renansaddam/cakephp-xhprof-plugin

此包已被废弃,不再维护。作者建议使用 renan/cakephp-xhprof 包。

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

安装: 112

依赖者: 0

建议者: 0

安全性: 0

星标: 21

关注者: 3

分支: 2

开放问题: 1

类型:cakephp-plugin

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

This package is not auto-updated.

Last update: 2022-02-01 12:21:47 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,
));

使用

调度器过滤器

只需在 Config/bootstrap.php 中的调度器过滤器列表中包含 XHProfDispatcher

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

特此授予,任何人获得本软件及其相关文档文件(“软件”)的副本(“软件”),可以在不受限制的情况下处理该软件,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件副本,并允许获得该软件的人这样做,前提是遵守以下条件

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

本软件按“原样”提供,不提供任何形式的保证,无论是明示的、暗示的,还是与商业性、特定目的适用性或非侵权相关的保证。在任何情况下,作者或版权所有者均不对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他方式引起的,无论是否与软件或其使用或其他交易有关。