DEV Community

rahul chavan
rahul chavan

Posted on

From Personal Tool to Open Source: Console Profiler Bundle

Hey everyone! πŸ‘‹

If there's one thing I've learned from using Symfony since version 2, it's that as your application scales, so do your hidden bottlenecks. Over the years, I've built dozens of little utilities and scripts for my personal use cases to help debug long-running console queue workers, heavy data imports, and nightly cron jobs.

Recently, I looked back at some of these tools and realized they could be incredibly helpful to the broader community. So, I took one of my tools, completely modernized it for PHP 8.4 and Symfony 8.0, and decided to open-source it.

I'm excited to share the Console Profiler Bundle with you all.

But Why Another Profiler?

The standard Symfony Web Profiler is absolutely amazing for HTTP requests. It's the gold standard. But what happens when you run a heavy queue worker (messenger:consume) and you want to know if it's leaking memory? What if a CLI sync command is hammering your database with N+1 queries in the background?

You typically have to pepper your code with memory_get_usage() dumps or echo "Running query...", which is tedious and messy.

The Console Profiler Bundle solves this by hooking right into your terminal and giving you a live, auto-refreshing
TUI while your commands are actually running.

Key Features

I wanted this bundle to be as zero-config and plug-and-play as possible while providing deep insights. Here’s what it tracks for you in real time:

  • Memory Tracking: Live memory usage, peak memory, and even a live growth rate indicator (+X MB/s). If you see a steady red upward trend, you know you've got a memory leak.
  • SQL Query Counting: Zero-config automatic SQL query counting via Doctrine DBAL 4 Middleware. It tracks exactly how many queries your command is making in real time.
  • CPU Time: Tracks both user and system CPU time via getrusage().
  • Performance Trends: Real-time trend indicators (↑ ↓ β†’) for both memory and SQL queries so you can spot spikes instantly.
  • JSON Profiler Export: You can optionally dump a JSON report at the end of the command. I use this heavily in CI pipelines to automatically fail builds if a CLI N+1 regression sneaks in!

The Journey to Open Source

Moving from a "personal hack" to an open-source library was an eye-opening experience. I had to rip out a lot of hardcoded assumptions and ensure the codebase adheres strictly to modern standards.

Modernizing the code to leverage the features of PHP 8.4 and Symfony 8 was a blast, and honestly, seeing the live terminal dashboard update smoothly feels like magic. I also made sure the TUI degrades gracefully when ext-pcntl isn't available.

Try It Out!

If you are running PHP 8.4+ and Symfony 8.0+, you can load it in as a dev dependency right now:

composer require --dev rcsofttech/console-profiler-bundle
Enter fullscreen mode Exit fullscreen mode

It works out of the boxβ€”just run any console command like bin/console messenger:consume async and look at the top of your terminal.

If you don't use it or want to turn it off, it gracefully steps aside. Oh, and it's smart enough to turn itself off in production!

You can find the repo here: rcsofttech85/ConsoleProfilerBundle

I Need Your Feedback!

Since this is my transition from keeping things internal to releasing them to the world, I would absolutely love to hear your thoughts.

  • Does this solve a problem you face with Symfony console commands?
  • Are there specific metrics you wish were tracked in the terminal?
  • Do you like the TUI layout?

Please drop a comment below or open an issue/PR on GitHub. Your feedback is what will shape the future of this tool. Let's build better CLIs together! πŸš€

Top comments (0)