An open API service indexing awesome lists of open source software.

https://github.com/jonaswouters/XhprofBundle

XHProf bundle for Symfony 2
https://github.com/jonaswouters/XhprofBundle

Last synced: 8 months ago
JSON representation

XHProf bundle for Symfony 2

Awesome Lists containing this project

README

          

README
======

[![Build Status](https://travis-ci.org/jonaswouters/XhprofBundle.svg?branch=master)](https://travis-ci.org/jonaswouters/XhprofBundle) [![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/jonaswouters/XhprofBundle/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/jonaswouters/XhprofBundle/?branch=master) [![Code Coverage](https://scrutinizer-ci.com/g/jonaswouters/XhprofBundle/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/jonaswouters/XhprofBundle/?branch=master)

What is XHProf?
---------------

XHProf is a hierarchical profiler for PHP. It reports function-level call counts and inclusive and exclusive metrics such as wall (elapsed) time, CPU time and memory usage.
A function's profile can be broken down by callers or callees. The raw data collection component is implemented in C as a PHP Zend extension called xhprof.
XHProf has a simple HTML based user interface (written in PHP). The browser based UI for viewing profiler results makes it easy to view results or to share results with peers.
A callgraph image view is also supported.

See [official documentation][1]

What does this Symfony 2 Bundle do?
-----------------------------------

This bundle helps you to easily use the XHProf bundle with the web debug toolbar in Symfony 2.
With Symfony 2.3 and newer, it can also profile console commands.

## Installation

Make sure you have XHProf installed.
If you are on a mac you can easily install it via [Macports][2]
sudo port install php5-xhprof

1. ### Composer

Add the following dependencies to your projects composer.json file:

```json
"require": {
"jns/xhprof-bundle": "1.0.*@dev",
"lox/xhprof": "dev-master@dev"
}
```

Of course, you have to install [xhprof library](http://php.net/manual/fr/book.xhprof.php) in your server.
At this moment, `ext-xhprof` is not required because your application could be deployed to a server without xhprof.

2. ### Old way by adding to your vendor/bundles/ dir

1. #### To install the bundle, place it in the `src/Jns/Bundle` directory of your project
(so that it lives at `src/Jns/Bundle/XhprofBundle`). You can do this by adding
the bundle as a submodule, cloning it, or simply downloading the source.

```bash
$ git submodule add https://github.com/jonaswouters/XhprofBundle.git src/Jns/Bundle/XhprofBundle
```

2. #### Add the Jns namespace to your autoloader

If this is the first Jns bundle in your Symfony 2 project, you'll
need to add the `Jns` namespace to your autoloader. This file is usually located at `app/autoload.php`.

```php
$loader->registerNamespaces(array(
'Jns' => __DIR__.'/../src'
// ...
));
```

### Initializing the bundle

To initialize the bundle, you'll need to add it in your kernel. This
file is usually located at `app/AppKernel.php`. Loading it only in your dev environment is recommended.

```php
public function registerBundles()
{
// ...

if (in_array($this->getEnvironment(), array('dev', 'test'))) {
// ...
$bundles[] = new Jns\Bundle\XhprofBundle\JnsXhprofBundle();
}
}
```

## Configuration

### Configure the XHProf locations.

The Bundle comes preconfigured for the macports php5-xhprof default installation,
with the xhprof web located at http://xhprof.localhost.
To change these settings for your environment you can override the defaults by
defining the following settings in your config. The config is usually located at `app/config/config_dev.yml`.

```yaml
jns_xhprof:
location_web: http://xhprof.localhost
enabled: true
```

Do not forget to set `enabled` to `true`, or the profiler will never be activated.

### Using XHGui

[XHGui][3] is a GUI for the XHProf PHP extension, using a database backend, and pretty graphs to make it easy to use and interpret. The XHProf bundle supports using XHGui to display the results. To use, install XHGui, and add the following two settings to the configuration, usually located at `app/config/config.yml`:

```yaml
jns_xhprof:
entity_manager: (defaults to default)
entity_class: Acme\FooBundle\Entity\XhprofDetail
enable_xhgui: true
```

Create your class `Acme\FooBundle\Entity\XhprofDetail`:

```php