From eb9e188fc218cf3e68359a3c67150c97d2a28142 Mon Sep 17 00:00:00 2001 From: Benaka Moorthi Date: Thu, 16 May 2013 19:12:56 -0700 Subject: Allow easy use of XHProf when running phpunit tests from the command line. --- tests/PHPUnit/bootstrap.php | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'tests') diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php index fe0d757b4d..909005773c 100644 --- a/tests/PHPUnit/bootstrap.php +++ b/tests/PHPUnit/bootstrap.php @@ -25,6 +25,32 @@ if (!defined('PIWIK_INCLUDE_SEARCH_PATH')) { error_reporting(E_ALL | E_NOTICE); @date_default_timezone_set('UTC'); +$useXhprof = true; +if ($useXhprof) { + require_once PIWIK_INCLUDE_PATH . '/tests/lib/xhprof-0.9.2/xhprof_lib/utils/xhprof_runs.php'; + + if (!isset($profilerNamespace)) { + $firstLineOfGitHead = file(PIWIK_INCLUDE_PATH . '/.git/HEAD'); + $firstLineOfGitHead = $firstLineOfGitHead[0]; + + $parts = explode("/", $firstLineOfGitHead); + $currentGitBranch = trim($parts[2]); + + $profilerNamespace = "piwik.$currentGitBranch"; + } + + xhprof_enable(XHPROF_FLAGS_CPU + XHPROF_FLAGS_MEMORY); + + register_shutdown_function(function () use($profilerNamespace) { + $xhprofData = xhprof_disable(); + + $xhprofRuns = new \XHProfRuns_Default(); + $runId = $xhprofRuns->save_run($xhprofData, $profilerNamespace); + + echo "\n\nPROFILER RUN URL: /tests/lib/xhprof-0.9.2/xhprof_html/?source=$profilerNamespace&run=$runId\n\n"; + }); +} + require_once PIWIK_INCLUDE_PATH . '/libs/upgradephp/upgrade.php'; require_once PIWIK_INCLUDE_PATH . '/core/testMinimumPhpVersion.php'; require_once PIWIK_INCLUDE_PATH . '/core/Loader.php'; -- cgit v1.2.3