/**
  * Profile command
  * 
  * @param string $command
  * @return array
  */
 public function profileCommand($command)
 {
     $tasks = $this->Task->find('all', array('conditions' => array('command' => $command, 'status' => array(TaskType::STOPPED, TaskType::FINISHED), 'runtime >' => 0), 'fields' => array('runtime', 'id', 'started', 'stopped', 'created', 'waittime'), 'limit' => Configure::read('Task.profilerLimit'), 'order' => array('id' => 'DESC')));
     if (!$tasks) {
         return null;
     }
     $statistics = array_map(function ($item) {
         $endDate = new DateTime($item['stopped']);
         $startDate = new DateTime($item['started']);
         $createdDate = new DateTime($item['created']);
         $item['runtimeHuman'] = $startDate->diff($endDate)->format(Configure::read('Task.dateDiffFormat'));
         $item['waittimeHuman'] = $createdDate->diff($startDate)->format(Configure::read('Task.dateDiffFormat'));
         $item['startedTimestamp'] = $startDate->getTimestamp();
         $item['runtime'] = (int) $item['runtime'];
         $item['waittime'] = (int) $item['waittime'];
         return $item;
     }, Hash::extract($tasks, '{n}.{s}'));
     $runtimes = Hash::extract($statistics, '{n}.runtime');
     $runtimeAverage = (int) round($runtimes ? array_sum($runtimes) / count($runtimes) : 0);
     $runtimeMax = $runtimes ? max($runtimes) : 0;
     $runtimeMin = $runtimes ? min($runtimes) : 0;
     $waittimes = Hash::extract($statistics, '{n}.waittime');
     $waittimeAverage = (int) round($waittimes ? array_sum($waittimes) / count($waittimes) : 0);
     $waittimeMax = $waittimes ? max($waittimes) : 0;
     $waittimeMin = $waittimes ? min($waittimes) : 0;
     $countByStatus = array();
     foreach (TaskType::getTypes() as $statusCode) {
         $countByStatus[$statusCode] = $this->Task->find('count', array('conditions' => array('command' => $command, 'status' => $statusCode)));
     }
     $errored = $this->Task->find('count', array('conditions' => array('command' => $command, 'errored' => true)));
     return array('command' => $command, 'countByStatus' => $countByStatus, 'errored' => $errored, 'statistics' => $statistics, 'runtimeAverage' => $runtimeAverage, 'runtimeAverageHuman' => $this->_secondsToHuman($runtimeAverage), 'runtimeMax' => $runtimeMax, 'runtimeMaxHuman' => $this->_secondsToHuman($runtimeMax), 'runtimeMin' => $runtimeMin, 'runtimeMinHuman' => $this->_secondsToHuman($runtimeMin), 'waittimeAverage' => $waittimeAverage, 'waittimeAverageHuman' => $this->_secondsToHuman($waittimeAverage), 'waittimeMax' => $waittimeMax, 'waittimeMaxHuman' => $this->_secondsToHuman($waittimeMax), 'waittimeMin' => $waittimeMin, 'waittimeMinHuman' => $this->_secondsToHuman($waittimeMin));
 }
 /**
  * Test types
  */
 public function testType()
 {
     $this->assertSame(array('UNSTARTED' => (int) 0, 'DEFFERED' => (int) 1, 'RUNNING' => (int) 2, 'FINISHED' => (int) 3, 'STOPPING' => (int) 4, 'STOPPED' => (int) 5), TaskType::getTypes());
 }