It represents the result rather than the details of how to create that result.
Esempio n. 1
0
 private function processVariant(Subject $subject, Variant $variant, \DOMElement $subjectEl)
 {
     $variantEl = $subjectEl->appendElement('variant');
     // TODO: These attributes should be on the subject, see
     // https://github.com/phpbench/phpbench/issues/307
     $variantEl->setAttribute('sleep', $subject->getSleep());
     $variantEl->setAttribute('output-time-unit', $subject->getOutputTimeUnit() ?: TimeUnit::MICROSECONDS);
     $variantEl->setAttribute('output-time-precision', $subject->getOutputTimePrecision());
     $variantEl->setAttribute('output-mode', $subject->getOutputMode() ?: TimeUnit::MODE_TIME);
     $variantEl->setAttribute('revs', $variant->getRevolutions());
     $variantEl->setAttribute('warmup', $variant->getWarmup());
     $variantEl->setAttribute('retry-threshold', $subject->getRetryThreshold());
     foreach ($variant->getParameterSet() as $name => $value) {
         $this->createParameter($variantEl, $name, $value);
     }
     if ($variant->hasErrorStack()) {
         $errorsEl = $variantEl->appendElement('errors');
         foreach ($variant->getErrorStack() as $error) {
             $errorEl = $errorsEl->appendElement('error', $error->getMessage());
             $errorEl->setAttribute('exception-class', $error->getClass());
             $errorEl->setAttribute('code', $error->getCode());
             $errorEl->setAttribute('file', $error->getFile());
             $errorEl->setAttribute('line', $error->getLine());
         }
         return;
     }
     $stats = $variant->getStats();
     $stats = iterator_to_array($stats);
     $resultClasses = [];
     // ensure same order (for testing)
     ksort($stats);
     foreach ($variant as $iteration) {
         $iterationEl = $variantEl->appendElement('iteration');
         foreach ($iteration->getResults() as $result) {
             // we need to store the class FQNs of the results for deserialization later.
             if (!isset($resultClasses[$result->getKey()])) {
                 $resultClasses[$result->getKey()] = get_class($result);
             }
             $prefix = $result->getKey();
             $metrics = $result->getMetrics();
             foreach ($metrics as $key => $value) {
                 $iterationEl->setAttribute(sprintf('%s-%s', $prefix, str_replace('_', '-', $key)), $value);
             }
         }
     }
     $statsEl = $variantEl->appendElement('stats');
     foreach ($stats as $statName => $statValue) {
         $statsEl->setAttribute($statName, $statValue);
     }
     foreach ($resultClasses as $resultKey => $classFqn) {
         if ($subjectEl->queryOne('ancestor::suite/result[@key="' . $resultKey . '"]')) {
             continue;
         }
         $resultEl = $subjectEl->queryOne('ancestor::suite')->appendElement('result');
         $resultEl->setAttribute('key', $resultKey);
         $resultEl->setAttribute('class', $classFqn);
     }
 }
Esempio n. 2
0
 public function createSubjectFromMetadata(SubjectMetadata $metadata)
 {
     $subject = new Subject($this, $metadata->getName());
     $subject->setGroups($metadata->getGroups());
     $subject->setSleep($metadata->getSleep());
     $subject->setRetryThreshold($metadata->getRetryThreshold());
     $subject->setOutputTimeUnit($metadata->getOutputTimeUnit());
     $subject->setOutputTimePrecision($metadata->getOutputTimePrecision());
     $subject->setOutputMode($metadata->getOutputMode());
     $this->subjects[] = $subject;
     return $subject;
 }
Esempio n. 3
0
 private function processSubject(Subject $subject, \DOMElement $subjectEl, array $resultClasses)
 {
     $groups = [];
     foreach ($subjectEl->query('./group') as $groupEl) {
         $groups[] = $groupEl->getAttribute('name');
     }
     $subject->setGroups($groups);
     // TODO: These attributes should be on the subject, see
     // https://github.com/phpbench/phpbench/issues/307
     foreach ($subjectEl->query('./variant') as $variantEl) {
         $subject->setSleep($variantEl->getAttribute('sleep'));
         $subject->setOutputTimeUnit($variantEl->getAttribute('output-time-unit'));
         $subject->setOutputTimePrecision($variantEl->getAttribute('output-time-precision'));
         $subject->setOutputMode($variantEl->getAttribute('output-mode'));
         $subject->setRetryThreshold($variantEl->getAttribute('retry-threshold'));
         break;
     }
     foreach ($subjectEl->query('./variant') as $index => $variantEl) {
         $parameters = $this->getParameters($variantEl);
         $parameterSet = new ParameterSet($index, $parameters);
         $stats = $this->getComputedStats($variantEl);
         $variant = $subject->createVariant($parameterSet, $variantEl->getAttribute('revs'), $variantEl->getAttribute('warmup'), $stats);
         $this->processVariant($variant, $variantEl, $resultClasses);
     }
 }
Esempio n. 4
0
 private function getVariant(\ArrayObject $context, Subject $subject, $row)
 {
     $key = $row['variant.id'];
     if (isset($context[self::VARIANTS][$key])) {
         return $context[self::VARIANTS][$key];
     }
     $variant = $subject->createVariant(new ParameterSet(0, $this->repository->getParameters($row['variant.id'])), $row['variant.revolutions'], $row['variant.warmup']);
     $context[self::VARIANTS][$key] = $variant;
     return $variant;
 }
Esempio n. 5
0
 private function runSubject(ExecutorInterface $executor, RunnerContext $context, Subject $subject, SubjectMetadata $subjectMetadata)
 {
     $parameterSets = $context->getParameterSets($subjectMetadata->getParameterSets());
     $paramsIterator = new CartesianParameterIterator($parameterSets);
     // create the variants.
     foreach ($paramsIterator as $parameterSet) {
         foreach ($subjectMetadata->getIterations() as $nbIterations) {
             foreach ($subjectMetadata->getRevs() as $revolutions) {
                 foreach ($subjectMetadata->getWarmup() as $warmup) {
                     $variant = $subject->createVariant($parameterSet, $revolutions, $warmup);
                     $variant->spawnIterations($nbIterations);
                 }
             }
         }
     }
     // run the variants.
     foreach ($subject->getVariants() as $variant) {
         $this->runVariant($executor, $context, $subjectMetadata, $variant);
     }
     return $subject;
 }