nowo-tech / performance-bundle
Symfony bundle for tracking and analyzing route performance metrics. Records request time, database queries count, and query execution time for performance analysis.
Installs: 141
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Type:symfony-bundle
pkg:composer/nowo-tech/performance-bundle
Requires
- php: >=8.1 <8.6
- doctrine/doctrine-bundle: ^2.8 || ^3.0
- doctrine/orm: ^2.13 || ^3.0
- symfony/form: ^6.1 || ^7.0 || ^8.0
- symfony/framework-bundle: ^6.1 || ^7.0 || ^8.0
- symfony/security-bundle: ^6.1 || ^7.0 || ^8.0
- symfony/stopwatch: ^6.1 || ^7.0 || ^8.0
- symfony/translation: ^6.1 || ^7.0 || ^8.0
- symfony/twig-bundle: ^6.1 || ^7.0 || ^8.0
- symfony/ux-icons: ^2.0 || ^3.0
- symfony/ux-twig-component: ^2.0 || ^3.0
- symfony/yaml: ^6.1 || ^7.0 || ^8.0
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.0
- phpunit/phpunit: ^10.0
- rector/rector: ^0.14.8|^0.15
Suggests
- symfony/http-client: For webhook notifications (Slack, Teams, custom webhooks)
README
β Found this project useful? Give it a star on GitHub! It helps us maintain and improve the project.
Symfony bundle for tracking and analyzing route performance metrics. Automatically records request time, database query count, and query execution time for performance analysis.
π Compatible with Symfony 6.1+, 7.x, and 8.x - This bundle requires Symfony 6.1 or higher.
What is this?
This bundle helps you track and analyze route performance in your Symfony applications:
- π Automatic Performance Tracking - Automatically tracks route performance metrics
- π Query Analysis - Counts and times database queries per route
- β±οΈ Request Timing - Measures request execution time
- π Performance Analysis - Identifies slow routes and query-heavy endpoints
- π― Route Metrics - Stores metrics per route and environment
- π§ Manual Updates - Command to manually set/update route metrics
Quick Search Terms
Looking for: route performance, performance monitoring, query tracking, Symfony performance, route metrics, performance analysis, database query tracking, request timing, profiling, performance bundle? You've found the right bundle!
Features
- β Automatic route performance tracking via event subscribers
- β Database query counting and execution time tracking
- β Request execution time measurement
- β Memory usage tracking - Track peak memory consumption per route
- β Access frequency tracking - Track how often routes are accessed
- β HTTP status code tracking - Track and calculate ratios for HTTP status codes (200, 404, 500, etc.)
- β Sub-request tracking - Optional tracking of sub-requests (ESI, fragments, includes) in addition to main requests
- β Performance notifications - Email, Slack, Teams, and webhook notifications for performance alerts
- β Route data persistence in database
- β Environment-specific metrics (dev, test, prod)
- β Configurable route ignore list
- β Command to manually set/update route metrics
- β Support for multiple Doctrine connections
- β Performance dashboard with filtering and sorting
- β Data export - CSV and JSON export functionality
- β Record management - Delete individual records (optional)
- β Review system - Mark and edit records as reviewed with improvement tracking (optional)
- β Bootstrap and Tailwind CSS support - Choose your preferred CSS framework
- β Role-based access control for dashboard
- β WebProfiler integration with ranking information
- β Chart.js integration - Interactive performance charts
- β Symfony UX Twig Components - Optional modern component system
- β Symfony 6.1+, 7.x, and 8.x compatible
Installation
composer require nowo-tech/performance-bundle
Then, register the bundle in your config/bundles.php:
<?php return [ // ... Nowo\PerformanceBundle\NowoPerformanceBundle::class => ['all' => true], ];
Quick Start
- Configure the bundle (optional - works with defaults):
# config/packages/nowo_performance.yaml nowo_performance: enabled: true environments: ['prod', 'dev', 'test'] connection: 'default' track_queries: true track_request_time: true ignore_routes: - '_wdt' - '_profiler' - 'web_profiler*' - '_error' dashboard: enabled: true path: '/performance' template: 'bootstrap' # or 'tailwind' roles: ['ROLE_ADMIN'] # Optional: restrict access
-
Create the database table:
Option A: Using the bundle command (Recommended):
php bin/console nowo:performance:create-table
Option B: Using Doctrine Schema Update:
php bin/console doctrine:schema:update --force
# or
php bin/console doctrine:migrations:diff
php bin/console doctrine:migrations:migrate
- That's it! The bundle will automatically track route performance metrics.
For detailed installation steps (including sync-schema and migrations), see Installation Guide.
Usage
Automatic Tracking
The bundle automatically tracks performance metrics for all routes (except ignored ones) in configured environments.
Manual Metrics Update
Use the command to manually set or update route metrics:
# Set route metrics php bin/console nowo:performance:set-route app_home \ --env=dev \ --request-time=0.5 \ --queries=10 \ --query-time=0.2 # Update with worse metrics (higher time or more queries) php bin/console nowo:performance:set-route app_user_show \ --env=prod \ --request-time=1.2 \ --queries=25 \ --query-time=0.3 \ --params='{"id":123}'
Accessing Metrics
use Nowo\PerformanceBundle\Service\PerformanceMetricsService; // Get route data $routeData = $metricsService->getRouteData('app_home', 'dev'); // Get all routes for environment $routes = $metricsService->getRoutesByEnvironment('dev'); // Get worst performing routes $worstRoutes = $metricsService->getWorstPerformingRoutes('dev', 10);
Requirements
- PHP >= 8.1, < 8.6
- Symfony >= 6.1 || >= 7.0 || >= 8.0
- Doctrine ORM >= 2.13 || >= 3.0
- Doctrine Bundle >= 2.8 || >= 3.0 (3.0 required for Symfony 8)
Configuration
The bundle works with default settings. Create config/packages/nowo_performance.yaml. For the full reference and all options, see Configuration Guide.
nowo_performance: enabled: true environments: ['prod', 'dev', 'test'] connection: 'default' table_name: 'routes_data' track_queries: true track_request_time: true track_sub_requests: false ignore_routes: - '_wdt' - '_profiler' - 'web_profiler*' - '_error' dashboard: enabled: true path: '/performance' template: 'bootstrap' # or 'tailwind' roles: [] # empty = unrestricted
Commands
See Commands for full documentation. Main commands:
nowo:performance:set-route- Set or update route performance metricsnowo:performance:create-table- Create or update the metrics tablenowo:performance:sync-schema- Sync database schema with entity metadatanowo:performance:diagnose- Diagnostic report of bundle configuration and statusnowo:performance:check-dependencies- Check status of optional dependencies
Entity Structure
The RouteData entity stores:
id- Primary keyenv- Environment (dev, test, prod)name- Route nametotalQueries- Total number of database queriesqueryTime- Total query execution time in secondsrequestTime- Request execution time in secondsmemoryUsage- Peak memory usage in bytes (nullable)accessCount- Number of times route was accessed (default: 1)lastAccessedAt- Last access timestamp (nullable)httpMethod- HTTP method (GET, POST, PUT, DELETE, etc.) (nullable)statusCodes- HTTP status codes counts (JSON, e.g., {'200': 100, '404': 5}) (nullable)reviewed- Whether record has been reviewed (default: false)reviewedAt- Review timestamp (nullable)queriesImproved- Whether queries improved after review (nullable)timeImproved- Whether time improved after review (nullable)reviewedBy- Username of reviewer (nullable)params- Route parameters (JSON)createdAt- Creation timestampupdatedAt- Last update timestamp
How It Works
- Event Subscriber (
PerformanceMetricsSubscriber) listens to kernel events - On
KernelEvents::REQUEST, it starts tracking:- Request start time
- Resets query tracking middleware
- On
KernelEvents::TERMINATE, it:- Calculates request time
- Collects query count and execution time using multiple strategies:
- Primary:
QueryTrackingMiddleware(DBAL middleware for DBAL 3.x compatibility) - Fallback 1:
DoctrineDataCollectorfrom Symfony profiler - Fallback 2: Request attributes (
_profiler,_profiler_profile) - Fallback 3: Stopwatch (time only)
- Primary:
- Saves metrics to database via
PerformanceMetricsService
- Metrics are only updated if they're worse (higher time or more queries)
Query Tracking Architecture
The bundle uses a multi-layered approach for query tracking:
- QueryTrackingMiddleware: A custom DBAL middleware that intercepts all database queries at the driver level. This is the primary method and works with DBAL 3.x (which removed
SQLLogger). - DoctrineDataCollector: Falls back to Symfony's built-in profiler data collector if the middleware is not available.
- Request Attributes: Attempts to access profiler data from request attributes for sub-requests.
- Stopwatch: Last resort fallback for timing information only (does not provide query count).
This ensures reliable query tracking across different Symfony and Doctrine versions.
Documentation
- Documentation index β Γndice de toda la documentaciΓ³n con descripciones y referencias cruzadas
- Installation Guide β Step-by-step installation
- Configuration Guide β Detailed configuration options (source of truth for defaults)
- Usage Guide β Complete usage examples
- Commands β Command documentation
- Events & priorities β Custom events and internal listener flow (relevant for
ignore_routes) - Compatibility Guide β Doctrine and DBAL version compatibility
- Notifications β Performance alert notifications (Email, Slack, Teams, Webhooks)
- CHANGELOG β Version history
- UPGRADING β Upgrade instructions
- ROADMAP β Future improvements and features
Testing
# Run tests composer test # Run with coverage composer test-coverage
License
The MIT License (MIT). Please see LICENSE for more information.
Contributing
We welcome contributions! Please see CONTRIBUTING.md for details.
Author
Created by HΓ©ctor Franco Aceituno at Nowo.tech