ekino/console-metrics-bundle 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

ekino/console-metrics-bundle

最新稳定版本:0.0.1

Composer 安装命令:

composer require ekino/console-metrics-bundle

包简介

Monitor your commands

README 文档

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.

统计信息

  • 总下载量: 1
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 0
  • Forks: 1
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-03

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固