Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Console Metrics Bundle Laravel Package

ekino/console-metrics-bundle

View on GitHub
Deep Wiki
Context7

Console Metrics Bundle

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.

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
elnasnato/laraliveui
labrodev/rest-sdk
sampaui/sampaui
babelqueue/php-sdk
facebook/capi-param-builder-php
babelqueue/symfony
hamzi/corewatch
minionfactory/raw-hydrator
hexters/coinpayment
rjcodes/rjcms
act-training/laravel-permissions-manager
alimarchal/laravel-chart-of-accounts
babenkoivan/elastic-scout-driver
mkwebdesign/filament-watchdog-v5
renatomarinho/laravel-page-speed
zedmagdy/filament-business-hours
renatovdemoura/blade-elements-ui
devgeek/beacon-admin
benjamin-rqt/data-watcher-bundle
atriumphp/atrium