/** * Build the BenchmarkMetadata collection. * * @param string $path * @param array $subjectFilter * @param array $groupFilter */ public function findBenchmarks($path, array $subjectFilter = [], array $groupFilter = []) { $finder = new Finder(); $path = PhpBench::normalizePath($path); if (!file_exists($path)) { throw new \InvalidArgumentException(sprintf('File or directory "%s" does not exist (cwd: %s)', $path, getcwd())); } if (is_dir($path)) { $finder->in($path)->name('*.php'); } else { // the path is already a file, just restrict the finder to that. $finder->in(dirname($path))->depth(0)->name(basename($path)); } $benchmarks = []; foreach ($finder as $file) { if (!is_file($file)) { continue; } $benchmark = $this->factory->getMetadataForFile($file->getPathname()); if (null === $benchmark) { continue; } if ($groupFilter) { $benchmark->filterSubjectGroups($groupFilter); } if ($subjectFilter) { $benchmark->filterSubjectNames($subjectFilter); } if (false === $benchmark->hasSubjects()) { continue; } $benchmarks[] = $benchmark; } return $benchmarks; }
public function handleOutputDir(InputInterface $input, OutputInterface $output) { $outputDir = PhpBench::normalizePath($input->getOption('outdir') ?: $this->outputDir); if (!$this->filesystem->exists($outputDir)) { $output->writeln(sprintf('<comment>// creating non-existing directory %s</comment>', $outputDir)); $this->filesystem->mkdir($outputDir); } return $outputDir; }
/** * {@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; }
public function load(Container $container) { if (!class_exists(Version::class)) { throw new \RuntimeException('The DBAL extension requires the "doctrine/dbal" package. Run `composer require --dev "doctrine/dbal"`'); } $container->register('storage.driver.dbal.connection', function (Container $container) { static $connection; if ($connection) { return $connection; } $params = $container->getParameter('storage.dbal.connection'); if (isset($params['path'])) { $params['path'] = PhpBench::normalizePath($params['path']); } $connection = DriverManager::getConnection($params); return $connection; }); $container->register('storage.driver.dbal.connection_manager', function (Container $container) { return new Storage\Driver\Dbal\ConnectionManager($container->get('storage.driver.dbal.connection')); }); $container->register('storage.driver.dbal', function (Container $container) { return new Storage\Driver\DbalDriver($container->get('storage.driver.dbal.loader'), $container->get('storage.driver.dbal.persister'), $container->get('storage.driver.dbal.repository')); }, ['storage_driver' => ['name' => 'dbal']]); $container->register('storage.driver.dbal.persister', function (Container $container) { return new Storage\Driver\Dbal\Persister($container->get('storage.driver.dbal.connection_manager')); }); $container->register('storage.driver.dbal.loader', function (Container $container) { return new Storage\Driver\Dbal\Loader($container->get('storage.driver.dbal.repository')); }); $container->register('storage.driver.dbal.visitor.token_value', function (Container $container) { return new Storage\Driver\Dbal\Visitor\TokenValueVisitor($container->get('storage.uuid_resolver')); }); $container->register('storage.driver.dbal.repository', function (Container $container) { return new Storage\Driver\Dbal\Repository($container->get('storage.driver.dbal.connection_manager'), $container->get('storage.driver.dbal.visitor.token_value')); }); $container->register('command.dbal.migrate', function (Container $container) { return new MigrateCommand($container->get('storage.driver.dbal.connection')); }, ['console.command' => []]); }