diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index 82bfa96b0..72b4c6b2e 100755 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -14,6 +14,7 @@ namespace Composer\Console; use Symfony\Component\Console\Application as BaseApplication; use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\Console\Formatter\OutputFormatter; @@ -83,7 +84,17 @@ class Application extends BaseApplication } } - return parent::doRun($input, $output); + if ($input->hasParameterOption('--profile')) { + $startTime = microtime(true); + } + + $result = parent::doRun($input, $output); + + if (isset($startTime)) { + $output->writeln('Memory usage: '.round(memory_get_usage() / 1024 / 1024, 2).'MB (peak: '.round(memory_get_peak_usage() / 1024 / 1024, 2).'MB), time: '.round(microtime(true) - $startTime, 2).'s'); + } + + return $result; } /** @@ -140,6 +151,17 @@ class Application extends BaseApplication return $commands; } + /** + * {@inheritDoc} + */ + protected function getDefaultInputDefinition() + { + $definition = parent::getDefaultInputDefinition(); + $definition->addOption(new InputOption('--profile', null, InputOption::VALUE_NONE, 'Display timing and memory usage information')); + + return $definition; + } + /** * {@inheritDoc} */