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); } }
private function appendEnvironment(\DOMElement $suiteEl) { $envEl = $suiteEl->appendElement('env'); $informations = $this->envSupplier->getInformations(); foreach ($informations as $information) { $infoEl = $envEl->appendElement($information->getName()); foreach ($information as $key => $value) { $infoEl->setAttribute($key, $value); } } }
private function runIterations(RunnerContext $context, SubjectMetadata $subject, ParameterSet $parameterSet, \DOMElement $variantEl) { $iterationCount = $context->getIterations($subject->getIterations()); $revolutionCount = $context->getRevolutions($subject->getRevs()); $iterationCollection = new IterationCollection($subject, $parameterSet, $context->getRetryThreshold($this->retryThreshold)); $this->logger->iterationsStart($iterationCollection); $iterations = $iterationCollection->spawnIterations($iterationCount, $revolutionCount); foreach ($iterations as $iteration) { $this->runIteration($iteration, $subject->getSleep()); $iterationCollection->add($iteration); } $iterationCollection->computeStats(); $this->logger->iterationsEnd($iterationCollection); while ($iterationCollection->getRejectCount() > 0) { $this->logger->retryStart($iterationCollection->getRejectCount()); $this->logger->iterationsStart($iterationCollection); foreach ($iterationCollection->getRejects() as $reject) { $reject->incrementRejectionCount(); $this->runIteration($reject, $context->getSleep($subject->getSleep())); } $iterationCollection->computeStats(); $this->logger->iterationsEnd($iterationCollection); } $stats = $iterationCollection->getStats(); foreach ($iterationCollection as $iteration) { $iterationEl = $variantEl->ownerDocument->createElement('iteration'); $iterationEl->setAttribute('revs', $iteration->getRevolutions()); $iterationEl->setAttribute('time-net', $iteration->getResult()->getTime()); $iterationEl->setAttribute('time', $iteration->getResult()->getTime() / $iteration->getRevolutions()); $iterationEl->setAttribute('z-value', $iteration->getZValue()); $iterationEl->setAttribute('memory', $iteration->getResult()->getMemory()); $iterationEl->setAttribute('deviation', $iteration->getDeviation()); $iterationEl->setAttribute('rejection-count', $iteration->getRejectionCount()); $variantEl->appendChild($iterationEl); } $statsEl = $variantEl->appendElement('stats'); foreach ($stats as $statName => $statValue) { $statsEl->setAttribute($statName, $statValue); } }
private function appendException(\DOMElement $node, \Exception $exception) { $errorsEl = $node->appendElement('errors'); do { $errorEl = $errorsEl->appendElement('error', $exception->getMessage()); $errorEl->setAttribute('exception-class', get_class($exception)); $errorEl->setAttribute('code', $exception->getCode()); $errorEl->setAttribute('file', $exception->getFile()); $errorEl->setAttribute('line', $exception->getLine()); } while ($exception = $exception->getPrevious()); }