2a/symfony-performance-analyzer
Installation
composer require 2a/symfony-performance-analyzer
Add to config/bundles.php:
return [
// ...
Ajenguianis\PerformanceAnalyzerBundle\AjenguianisPerformanceAnalyzerBundle::class => ['all' => true],
];
Basic Configuration
Update config/packages/ajenguianis_performance_analyzer.yaml:
ajenguianis_performance_analyzer:
enabled: true
dashboard_path: /_performance
alerts:
response_time: 500ms
First Use Case
/_performance to see real-time metrics.php bin/console cache:clear) and check the "CLI Performance" tab.Request Profiling
enabled: true in config. No manual instrumentation needed.PerformanceAnalyzer::start() and stop() for granular control:
use Ajenguianis\PerformanceAnalyzerBundle\PerformanceAnalyzer;
$analyzer = PerformanceAnalyzer::getInstance();
$analyzer->start('custom_section');
// ... code ...
$analyzer->stop('custom_section');
N+1 Query Detection
ajenguianis_performance_analyzer:
n_plus_1:
max_queries_per_request: 50
max_duplicates: 3
Cognitive Complexity
php bin/console performance:complexity:scan src/
config/packages/ajenguianis_performance_analyzer.yaml:
complexity:
max_complexity: 10
excluded_paths: ['src/Migrations/*']
CI/CD Integration
php bin/console performance:report:generate --format=json --output=report.json
php bin/console performance:badge:generate --threshold=500ms --output=badge.svg
- name: Run Performance Tests
run: php bin/console performance:report:generate --format=json
- name: Upload Report
uses: actions/upload-artifact@v3
with:
name: performance-report
path: report.json
Alerting
config/packages/ajenguianis_performance_analyzer.yaml:
alerts:
webhook_url: 'https://your-webhook.example.com/alerts'
enabled: true
performance:alert:slack command with a pre-configured webhook.AjenguianisPerformanceAnalyzerBundle\Event\QueryEvent:
use Ajenguianis\PerformanceAnalyzerBundle\Event\QueryEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
class CustomQuerySubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
return [
QueryEvent::QUERY_EXECUTED => 'onQueryExecuted',
];
}
public function onQueryExecuted(QueryEvent $event)
{
if ($event->getQuery()->getSql() === 'SELECT * FROM legacy_table') {
$event->markAsCritical('Legacy query detected');
}
}
}
monolog:
handlers:
performance:
type: stream
path: "%kernel.logs_dir%/performance.log"
level: debug
channels: ["performance"]
Then enable in the bundle config:
ajenguianis_performance_analyzer:
logging:
enabled: true
channel: performance
Dashboard Security
/_performance endpoint is not secured by default. Protect it in security.yaml:
access_control:
- { path: ^/_performance, roles: ROLE_ADMIN }
ajenguianis_performance_analyzer:
dashboard:
http_basic_auth:
username: admin
password: $2y$10$92IXUNpk... # hashed password
Performance Overhead
ajenguianis_performance_analyzer:
enabled: "%kernel.debug%" # Only in dev
php bin/console performance:complexity:scan --parallel=4 src/
Doctrine Proxy Issues
ajenguianis_performance_analyzer:
n_plus_1:
excluded_entities: ['App\Entity\Proxy\__CG__\User']
CLI Command Conflicts
performance:* to prevent conflicts with the bundle’s commands.Log Levels
config/packages/ajenguianis_performance_analyzer.yaml:
logging:
level: debug # Options: error, warning, info, debug
Query Debugging
doctrine:
dbal:
logging: true
performance:query:debug command to inspect specific queries:
php bin/console performance:query:debug --query="SELECT * FROM users"
Complexity False Positives
complexity:
max_complexity: 20
excluded_methods: ['*get*', '*set*']
Dashboard Caching
php bin/console cache:clear AjenguianisPerformanceAnalyzerBundle
Custom Metrics
PerformanceAnalyzer service:
$analyzer = PerformanceAnalyzer::getInstance();
$analyzer->addMetric('custom_metric', 42, 'Custom value');
Report Customization
templates/bundles/ajenguianisperformanceanalyzer/:
templates/
bundles/
ajenguianisperformanceanalyzer/
report/
index.html.twig # Override default template
Storage Backends
Ajenguianis\PerformanceAnalyzerBundle\Storage\StorageInterface and configuring:
ajenguianis_performance_analyzer:
storage:
class: App\Storage\CustomPerformanceStorage
Event Listeners
use Ajenguianis\PerformanceAnalyzerBundle\Event\PerformanceEvent;
$dispatcher->addListener(PerformanceEvent::REQUEST_COMPLETED, function (PerformanceEvent $event) {
if ($event->getTotalDuration() > 1000) {
// Trigger fallback logic
}
});
Badge Customization
BadgeGenerator:
use Ajenguianis\PerformanceAnalyzerBundle\Generator\BadgeGenerator;
class CustomBadgeGenerator extends BadgeGenerator
{
protected function getColor(int $score): string
{
return $score > 800 ? 'red' : 'yellow';
}
}
Then configure in services.yaml:
Ajenguianis\PerformanceAnalyzerBundle\Generator\BadgeGenerator:
class: App\Generator\CustomBadgeGenerator
How can I help you explore Laravel packages today?