diff --git a/tests/PHPUnit/bootstrap.php b/tests/PHPUnit/bootstrap.php
index d734d71439e1b9ee11e21b7f0f4cb9a183e10723..3892f1ebb2bdd0157aed2df8542d8d3414aaee26 100644
--- a/tests/PHPUnit/bootstrap.php
+++ b/tests/PHPUnit/bootstrap.php
@@ -29,31 +29,6 @@ if (!defined('PIWIK_INCLUDE_SEARCH_PATH')) {
 error_reporting(E_ALL | E_NOTICE);
 @date_default_timezone_set('UTC');
 
-$useXhprof = false;
-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';
@@ -67,6 +42,8 @@ require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/FakeAccess.php';
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/MockPiwikOption.php';
 require_once PIWIK_INCLUDE_PATH . '/vendor/autoload.php';
 
+\Piwik\Profiler::setupProfilerXHProf( $mainRun = true );
+
 // require test fixtures
 require_once PIWIK_INCLUDE_PATH . '/tests/PHPUnit/BaseFixture.php';
 foreach (glob(PIWIK_INCLUDE_PATH . '/tests/PHPUnit/Fixtures/*.php') as $file) {