Sfoglia il codice sorgente

Add more output to the profiled runs, refs #1659

Jordi Boggiano 12 anni fa
parent
commit
b474944155
2 ha cambiato i file con 16 aggiunte e 0 eliminazioni
  1. 1 0
      src/Composer/Console/Application.php
  2. 15 0
      src/Composer/IO/ConsoleIO.php

+ 1 - 0
src/Composer/Console/Application.php

@@ -102,6 +102,7 @@ class Application extends BaseApplication
 
         if ($input->hasParameterOption('--profile')) {
             $startTime = microtime(true);
+            $this->io->enableDebugging($startTime);
         }
 
         $oldWorkingDir = getcwd();

+ 15 - 0
src/Composer/IO/ConsoleIO.php

@@ -29,6 +29,7 @@ class ConsoleIO implements IOInterface
     protected $helperSet;
     protected $authentications = array();
     protected $lastMessage;
+    private $startTime;
 
     /**
      * Constructor.
@@ -44,6 +45,11 @@ class ConsoleIO implements IOInterface
         $this->helperSet = $helperSet;
     }
 
+    public function enableDebugging($startTime)
+    {
+        $this->startTime = $startTime;
+    }
+
     /**
      * {@inheritDoc}
      */
@@ -73,6 +79,15 @@ class ConsoleIO implements IOInterface
      */
     public function write($messages, $newline = true)
     {
+        if (null !== $this->startTime) {
+            $messages = (array) $messages;
+            $messages[0] = sprintf(
+                '[%.1fMB/%.2fs] %s',
+                memory_get_usage() / 1024 / 1024,
+                microtime(true) - $this->startTime,
+                $messages[0]
+            );
+        }
         $this->output->write($messages, $newline);
         $this->lastMessage = join($newline ? "\n" : '', (array) $messages);
     }