Skip to content
Extraits de code Groupes Projets
Valider d0806c36 rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Add xhprof option to tests:run command.

parent 7d402e65
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -186,9 +186,11 @@ class Profiler ...@@ -186,9 +186,11 @@ class Profiler
* Initializes Profiling via XHProf. * Initializes Profiling via XHProf.
* See: https://github.com/piwik/piwik/blob/master/tests/README.xhprof.md * See: https://github.com/piwik/piwik/blob/master/tests/README.xhprof.md
*/ */
public static function setupProfilerXHProf($mainRun = false) public static function setupProfilerXHProf($mainRun = false, $setupDuringTracking = false)
{ {
if(SettingsServer::isTrackerApiRequest()) { if (!$setupDuringTracking
&& SettingsServer::isTrackerApiRequest()
) {
// do not profile Tracker // do not profile Tracker
return; return;
} }
...@@ -237,9 +239,6 @@ class Profiler ...@@ -237,9 +239,6 @@ class Profiler
} }
$runs = self::getProfilingRunIds(); $runs = self::getProfilingRunIds();
$runs[] = $runId; $runs[] = $runId;
// $weights = array_fill(0, count($runs), 1);
// $aggregate = xhprof_aggregate_runs($xhprofRuns, $runs, $weights, $profilerNamespace);
// $runId = $xhprofRuns->save_run($aggregate, $profilerNamespace);
if($mainRun) { if($mainRun) {
$runIds = implode(',', $runs); $runIds = implode(',', $runs);
......
...@@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputOption; ...@@ -16,6 +16,7 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
/** /**
* Executes PHP tests.
*/ */
class TestsRun extends ConsoleCommand class TestsRun extends ConsoleCommand
{ {
...@@ -25,6 +26,7 @@ class TestsRun extends ConsoleCommand ...@@ -25,6 +26,7 @@ class TestsRun extends ConsoleCommand
$this->setDescription('Run Piwik PHPUnit tests one group after the other'); $this->setDescription('Run Piwik PHPUnit tests one group after the other');
$this->addArgument('group', InputArgument::OPTIONAL, 'Run only a specific test group. Separate multiple groups by comma, for instance core,integration', ''); $this->addArgument('group', InputArgument::OPTIONAL, 'Run only a specific test group. Separate multiple groups by comma, for instance core,integration', '');
$this->addOption('options', 'o', InputOption::VALUE_OPTIONAL, 'All options will be forwarded to phpunit', ''); $this->addOption('options', 'o', InputOption::VALUE_OPTIONAL, 'All options will be forwarded to phpunit', '');
$this->addOption('xhprof', null, InputOption::VALUE_NONE, 'Profile using xhprof.');
} }
protected function execute(InputInterface $input, OutputInterface $output) protected function execute(InputInterface $input, OutputInterface $output)
...@@ -67,10 +69,17 @@ class TestsRun extends ConsoleCommand ...@@ -67,10 +69,17 @@ class TestsRun extends ConsoleCommand
$command = sprintf('php -d zend_extension=%s %s', $xdebugFile, $phpunitPath); $command = sprintf('php -d zend_extension=%s %s', $xdebugFile, $phpunitPath);
} }
if(empty($groups)) { if (empty($groups)) {
$groups = $this->getTestsGroups(); $groups = $this->getTestsGroups();
} }
foreach($groups as $group) {
if ($input->getOption('xhprof')) {
Profiler::setupProfilerXHProf($isMainRun = true);
putenv('PIWIK_USE_XHPROF=1');
}
foreach ($groups as $group) {
$params = '--group ' . $group . ' ' . str_replace('%group%', $group, $options); $params = '--group ' . $group . ' ' . str_replace('%group%', $group, $options);
$cmd = sprintf('cd %s/tests/PHPUnit && %s %s', PIWIK_DOCUMENT_ROOT, $command, $params); $cmd = sprintf('cd %s/tests/PHPUnit && %s %s', PIWIK_DOCUMENT_ROOT, $command, $params);
$output->writeln('Executing command: <info>' . $cmd . '</info>'); $output->writeln('Executing command: <info>' . $cmd . '</info>');
...@@ -83,5 +92,4 @@ class TestsRun extends ConsoleCommand ...@@ -83,5 +92,4 @@ class TestsRun extends ConsoleCommand
{ {
return array('Core', 'Plugins', 'Integration', 'UI'); return array('Core', 'Plugins', 'Integration', 'UI');
} }
}
} \ No newline at end of file
...@@ -243,6 +243,10 @@ class Fixture extends PHPUnit_Framework_Assert ...@@ -243,6 +243,10 @@ class Fixture extends PHPUnit_Framework_Assert
if ($this->testEnvironment === null) { if ($this->testEnvironment === null) {
$this->testEnvironment = new Piwik_TestingEnvironment(); $this->testEnvironment = new Piwik_TestingEnvironment();
$this->testEnvironment->delete(); $this->testEnvironment->delete();
if (getenv('PIWIK_USE_XHPROF') == 1) {
$this->testEnvironment->useXhprof = true;
}
} }
return $this->testEnvironment; return $this->testEnvironment;
} }
......
...@@ -132,6 +132,10 @@ class Piwik_TestingEnvironment ...@@ -132,6 +132,10 @@ class Piwik_TestingEnvironment
} }
} }
if ($testingEnvironment->useXhprof) {
\Piwik\Profiler::setupProfilerXHProf($mainRun = false, $setupDuringTracking = true);
}
Config::setSingletonInstance(new Config( Config::setSingletonInstance(new Config(
$testingEnvironment->configFileGlobal, $testingEnvironment->configFileLocal, $testingEnvironment->configFileCommon $testingEnvironment->configFileGlobal, $testingEnvironment->configFileLocal, $testingEnvironment->configFileCommon
)); ));
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter