Example #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);
     }
 }