<commit_before># CakePHP XHProf Plugin [![Build Status](https://secure.travis-ci.org/renansaddam/CakePHP-XHProf-Plugin.png)](http://travis-ci.org/renansaddam/CakePHP-XHProf-Plugin)

Plugin that quickly enables XHProf profiling for your CakePHP application.

## Requirements

* PHP 5.2+
* XHProf
* CakePHP 2.1+ (2.2+ is needed for using the Dispatcher Filter)

## Installation

### Manual

1. Download http://github.com/renansaddam/CakePHP-XHProf-Plugin/zipball/master
2. Unzip the downloaded file
3. Move the contents to `app/Plugin/XHProf`

### Git Submodule

```bash
git submodule add git://github.com/renansaddam/CakePHP-XHProf-Plugin.git app/Plugin/XHProf
git submodule update --init
```

### Git Clone

```bash
git clone git://github.com/renansaddam/CakePHP-XHProf-Plugin.git app/Plugin/XHProf
```

### Composer / Packagist

```json
{
	"require": {
		"renansaddam/cakephp-xhprof-plugin": "dev-master"
	},
	"extra": {
		"installer-paths": {
			"Plugin/XHProf/": ["renansaddam/cakephp-xhprof-plugin"]
		}
	}
}
```

## Configuration

The basic configuration consists in loading the plugin and pointing where the `xhprof_lib` directory is located on your system.

On your `app/Config/bootstrap.php` file:

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

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

Options:

* `library`: Path to your xhprof_lib directory (required)
* `namespace`: Namespace to save your xhprof runs, default is your application directory name
* `flags`: Flags passed over to profiler, default is `0`. For a list of flags visit: http://php.net/xhprof.constants.php
* `ignored_functions`: Array of functions to ignore, default is `call_user_func` and `call_user_func_array`
* `replaceRunId`: Placeholder used to replace the run id in order to display a link in the page, set `false` to disable, default is `%XHProfRunId%`. Read the usage for more information

All options example:

```php
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,
));
```

## Usage

### Dispatcher Filter

Just include the `XHProfDispatcher` on your dispatcher filters list on `app/Config/bootstrap.php`:

```php
Configure::write('Dispatcher.filters', array(
	'XHProf.XHProfDispatcher',
));
```

By default it will try replace `%replaceRunId%` to the saved run id from the page's output. It allows you to include a link to the xhprof report on the page.

On your `app/View/Layouts/default.ctp`:

```php
$url = sprintf(
	'/path/to/xhprof_html/index.php?run=%s&source=%s',
	'%XHProfRunId%',
	Configure::read('XHProf.namespace')
);
echo $this->Html->link('XHProf Output', $url);
```
<commit_msg>Fixing documentation and displaying the status of the master branch build.<commit_after># CakePHP XHProf Plugin [![Build Status](https://secure.travis-ci.org/renansaddam/CakePHP-XHProf-Plugin.png?branch=master)](http://travis-ci.org/renansaddam/CakePHP-XHProf-Plugin)

Plugin that quickly enables XHProf profiling for your CakePHP application.

## Requirements

* PHP 5.2+ (5.3+ is needed for running tests)
* CakePHP 2.1+ (2.2+ is needed for using the Dispatcher Filter)
* XHProf

## Installation

### Manual

1. Download http://github.com/renansaddam/CakePHP-XHProf-Plugin/zipball/master
2. Unzip the downloaded file
3. Move the contents to `app/Plugin/XHProf`

### Git Submodule

```bash
git submodule add git://github.com/renansaddam/CakePHP-XHProf-Plugin.git app/Plugin/XHProf
git submodule update --init
```

### Git Clone

```bash
git clone git://github.com/renansaddam/CakePHP-XHProf-Plugin.git app/Plugin/XHProf
```

### Composer / Packagist

```json
{
	"require": {
		"renansaddam/cakephp-xhprof-plugin": "dev-master"
	},
	"extra": {
		"installer-paths": {
			"Plugin/XHProf/": ["renansaddam/cakephp-xhprof-plugin"]
		}
	}
}
```

## Configuration

The basic configuration consists in loading the plugin and pointing where the `xhprof_lib` directory is located on your system.

On your `app/Config/bootstrap.php` file:

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

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

Options:

* `library`: Path to your xhprof_lib directory (required)
* `namespace`: Namespace to save your xhprof runs, default is your application directory name
* `flags`: Flags passed over to profiler, default is `0`. For a list of flags visit: http://php.net/xhprof.constants.php
* `ignored_functions`: Array of functions to ignore, default is `call_user_func` and `call_user_func_array`
* `replaceRunId`: Placeholder used to replace the run id in order to display a link in the page, set `false` to disable, default is `%XHProfRunId%`. Read the usage for more information

All options example:

```php
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,
));
```

## Usage

### Dispatcher Filter

Just include the `XHProfDispatcher` on your dispatcher filters list on `app/Config/bootstrap.php`:

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

By default it will try replace `%XHProfRunId%` to the saved run id from the page's output. It allows you to include a link to the xhprof report on the page.

On your `app/View/Layouts/default.ctp`:

```php
$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);
```

{'fraction_non_alphanumeric': 0.14316921525793985, 'fraction_numerical': 0.008401949252226516, 'mean_word_length': 4.963927855711423, 'pattern_counts': {'":': 10, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5842824', 'n_tokens_mistral': 2229, 'n_tokens_neox': 2052, 'n_words': 551}