@@ -33,6 +33,8 @@ class Command
3333 protected $ _stdout = null ;
3434 protected $ _stderr = null ;
3535 protected $ _callback = null ;
36+ protected $ _timestart = null ;
37+ protected $ _timeend = null ;
3638 protected $ _cwd = null ;
3739 protected $ _env = null ;
3840 protected $ _conf = array ();
@@ -189,6 +191,7 @@ public function run($stdin = null)
189191 $ this ->_exitcode = null ;
190192 $ this ->_stdout = null ;
191193 $ this ->_stderr = null ;
194+ $ this ->_timestart = microtime (true );
192195
193196 // Prepare the buffers structure
194197 $ buffers = array (
@@ -197,9 +200,10 @@ public function run($stdin = null)
197200 2 => &$ this ->_stderr ,
198201 );
199202 $ this ->_exitcode = self ::exec ($ this ->getFullCommand (), $ buffers , $ this ->_callback , $ this ->_cwd , $ this ->_env , $ this ->_conf );
203+ $ this ->_timeend = microtime (true );
200204
201205 if ($ this ->_throw && $ this ->_exitcode !== 0 ) {
202- throw new CommandException ($ this , "Command failed ' " . $ this -> getFullCommand (). " ': \n" .trim ($ this ->getStdErr ()));
206+ throw new CommandException ($ this , "Command failed ' $ this ': \n" .trim ($ this ->getStdErr ()));
203207 }
204208
205209 return $ this ;
@@ -250,6 +254,17 @@ public function getStdErr()
250254 return $ this ->_stderr ;
251255 }
252256
257+ /**
258+ * Gets the duration of the command execution
259+ *
260+ * @param bool $microseconds If true, return microseconds (float), otherwise seconds (int)
261+ * @return int|float
262+ */
263+ public function getDuration ($ microseconds =false )
264+ {
265+ $ duration = $ this ->_timeend - $ this ->_timestart ;
266+ return $ microseconds ? $ duration : round ($ duration );
267+ }
253268
254269 /**
255270 * Executes a command returning the exitcode and capturing the stdout and stderr
0 commit comments