diff options
author | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-05-17 06:12:56 +0400 |
---|---|---|
committer | Benaka Moorthi <benaka.moorthi@gmail.com> | 2013-05-17 06:12:56 +0400 |
commit | eb9e188fc218cf3e68359a3c67150c97d2a28142 (patch) | |
tree | 9363ed2e820c21f611fe5c223c97eab3abca4ab8 /tests | |
parent | ed60fae0cb3a151a03070bbe24d022f3e4e01e5c (diff) |
Allow easy use of XHProf when running phpunit tests from the command line.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/PHPUnit/bootstrap.php | 26 |
1 files changed, 26 insertions, 0 deletions
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'; |