示例#1
0
 /**
  * @return StorageApiEvent
  */
 private function prepareEvent()
 {
     $event = new StorageApiEvent();
     $event->setComponent(KeboolaOrchestratorBundle::SYRUP_COMPONENT_NAME)->setRunId($this->job->getRunId());
     if ($this->stopwatchEvent) {
         $event->setDuration($this->stopwatchEvent->stop()->getDuration() / 1000);
     }
     return $event;
 }
 /**
  * Stops the profiling
  *
  * @param StopwatchEvent $event A stopwatchEvent instance
  */
 protected function stopProfiling(StopwatchEvent $event = null)
 {
     if ($this->stopwatch instanceof Stopwatch) {
         $event->stop();
         $values = array('duration' => $event->getDuration(), 'memory_end' => memory_get_usage(true), 'memory_peak' => memory_get_peak_usage(true));
         $this->profiles[$this->counter] = array_merge($this->profiles[$this->counter], $values);
         $this->counter++;
     }
 }
    public function testHumanRepresentation()
    {
        $event = new StopwatchEvent(microtime(true) * 1000);
        $this->assertEquals('default: 0.00 MiB - 0 ms', (string) $event);
        $event->start();
        $event->stop();
        $this->assertEquals(1, preg_match('/default: [0-9\.]+ MiB - [0-9]+ ms/', (string) $event));

        $event = new StopwatchEvent(microtime(true) * 1000, 'foo');
        $this->assertEquals('foo: 0.00 MiB - 0 ms', (string) $event);
    }
示例#4
0
 public function testStartTime()
 {
     $event = new StopwatchEvent(microtime(true) * 1000);
     $this->assertLessThanOrEqual(0.5, $event->getStartTime());
     $event = new StopwatchEvent(microtime(true) * 1000);
     $event->start();
     $event->stop();
     $this->assertLessThanOrEqual(1, $event->getStartTime());
     $event = new StopwatchEvent(microtime(true) * 1000);
     $event->start();
     usleep(100000);
     $event->stop();
     $this->assertEquals(0, $event->getStartTime(), null, self::DELTA);
 }
 public function testEndTime()
 {
     $event = new StopwatchEvent(microtime(true) * 1000);
     $this->assertEquals(0, $event->getEndTime());
     $event = new StopwatchEvent(microtime(true) * 1000);
     $event->start();
     $this->assertEquals(0, $event->getEndTime());
     $event = new StopwatchEvent(microtime(true) * 1000);
     $event->start();
     usleep(100000);
     $event->stop();
     $event->start();
     usleep(100000);
     $event->stop();
     $this->assertEquals(200, $event->getEndTime(), null, self::DELTA);
 }
 /**
  * Command duration time in seconds
  *
  * @return float
  */
 protected function getDuration()
 {
     return (double) $this->stopWatchEvent->stop()->getDuration() / 1000;
 }