ekino/console-metrics-bundle

Monitor your commands

Maintainers

Package info

github.com/ekino/console-metrics-bundle

Type:symfony-bundle

pkg:composer/ekino/console-metrics-bundle

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 6

Open Issues: 0

0.0.1 2026-03-23 17:02 UTC

This package is not auto-updated.

Last update: 2026-04-03 19:12:16 UTC


README

A Symfony bundle that adds detailed performance metrics to your console commands.

Features

  • 📊 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+

Prerequisites

  • PHP: >= 8.2
  • Symfony: 7.4.x, or 8.0+

Installation

Step 1: Install the bundle

composer require ekino/console-metrics-bundle

Step 2: Register the bundle (if not using Symfony Flex)

If 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],
];

How it works

Once installed, the bundle automatically registers event listeners that:

  • AddMetricsOptionListener: Adds a --metrics option to all console commands
  • ConsoleBeforeListener: Starts tracking metrics when the option is enabled
  • ConsoleAfterListener: Displays the collected metrics after command execution

Usage

Basic usage

Simply add the --metrics option (or its shortcut -m) to any console command:

php bin/console your:command --metrics

Collected metrics

The 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)

Configuration

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 -p

Example output

Running 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                  |
+----------------+---------------------------+

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.