A Symfony bundle that adds detailed performance metrics to your console commands.
- 📊 Displays execution time, memory usage, and timestamps for any console command
- ⚡ Zero configuration required - works out of the box
- 🎯 Opt-in per command execution with a simple flag
- 🔧 Fully customizable option name and shortcut
- 🚀 Compatible with Symfony 7.4, and 8.0+
- PHP: >= 8.2
- Symfony: 7.4.x, or 8.0+
composer require ekino/console-metrics-bundleIf your Symfony application doesn't use Symfony Flex, manually add the bundle to your config/bundles.php file:
<?php
return [
// ...other bundles...
Ekino\ConsoleMetricsBundle\ConsoleMetricsBundle::class => ['all' => true],
];Once installed, the bundle automatically registers event listeners that:
- AddMetricsOptionListener: Adds a
--metricsoption to all console commands - ConsoleBeforeListener: Starts tracking metrics when the option is enabled
- ConsoleAfterListener: Displays the collected metrics after command execution
Simply add the --metrics option (or its shortcut -m) to any console command:
php bin/console your:command --metricsThe bundle displays the following information:
| Metric | Description |
|---|---|
| Start date | ISO 8601 timestamp when the command started |
| End date | ISO 8601 timestamp when the command completed |
| Execution time | Total time in milliseconds |
| Memory usage | Memory consumed by the command (in MB) |
| Peak memory | Maximum memory used during execution (in MB) |
You can customize the option name and shortcut by creating a configuration file at config/packages/console_metrics.yaml:
# config/packages/console_metrics.yaml
console_metrics:
metrics_option_name: 'perf' # Default: 'metrics'
metrics_option_shortcut: 'p' # Default: 'm'With this configuration, you would use:
php bin/console your:command --perf
# or
php bin/console your:command -pRunning a command with the metrics option enabled:
$ php bin/console app:my-command --metrics
[INFO] The task is executed successfully
+----------------+ Metrics ------------------+
| Name | Value |
+----------------+---------------------------+
| Start date | 2025-09-30T12:56:24+00:00 |
| End date | 2025-09-30T12:56:27+00:00 |
| Execution time | 3012 ms |
| Memory usage | 22.00 MB |
| Peak memory | 22.00 MB |
+----------------+---------------------------+Using the shortcut:
$ php bin/console cache:clear -m
// Clearing the cache for the dev environment with debug true
[OK] Cache for the "dev" environment (debug=true) was successfully cleared.
+----------------+ Metrics ------------------+
| Name | Value |
+----------------+---------------------------+
| Start date | 2025-01-22T14:30:12+00:00 |
| End date | 2025-01-22T14:30:14+00:00 |
| Execution time | 1847 ms |
| Memory usage | 18.50 MB |
| Peak memory | 20.25 MB |
+----------------+---------------------------+Contributions are welcome! Please feel free to submit a Pull Request.