Track Memory Usage and Runtime of Symfony Commands

If you write lots of Console Commands in your Symfony application you sure want to know more about their memory and time consumption. To collect the necessary data you can make use of the Stopwatch Component:

You might also have noticed the Verbosity check which causes our stats only to be printed if the command is run with -v. Symfony >= 2.4 allows to do this a little bit cleaner with $output->isVerbose().

In Addition to David’s Blog Post:
Stopwatch is a debugging tool that has already an own service called debug.stopwatch. Since Stopwatch is meant to be debug only a new service like flagbit_core.stopwatch was created for usage on a production system.