PHPackages                             2a/symfony-performance-analyzer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Testing &amp; Quality](/categories/testing)
4. /
5. 2a/symfony-performance-analyzer

ActiveSymfony-bundle[Testing &amp; Quality](/categories/testing)

2a/symfony-performance-analyzer
===============================

Bundle to monitor and analyze performance of Symfony applications

1.0.5(11mo ago)120[1 issues](https://github.com/ajenguianis/symfony-performance-analyzer/issues)MITPHPPHP &gt;=8.3

Since May 30Pushed 11mo agoCompare

[ Source](https://github.com/ajenguianis/symfony-performance-analyzer)[ Packagist](https://packagist.org/packages/2a/symfony-performance-analyzer)[ Docs](https://github.com/ajenguianis/symfony-performance-analyzer)[ RSS](/packages/2a-symfony-performance-analyzer/feed)WikiDiscussions develop Synced 1mo ago

READMEChangelog (2)Dependencies (17)Versions (7)Used By (0)

Symfony Performance Analyzer Bundle
===================================

[](#symfony-performance-analyzer-bundle)

[![License](https://camo.githubusercontent.com/7013272bd27ece47364536a221edb554cd69683b68a46fc0ee96881174c4214c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d626c75652e737667)](LICENSE)[![PHP Version](https://camo.githubusercontent.com/e69fc10ad0d3845d44d08b0eeedd6dd7a5bfa4ab872e68e26b131554122d35d5/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253545382e332d626c75652e737667)](https://php.net/)[![Symfony Version](https://camo.githubusercontent.com/399ba9eb4bbc617a8592d7082c4bd20df32e29c99375444ee22ae2ac5f2c9ccf/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f73796d666f6e792d253545372e302d626c75652e737667)](https://symfony.com/)[![Build Status](https://camo.githubusercontent.com/c27a457659b89ee4f1f80f7995c559dd37f2051bde7167ad25791e5c5c92cc8e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6275696c642d70617373696e672d627269676874677265656e2e737667)](https://travis-ci.org/2a-2a/symfony-performance-analyzer)[![Coverage](https://camo.githubusercontent.com/b3545ae1bcdb4ea486f71f87b43001e82dd21933bc8035d44601706c851265da/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f636f7665726167652d3130302532352d627269676874677265656e2e737667)](https://codecov.io/gh/2a-2a/symfony-performance-analyzer)

A powerful toolkit for monitoring and optimizing Symfony applications, offering real-time performance metrics, N+1 query detection, cognitive complexity analysis, automated reporting, a secure web dashboard, and seamless CI/CD integration.

Features
--------

[](#features)

- 🚀 **Real-time Performance Metrics**: Monitor request response time, database queries, memory usage, and CLI command performance.
- 🔍 **N+1 Query Detection**: Identify and resolve N+1 query issues with detailed analysis.
- 🧠 **Cognitive Complexity Analysis**: Detect complex code structures (threshold &gt; 10) to improve maintainability.
- 📊 **Automated Reporting**: Generate HTML, JSON, or SVG badge reports for CI/CD pipelines.
- 📈 **Secure Web Dashboard**: Visualize performance trends and metrics at `/_performance`.
- 🔔 **Performance Alerts**: Configurable thresholds for response time, memory usage, query count, and complexity.
- 💾 **Flexible Storage**: Store data using Doctrine ORM (`DatabaseStorage`) or JSON files (`FileStorage`) with retention policies.
- 🌐 **Internationalization**: Supports English and French translations.
- 🛠 **Extensibility**: Add custom analyzers, collectors, and event listeners.
- ✅ **Standards Compliance**: Enforced with PHPStan (max level), PHPUnit (100% coverage), ECS, and Rector.
- ⚡ **Performance Optimizations**: Request sampling, degraded mode, and circuit breaker for external services.

Installation
------------

[](#installation)

Install the bundle via Composer:

```
composer require 2a/symfony-performance-analyzer
```

Enable the bundle in `config/bundles.php`:

```
return [
    // ...
    AA\PerformanceAnalyzer\PerformanceAnalyzerBundle::class => ['all' => true],
];
```

Generate and apply database migrations (for database storage):

```
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
```

Install assets for the web dashboard:

```
php bin/console assets:install --symlink
```

Configuration
-------------

[](#configuration)

Create a configuration file at `config/packages/symfony_performance_analyzer.yaml`:

```
symfony_performance_analyzer:
    enabled: true
    storage:
        type: database  # or 'file'
        file_path: '%kernel.project_dir%/var/performance'
        retention:
            days: 30  # Retain data for 30 days
            max_records: 10000  # Maximum number of records
    analyzers:
        memory: true
        n_plus_one: true
        cognitive_complexity: true
    thresholds:
        max_memory_mb: 256  # Maximum memory in MB
        max_response_time_ms: 500  # Maximum response time in ms
        max_db_queries: 50  # Maximum number of database queries
        max_cognitive_complexity: 10  # Maximum cognitive complexity score
    sampling:
        rate: 1.0  # Analyze 100% of requests (0.0 to 1.0)
        degraded_mode: false  # Enable degraded mode under high load
        degraded_threshold_ms: 1000  # Trigger degraded mode above this response time (ms)
    circuit_breaker:
        enabled: false  # Enable circuit breaker for external services
        failure_threshold: 5  # Number of failures before opening circuit
        retry_timeout: 60  # Seconds to wait before retrying
    dashboard:
        enabled: true
        route_prefix: /_performance
        security:
            enable_firewall: false
            allowed_ips: []  # Restrict dashboard access to specific IPs
    profiler:
        enabled: true
        toolbar: true  # Enable Symfony debug toolbar integration
    ci_cd:
        enabled: false
        level: warning  # Report level: error, warning, notice
        output_format: json  # Report format: json, html
```

For file-based storage, ensure the storage directory is writable:

```
mkdir -p var/performance
chmod -R 775 var/performance
```

Usage
-----

[](#usage)

### CLI Commands

[](#cli-commands)

Analyze performance and generate reports:

```
# Generate an HTML performance report
php bin/console performance:generate-report --format=html --output=report.html

# Generate a JSON report for CI/CD
php bin/console performance:generate-report --format=json --dry-run > ci-report.json

# Generate a CI/CD badge
php bin/console performance:generate-ci-badge --output=badge.svg

# Profile a CLI command
php bin/console performance:profile app:my-command
```

Example JSON report output:

```
{
    "logs": [
        {
            "route": "app_home",
            "response_time": 100,
            "memory_usage": 32,
            "query_count": 5
        }
    ],
    "stats": {
        "avg_response_time": 100,
        "avg_memory_usage": 32,
        "max_query_count": 10
    },
    "issues": [
        {
            "type": "high_complexity",
            "message": "Complexity 12 > 10",
            "severity": "high"
        }
    ]
}
```

### Web Dashboard

[](#web-dashboard)

Access the performance dashboard at `/_performance`. Secure it by enabling the firewall and restricting IP access:

```
symfony_performance_analyzer:
    dashboard:
        security:
            enable_firewall: true
            allowed_ips: ['127.0.0.1', '192.168.1.0/24']
```

Customize the dashboard route in `config/routes.yaml`:

```
performance_dashboard:
    path: /_performance
    controller: AA\PerformanceAnalyzer\Controller\DashboardController::index
```

### Debug Toolbar

[](#debug-toolbar)

The bundle integrates with Symfony’s debug toolbar, displaying request time, query count, memory usage, and performance issues. Enable it in the configuration:

```
symfony_performance_analyzer:
    profiler:
        toolbar: true
```

### Performance Metrics

[](#performance-metrics)

The bundle collects and analyzes the following metrics:

MetricDescriptionExpected RangeSource**Request Time**HTTP request execution time0–500 ms`PerformanceTracker`, `Timer`**Database Queries**Query count, duration, and N+1 issues0–50 queries`DatabaseQueryCollector`, `QueryAnalyzer`**Memory Usage**Peak memory consumption0–256 MB`MemoryAnalyzer`**Cognitive Complexity**Code complexity score0–10`CognitiveComplexityAnalyzer`**CLI Performance**Command execution time0–5000 ms`PerformanceTracker`**Issues**Performance violations detected0–10 issues`AnalysisResult`### Custom Analyzers

[](#custom-analyzers)

Create a custom analyzer by implementing `AnalyzerInterface`:

```
namespace App\Analyzer;

use AA\PerformanceAnalyzer\Model\AnalysisResult;
use AA\PerformanceAnalyzer\Model\PerformanceResult;
use AA\PerformanceAnalyzer\Service\Analyzer\AnalyzerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;

class CustomAnalyzer implements AnalyzerInterface
{
    public function analyze(Request $request, Response $response, PerformanceResult $result): AnalysisResult
    {
        $analysisResult = new AnalysisResult();
        if ($response->getStatusCode() >= 500) {
            $analysisResult->addIssue('server_error', [
                'message' => 'Server error detected',
                'status_code' => $response->getStatusCode(),
                'severity' => 'high'
            ]);
        }
        return $analysisResult;
    }
}
```

Register the analyzer in `config/services.yaml`:

```
App\Analyzer\CustomAnalyzer:
    tags: ['performance.analyzer']
```

### Custom Collectors

[](#custom-collectors)

Create a custom collector by implementing `CollectorInterface`:

```
namespace App\Collector;

use AA\PerformanceAnalyzer\Service\Collector\CollectorInterface;

class CustomCollector implements CollectorInterface
{
    private array $data = [];

    public function start(string $identifier): void
    {
        $this->data[$identifier] = ['start_time' => microtime(true)];
    }

    public function collect(string $identifier): array
    {
        return [
            'custom_duration' => microtime(true) - $this->data[$identifier]['start_time']
        ];
    }
}
```

Register the collector:

```
App\Collector\CustomCollector:
    tags: ['performance.collector']
```

Performance Considerations
--------------------------

[](#performance-considerations)

- **Request Sampling**: Set `sampling.rate` to a value less than 1.0 (e.g., 0.1 for 10% of requests) in production to reduce overhead.
- **Degraded Mode**: Enable `sampling.degraded_mode` to skip non-essential collectors when response time exceeds `degraded_threshold_ms`.
- **Circuit Breaker**: Activate `circuit_breaker.enabled` to protect against external service failures, with configurable failure thresholds and retry timeouts.
- **Data Retention**: Configure `storage.retention` to limit database or file storage growth, specifying retention days and maximum records.
- **Overhead**: Performance tests ensure tracking overhead is below 5ms per request.

Testing
-------

[](#testing)

Run the test suite:

```
vendor/bin/phpunit
```

Perform static analysis and linting:

```
vendor/bin/phpstan analyze
vendor/bin/ecs check
vendor/bin/rector process --dry-run
```

The bundle includes:

- **Unit Tests**: Cover all services and components (100% coverage).
- **Integration Tests**: Validate end-to-end workflows with database storage.
- **Performance Tests**: Measure tracking overhead.
- **Edge Case Tests**: Handle database failures and high-load scenarios.

Uninstallation
--------------

[](#uninstallation)

Remove the bundle:

```
composer remove 2a/symfony-performance-analyzer
```

Drop database tables (if using database storage):

```
php bin/console doctrine:query:sql "DROP TABLE performance_log, performance_stat"
```

Remove configuration files and assets:

```
rm config/packages/symfony_performance_analyzer.yaml
rm -rf var/performance
```

Contributing
------------

[](#contributing)

1. Fork the repository.
2. Create a feature branch: `git checkout -b feature/my-feature`
3. Commit changes: `git commit -am 'Add my feature'`
4. Push to the branch: `git push origin feature/my-feature`
5. Open a Pull Request.

Ensure all tests pass and adhere to coding standards (ECS, Rector, PHPStan).

License
-------

[](#license)

This bundle is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance31

Infrequent updates — may be unmaintained

Popularity10

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity56

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

6

Last Release

348d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/b688a46c87f4956e68a55c6cc99c1630807aa1c6ac2738f241a51cca032ec670?d=identicon)[ajenguianis](/maintainers/ajenguianis)

---

Top Contributors

[![ajenguianis](https://avatars.githubusercontent.com/u/48988628?v=4)](https://github.com/ajenguianis "ajenguianis (4 commits)")

---

Tags

ai-recommendationsanalyzerbundlechartjscode-qualitydashboardmetricsn-plus-oneoptimizationperformance-analysisphpreportingsymfonysymfonyperformancedashboardn-plus-oneanalyzerai-recommendations

###  Code Quality

TestsPHPUnit

Static AnalysisPHPStan, Rector

Code StyleECS

Type Coverage Yes

### Embed Badge

![Health badge](/badges/2a-symfony-performance-analyzer/health.svg)

```
[![Health](https://phpackages.com/badges/2a-symfony-performance-analyzer/health.svg)](https://phpackages.com/packages/2a-symfony-performance-analyzer)
```

###  Alternatives

[sylius/sylius

E-Commerce platform for PHP, based on Symfony framework.

8.4k5.6M651](/packages/sylius-sylius)[prestashop/prestashop

PrestaShop is an Open Source e-commerce platform, committed to providing the best shopping cart experience for both merchants and customers.

9.0k15.4k](/packages/prestashop-prestashop)[sulu/sulu

Core framework that implements the functionality of the Sulu content management system

1.3k1.3M152](/packages/sulu-sulu)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[easycorp/easyadmin-bundle

Admin generator for Symfony applications

4.3k16.7M310](/packages/easycorp-easyadmin-bundle)[contao/core-bundle

Contao Open Source CMS

1231.6M2.4k](/packages/contao-core-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
