+
+ /**
+ * Enable profiling.
+ */
+ public static function xhprofEnable($flags)
+ {
+ if (extension_loaded('tideways_xhprof')) {
+ \tideways_xhprof_enable(TIDEWAYS_XHPROF_FLAGS_MEMORY | TIDEWAYS_XHPROF_FLAGS_CPU);
+ } else {
+ \xhprof_enable($flags);
+ }
+ }
+
+ /**
+ * Disable profiling and save results.
+ */
+ public function xhprofFinishRun($namespace)
+ {
+ if (extension_loaded('tideways_xhprof')) {
+ $data = \tideways_xhprof_disable();
+ $dir = $this->getConfig()->tmp();
+ $run_id = uniqid();
+ file_put_contents($dir . DIRECTORY_SEPARATOR . $run_id . '.' . $namespace . '.xhprof', serialize($data));
+ return $run_id;
+ } else {
+ $xhprof_data = \xhprof_disable();
+ $xhprof_runs = new \XHProfRuns_Default();
+ return $xhprof_runs->save_run($xhprof_data, $namespace);
+ }
+ }