/**
  * {@inheritdoc}
  */
 public function launch(Payload $payload, Iteration $iteration, Config $config)
 {
     $name = XDebugUtil::filenameFromIteration($iteration);
     $dir = $config['output_dir'];
     $phpConfig = ['xdebug.trace_output_name' => $name, 'xdebug.trace_output_dir' => $dir, 'xdebug.trace_format' => '1', 'xdebug.auto_trace' => '1', 'xdebug.coverage_enable' => '0'];
     $payload->setPhpConfig($phpConfig);
     $path = $dir . DIRECTORY_SEPARATOR . $name . '.xt';
     $result = $payload->launch();
     if (false === $this->filesystem->exists($path)) {
         throw new \RuntimeException(sprintf('Trace file at "%s" was not generated. Is XDebug enabled in the benchmarking environment', $path));
     }
     $dom = $this->converter->convert($path);
     $subject = $iteration->getVariant()->getSubject();
     $class = $subject->getBenchmark()->getClass();
     if (substr($class, 0, 1) == '\\') {
         $class = substr($class, 1);
     }
     // extract only the timings for the benchmark class, ignore the bootstrapping
     $selector = '//entry[@function="' . $class . '->' . $subject->getName() . '"]';
     // calculate stats from the trace
     $time = (int) ($dom->evaluate(sprintf('sum(%s/@end-time) - sum(/@start-time)', $selector, $selector)) * 1000000.0);
     $memory = (int) $dom->evaluate(sprintf('sum(%s/@end-memory) - sum(/@start-memory)', $selector, $selector));
     $funcCalls = (int) $dom->evaluate('count(' . $selector . '//*)');
     $iteration->setResult(new TimeResult($result['time']));
     $iteration->setResult(MemoryResult::fromArray($result['mem']));
     $iteration->setResult(new XDebugTraceResult($time, $memory, $funcCalls));
 }
Example #2
0
 /**
  * {@inheritdoc}
  */
 public function launch(Payload $payload, Iteration $iteration, Config $config)
 {
     $name = XDebugUtil::filenameFromIteration($iteration);
     $dir = $config['output_dir'];
     $phpConfig = ['xdebug.trace_output_name' => $name, 'xdebug.trace_output_dir' => $dir, 'xdebug.trace_format' => '1', 'xdebug.auto_trace' => '1', 'xdebug.coverage_enable' => '0', 'xdebug.collect_params' => '3'];
     $payload->setPhpConfig($phpConfig);
     $path = $dir . DIRECTORY_SEPARATOR . $name . '.xt';
     // if the file exists, remove it. XDebug might not be installed
     // on the PHP binary and the file may not be generated. We should
     // fail in such a case and not use the file from a previous run.
     if ($this->filesystem->exists($path)) {
         $this->filesystem->remove($path);
     }
     $result = $payload->launch();
     if (false === $this->filesystem->exists($path)) {
         throw new \RuntimeException(sprintf('Trace file at "%s" was not generated.', $path));
     }
     $dom = $this->converter->convert($path);
     $subject = $iteration->getVariant()->getSubject();
     $class = $subject->getBenchmark()->getClass();
     // remove leading slash from class name for matching
     // the class in the trace.
     if (substr($class, 0, 1) == '\\') {
         $class = substr($class, 1);
     }
     // extract only the timings for the benchmark class, ignore the bootstrapping
     $selector = '//entry[@function="' . $class . '->' . $subject->getName() . '"]';
     // calculate stats from the trace
     $time = (int) ($dom->evaluate(sprintf('number(%s/@end-time) - number(%s/@start-time)', $selector, $selector)) * 1000000.0);
     $memory = (int) $dom->evaluate(sprintf('number(%s/@end-memory) - number(%s/@start-memory)', $selector, $selector));
     $funcCalls = (int) $dom->evaluate('count(' . $selector . '//*)');
     $iteration->setResult(new TimeResult($result['time']));
     $iteration->setResult(MemoryResult::fromArray($result['mem']));
     $iteration->setResult(new XDebugTraceResult($time, $memory, $funcCalls, $dom));
 }
Example #3
0
 /**
  * {@inheritdoc}
  */
 public function launch(Payload $payload, Iteration $iteration, Config $options)
 {
     $phpConfig = array('max_execution_time' => 0);
     $payload->setPhpConfig($phpConfig);
     $result = $payload->launch();
     if (isset($result['buffer']) && $result['buffer']) {
         throw new \RuntimeException(sprintf('Benchmark made some noise: %s', $result['buffer']));
     }
     return new IterationResult($result['time'], $result['memory']);
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function launch(Payload $payload, Iteration $iteration, Config $options)
 {
     $phpConfig = ['max_execution_time' => 0];
     $payload->setPhpConfig($phpConfig);
     $result = $payload->launch();
     if (isset($result['buffer']) && $result['buffer']) {
         throw new \RuntimeException(sprintf('Benchmark made some noise: %s', $result['buffer']));
     }
     $iteration->setResult(new TimeResult($result['time']));
     $iteration->setResult(MemoryResult::fromArray($result['mem']));
 }
Example #5
0
 /**
  * {@inheritdoc}
  */
 public function launch(Payload $payload, Iteration $iteration, Config $config)
 {
     $outputDir = $config['output_dir'];
     $callback = $config['callback'];
     $name = XDebugUtil::filenameFromIteration($iteration, '.cachegrind');
     $phpConfig = ['xdebug.profiler_enable' => 1, 'xdebug.profiler_output_dir' => PhpBench::normalizePath($outputDir), 'xdebug.profiler_output_name' => $name];
     $payload->setPhpConfig($phpConfig);
     $result = $payload->launch();
     if (isset($result['buffer']) && $result['buffer']) {
         throw new \RuntimeException(sprintf('Benchmark made some noise: %s', $result['buffer']));
     }
     $callback($iteration, $result);
     $iteration->setResult(new TimeResult($result['time']));
     $iteration->setResult(MemoryResult::fromArray($result['mem']));
     return $result;
 }
Example #6
0
 /**
  * {@inheritdoc}
  */
 public function launch(Payload $payload, Iteration $iteration, Config $config)
 {
     $outputDir = $config['output_dir'];
     $callback = $config['callback'];
     $name = XDebugUtil::filenameFromIteration($iteration);
     $phpConfig = array('xdebug.profiler_enable' => 1, 'xdebug.profiler_output_dir' => $outputDir, 'xdebug.profiler_output_name' => $name);
     if (!extension_loaded('xdebug')) {
         $phpConfig['zend_extension'] = 'xdebug.so';
     }
     $payload->setPhpConfig($phpConfig);
     $result = $payload->launch();
     if (isset($result['buffer']) && $result['buffer']) {
         throw new \RuntimeException(sprintf('Benchmark made some noise: %s', $result['buffer']));
     }
     $result = new IterationResult($result['time'], $result['memory']);
     $callback($iteration, $result);
     return $result;
 }
Example #7
0
 /**
  * It should throw an execption if a template is not found.
  *
  * @expectedException RuntimeException
  * @expectedExceptionMessage Could not find script template
  */
 public function testTemplateNotFound()
 {
     $process = $this->prophesize('Symfony\\Component\\Process\\Process');
     $payload = new Payload(__DIR__ . '/template/not-existing-filename.template', array(), $process->reveal());
     $payload->launch($payload);
 }
Example #8
0
 /**
  * It should throw an execption if a template is not found.
  *
  * @expectedException RuntimeException
  * @expectedExceptionMessage Could not find script template
  */
 public function testTemplateNotFound()
 {
     $process = $this->prophesize(Process::class);
     $payload = new Payload(__DIR__ . '/template/not-existing-filename.template', [], null, $process->reveal());
     $payload->launch($payload);
 }